11.3.4 Changing Program Memory Variable Allocation

The variables allocated to program memory can, to some degree, be allocated to alternate memory locations. 11.2.2 Non-Auto Variable Allocation and Access, Changing Non-Auto Variable Allocation describes alternate addresses and sections also applicable to objects in the program memory space. Note that you cannot use the address attribute for objects that are in the auto_psv space.

The space attribute can be used to define variables that are positioned for use in the PSV window. To specify certain variables for allocation in the compiler-managed PSV space, use attribute space(auto_psv). To allocate variables for PSV access in a section not managed by the compiler, use attribute space(psv). For more information on these attributes, see Differences Between MPLAB® XC-DSC and C Standard.

For example, to place a variable in the auto_psv space, which will cause storage to be allocated in Flash in a convenient way to be accessed by a single PSVPAG setting, specify:

unsigned int Flash_variable __attribute__((space(auto_psv)));

Other user spaces that relate to Flash are available:

  • space(psv) - a PSV space that the compiler does not access automatically
  • space(prog) - any location in Flash that the compiler does not access automatically

Note that both the psv and auto_psv spaces are appropriately blocked or aligned so that a single PSVPAG setting is suitable for accessing the entire variable.

For more on PSV usage, see the “MPLAB® XC-DSC Assembler, Linker and Utilities User’s Guide” (DS-50003590).