User`s guide

C for DSP56800E
Calling Conventions and Stack Frames
119Targeting MC56F83xx/DSP5685x Controllers
Stack Frame and Alignment
Figure 6.1. depicts generation of the stack frame. The stack grows upward, so pushing
data onto the stack increments the stack pointer’s address value.
Figure 6.1 Stack Frame
The stack pointer (SP) is a 24-bit register, always treated as a word pointer. During a
function execution, the stable position for the SP is at the top of the user and compiler
locals. The SP increases during the call if the stack is used for passed parameters.
The software stack supports structured programming techniques, such as parameter
passing to subroutines and local variables. These techniques are available for both
assembly-language and high-level-language programming. It is possible to support
passed parameters and local variables for a subroutine at the same time within the
stack frame.
The compiler stores local data by size. It stores smaller data closest to the SP,
exploiting SP addressing modes that have small offsets. This means that the compiler
packs all bytes two per word near the stack pointer. It packs the block of words next,
then blocks of longs. Aggregates (structs and arrays) are farthest from the stack
pointer, not sorted by size.
NOTE
When a function makes a dynamic allocation, the compiler reserves
R5 as a stack frame pointer. (This is the stack pointer before
allocations.)
called function stack space
outgoing parameters
user and compiler locals
nonvolatile registers
status register
return address
incoming parameters
calling function stack space
SP
callee’s SP