User`s guide
C for DSP56800E
User Stack Allocation
120
Targeting MC56F83xx/DSP5685x Controllers
The compiler always must operate with the stack pointer long aligned. This means
that:
• The start-up code in the runtime first initializes the stack pointer to an odd value.
• At all times after that, the stack pointer must point to an odd word address.
• The compiler never generates an instruction that adds or subtracts an odd value
from the stack pointer.
• The compiler never generates a MOVE.W or MOVEU.W instruction that uses
the X:(SP)+ or X:(SP)- addressing mode.
User Stack Allocation
The 56800 compilers build frames for hierarchies of function calls using the stack
pointer register (SP) to locate the next available free X memory location in which to
locate a function call’s frame information. There is usually no explicit frame pointer
register. Normally, the size of a frame is fixed at compile time. The total amount of
stack space required for incoming arguments, local variables, function return
information, register save locations (including those in pragma interrupt functions) is
calculated and the stack frame is allocated at the beginning of a function call.
Sometimes, you may need to modify the SP at runtime to allocate temporary local
storage using inline assembly calls. This invalidates all the stack frame offsets from
the SP used to access local variables, arguments on the stack, etc. With the User Stack
Allocation feature, you can use inline assembly instructions (with some restrictions) to
modify the SP while maintaining accurate local variable, compiler temps, and
argument offsets, i.e., these variables can still be accessed since the compiler knows
you have modified the stack pointer.
The User Stack Allocation feature is enabled with the
#pragma
check_inline_sp_effects [on|off|reset]
pragma setting. The pragma may
be set on individual functions. By default the pragma is off at the beginning of
compilation of each file in a project.
The User Stack Allocation feature allows you to simply add inline assembly
modification of the SP anywhere in the function. The restrictions are straight-forward:
1. The SP must be modified by the same amount on all paths leading to a control
flow merge point
2. The SP must be modified by a literal constant amount. That is, address modes
such as “(SP)+N” and direct writes to SP are not handled.
3. The SP must remain properly aligned.