What do I need to do to assembly code that reserves data memory when migrating this code to XC8 compiler?

It is advisable to define the objects in C so that there is no need to define psects, etc. for them in the assembly code. The MPLAB® XC8 compiler takes care of the variable allocation automatically. But while coding in assembly, the user has to take care of variable allocation, using psects, etc. in RAM space.

Global C variables can be used in the ASM code. As the code generator is involved in memory allocation of data memory objects, it must be aware of any memory that will be required by assembly code. The compiler driver will scan assembly modules for any psects that are located in data memory, and which are both flagged as being abs and ovrld. The memory requirements of these psects can be easily determined (without running the linker) and this information passed to the code generator. These memory locations will then not be used by any objects defined in C code.

Here is an example of a psect that contains a directive to reserves 10 bytes of memory at address 110h.

Description of the Flags used in the assembly code:

class should be one of the reserved names, e.g. CODE, RAM, BANK0, BANK1, etc.
Check the generated map file to see the list of classes. Not all classes can be supplied as a flag to the psect, e.g., the map file lists the BANK5-BANK10 under the list of classes, but they cannot be used as a flag for the psect, as they are not implemented by the compiler to be used as a keyword or a flag. Refer to the compiler manual for a list of available data space classes.

The {abs} flag defines the current psect as being absolute; i.e., it should start at location 110h.

The ovrld flag is used in combination with the abs flag and indicates that the psect is an absolute psect, i.e., all symbols defined in the psect will be located at absolute addresses.

The space flag must be set to 1 for RAM-based memory.
This is the memory mapping corresponding to the space flags:
1 Data memory/RAM
0 Program memory

For the above code, the code generator ensures that the address range specified for the psect, spanning 0x110-0x11A in RAM is not used by any other module (the abs and ovrld flags make sure of this). The class and space flags make sure that the psect is a RAM-based psect.

This is the snip from the map file for the above psect:

CLASS BANK2
Address Length Space
myAsmObjects 110 A 1
© 2023 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.