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 the linker having to be run) 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 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