SPRUIY2 November 2024 F29H850TU , F29H859TU-Q1
Stack space can be allocated and de-allocated as shown in the following examples:
Allocate 32-bytes (must be a multiple of 8-bytes):
ADD.U16 A15,A15,#32 ; SP = SP + 32
De-allocate 32-bytes (must be a multiple of 8-bytes):
SUB.U16 A15,A15,#32 ; SP = SP - 32
The compiler automatically allocates and de-allocates stack space and forces alignment to the 64-bit word boundary.
It is also possible to use the *(A15++#u8imm) addressing mode to push something on the stack and also allocate additional stack space if required and if the stack size is less than 256 bytes. For example:
ST.64 *(A15++#32),XD0 ; Push 64-bit XD0 value on stack, then allocate
; 32 bytes on stack (SP = SP + 32)
Similarly you can de-allocate and pop something from the stack using the *(A15 -= #n8imm) addressing mode. For example:
LD.64 XD0,*(A15-=#32) ; De-allocate 32-bytes from stack (SP = SP - 32),
; and pop 64-bit value from stack into XD0
If required to access a value on the stack that is a distance greater than 8192 bytes, an addressing pointer needs to be used to access the value. For example: to access a 32-bit value that is 8216 bytes away from top of stack:
SUB.U16 A0,A15,#8216 ; A0 = SP - #8216
LD.32 D0,*A0 ; D0 = contents of stack at SP-8216
Typically, for large stacks, the compiler allocates one of the Ax addressing mode registers as a frame pointer and can use the available pointer addressing modes to index into the stack.
The above approach can also be used to initialize pointers within the stack for situations where local variables located on stack need to be accessed frequently or if required to use pointer increment/decrement operations on the data.
Note that regardless of the addressing mode used, any stack memory access must be aligned to the accessed word size and any non-aligned access generates a fault. The compiler takes care of alignment of any data on the stack space.