Initially, the stack pointer will be set to contain the base address of the stack's memory area. Write back can then be used with the LDM and STM instructions to make the ARM automaticallt update the stack pointer each time registers are pushed to the stack or pulled off it.
For an empty ascending stack, the following instructions are used:
Push registers
STMIA R13!,{register_list}
Pull registers
LDMDB R13!,{register_list}
NB: The use of write back is vital - without it the stack pointer will never be updated, and the stack will be corrupt.
The options for the STM instruction are always reversed in the case of the LDM instruction. It can be confusing to have to translate the stack type used into the appropriate options, so the assembler provides an easier way.
We can simply specify the type of stack being used, which will be the same for both instructions:
FA Full, ascending stack
FD Full, descending stack
EA Empty, ascending stack
ED Empty, descending stack
The assembler will then choose appropriate options for the instruction.
The empty ascending stack could thus be implemented as follows:
Push registers
STMEA R13!,{register_list}
Pull registers
LDMEA R13!,{register_list}
|
|
|