4.2.3 Stacks

There is one stack implemented by MPLAB XC8. This stack is used for both function return addresses and stack-based objects allocated by functions. The registers r28 and r29 (Y pointer) act as a frame pointer from which stack-based objects can be accessed.

The stack pointer is initialized to the highest valid data memory address. As functions are called, they allocate a chunk of memory for the stack-based objects and the stack grows down in memory, towards smaller addresses. When the function exits, the memory it claimed is made available to other functions.

Note that the compiler cannot detect for overflow of the memory reserved for the stack as a whole. There is no runtime check made for software stack overflows. If the software stack overflows, data corruption and code failure might result.