Object Size Limits

The compiled stack can be built up in more than one block, each located in a different data bank, thus the total size of the stack is roughly limited only by the available memory on the device; however, individual objects in the stack are limited in size to the largest of the available spaces in the data banks.

The software stack is always allocated one block of memory; however, this memory may cross bank boundaries. The maximum size of the software stack is typically limited by the amount of free data space remaining. There are no compile-time or runtime checks made for stack overflow, but compiler errors are produced if a function defines too many stack-based objects.

There are instruction-set-imposed limitations on the amount of stack data that each function can define and the compiler can detect if these data allocations will be exceeded. The limits are 127 bytes for PIC18 devices and typically 31 bytes for Enhanced Mid-range devices. This latter limit can be exceeded, but for each additional 31 bytes of offset required to access an object, there will be several additional instructions output.

When reentrant functions call other reentrant functions, the stack pointer is incremented as any parameters to the called function are loaded. This increases the offset from the new top-of-stack position to the stack-based objects defined by the calling function. If this offset becomes too large, a warning (1488) or error might result when trying to access stack-based objects in the calling function. A similar situation exists if the called reentrant function returns a value, as this might also be located on the stack. For these reasons, the entire stack depth might not be usable for every function.