Software Stack Parameters

When a function uses the software stack, most arguments to that function will be passed on the stack (see Software Stack Operation).

Arguments are pushed onto the stack by the calling function, in a reverse order to that in which the corresponding parameters appear in the function’s prototype. Subsequently, and if required, the called function will increase the value stored in the stack pointer to allocate storage for any auto or temporary variables it needs to allocate.

The W register is sometimes used for the first function argument if it is byte-sized. This will only take place for Enhanced Mid-range devices and provided the function does not take a variable number of arguments. If a reentrant function is external (see Allocation of Executable Code), the W register will never be used to hold any function arguments. The W register is never used by reentrant function arguments when compiling for PIC18 devices.

The arguments for unnamed parameters in functions that take a variable argument list (defined using an ellipsis in the prototype), are placed on the software stack, before those for the named parameters. After all the function’s arguments have been pushed, the total size of the unnamed parameters is pushed on to the stack. A maximum of 256 bytes of non-prototyped parameters are permitted per function.

As there is no frame pointer, accessing function parameters (or other stack-based objects) is not recommended in hand-written assembly code.