Microchip Technology SW006022-2N Data Sheet

Page of 338
Memory Allocation and Access
 2012 Microchip Technology Inc.
DS52071B-page 129
7.4.4
Changing Program Memory Variable Allocation
The variables allocated to program memory can, to some degree, be allocated to alter-
nate memory locations. Section 7.3.1.4 “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 Chapter 5. “Differences Between MPLAB XC16 and ANSI 
C”
.
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 Assembler, Linker and Utilities for PIC24 
MCUs and dsPIC DSCs User’s Guide (DS51317)
.