SPRUIY2 November 2024 F29H850TU , F29H859TU-Q1
Register A15 in the available addressing registers is dedicated as the stack pointer register (SP = A15). The A15 register can access the full 32-bit address range (4GB) of the CPU (see Figure 2-2).
The operation of the stack is as follows:
If passing parameters on the software stack is required, the assembly code structure looks as follows:
; Allocate Parameter Space On Stack:
ADD.U16 A15, A15, #PARAMETER_SPACE
;....pass parameters on stackā¦
;....pass parameters in registersā¦
CALL.PROT @func
; 32-bit RPC automacally pushed on stack
; A15 = A15 + 8 (stack pointer incremented by 8 bytes = 64-bits)
; There is a 32-bit hole in the stack that can be used to save
; De-allocate Parameter Space From Stack
SUB.U16 A15, A15, #PARAMETER_SPACE
If allocating local variables on the software stack is required, the code structure looks as follows:
func:
; Allocate Local Variable Space On Stack:
ADD.U16 A15, A15, #PARAMETER_SPACE
; ... save on stack any registers used that need to be preserved across call..
; ... function code....
; ... restore from stack any registers used that need to be preserved across call..
; De-allocate Local Variable Space From Stack
SUB.U16 A15, A15, #PARAMETER_SPACE
RET.PROT
; 32-bit RPC automacally popped from stack
; A15 = A15 - 8 (stack pointer decremented by 8 bytes = 64 bits)
On normal function call: Return program counter (RPC, holds previous return address) register contents are pushed on software stack pointed by stack pointer (SP = A15). Then RPC register is initialized with new return address.
On normal function return: Return address is read from RPC register. Then RPC register is restored with value on software stack.
For more details regarding the RPC, see Section 2.2