Microchip Technology SW006023-2N Data Sheet

Page of 238
MPLAB
®
 XC32 C/C++ Compiler User’s Guide
DS51686E-page 86
 2012 Microchip Technology Inc.
4.4
STACK
The PIC32 devices use what is referred to in this user’s guide as a “software stack”. 
This is the typical stack arrangement employed by most computers and is ordinary data 
memory accessed by a push-and-pop type instruction and a stack pointer register. The 
term “hardware stack” is used to describe the stack employed by Microchip 8-bit 
devices, which is only used for storing function return addresses.
The PIC32 devices use a dedicated stack pointer register sp (register 29) for use as a 
software Stack Pointer. All processor stack operations, including function calls, inter-
rupts and exceptions, use the software stack. It points to the next free location on the 
stack. The stack grows downward, towards lower memory addresses.
By default, the size of the stack is 1024 bytes. The size of the stack may be changed
by specifying the size on the linker command line using the
--defsym_min_stack_size
 linker command line option. An example of allocating
a stack of 2048 bytes using the command line is:
xc32-gcc foo.c -Wl,--defsym,_min_stack_size=2048
The run-time stack grows downward from higher addresses to lower addresses. Two 
working registers are used to manage the stack:
• Register 29 (sp) – This is the Stack Pointer. It points to the next free location on
the stack.
• Register 30 (fp) – This is the Frame Pointer. It points to the current function’s
frame.
No stack overflow detection is supplied.
The C/C++ run-time start-up module initializes the stack pointer during the start-up 
and initialization sequence, see Section 12.3.2 “Initialize Stack Pointer and Heap”.
4.4.1
Configuration Bit Access
The PIC32 devices have several locations which contain the Configuration bits or 
fuses. These bits specify fundamental device operation, such as the oscillator mode, 
watchdog timer, programming mode and code protection. Failure to correctly set these 
bits may result in code failure, or a non-running device.
The #pragma config directive specifies the processor-specific configuration 
settings (i.e., Configuration bits) to be used by the application. Refer to the “PIC32MX 
Configuration Settings” online help (found under MPLAB 
IDE>Help>Topics>Language Tools)
 for more information. (If using the compiler from 
the command line, this help file is located at the default location at: 
Program Files/ Microchip/<install-dir>/doc/hlpPIC32MXConfigSet.chm
.)
Configuration settings may be specified with multiple #pragma config directives. 
The compiler verifies that the configuration settings specified are valid for the processor 
for which it is compiling. If a given setting in the Configuration word has not been 
specified in any #pragma config directive, the bits associated with that setting 
default to the unprogrammed value. Configuration settings should be specified in only 
a single translation unit (a C/C++ file with all of its include files after preprocessing).
For each Configuration word for which a setting is specified with the #pragma config 
directive, the compiler generates a read-only data section named .config_address
where address is the hexadecimal representation of the address of the Configuration 
word. For example, if a configuration setting was specified for the Configuration word 
located at address 0xBFC02FFC, a read-only data section named 
.config_BFC02FFC
 would be created.
• Syntax
• Example