15.1 Software 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, interrupts 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 can
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 18.2.3 Initialize Stack Pointer and Heap.