15.1 Software Stack
The PIC32C/SAM 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 PIC32C/SAM devices use a dedicated stack pointer register sp
(register r13) 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 at runtime, towards lower memory addresses.
By default, the size of the stack is 1024 bytes. The size of the stack can be specified by defining the _min_stack_size
symbol to the desired size in bytes using the --defsym
linker option. An example of allocating a stack of 2048 bytes using the command line is:
xc32-gcc -mprocessor=ATSAME70N20B foo.c -Wl,--defsym=__min_stack_size=2048
Two working registers are used to manage the stack:
• Register r13 (sp
) – This is the Stack Pointer. It points to the next free location on the stack.
• Register r11 (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.1 Initialize Stack Pointer and Heap.