| ||||||||||||||||||||||||||||
Technical Support On-Line Manuals RealView Assembler User's Guide | Implementing stacks with LDM and STM
The load and store multiple instructions can update the base register. For stack operations, the base register is usually the stack pointer, r13. This means that you can use these instructions to implement push and pop operations for any number of registers in a single instruction. The load and store multiple instructions can be used with several types of stack:
To make it easier for the programmer, stack‑oriented suffixes can be used instead of the increment or decrement, and before or after suffixes. See Table 2.9 for a list of stack‑oriented suffixes. Table 2.9. Suffixes for load and store multiple instructions
For example:
STMFD r13!, {r0‑r5} ; Push onto a Full Descending Stack
LDMFD r13!, {r0‑r5} ; Pop from a Full Descending Stack
NoteThe Procedure Call Standard for the ARM Architecture (AAPCS), and ARM and Thumb C and C++ compilers always use a full descending stack. The Stack operations are very useful at subroutine entry and exit. At the start of a subroutine, any working registers required can be stored on the stack, and at exit they can be popped off again. In addition, if the link register is pushed onto the stack at entry, additional subroutine calls can be made safely without causing the return address to be lost. If you do this, you can also return from a subroutine by popping pc off the stack at exit, instead of popping lr and then moving that value into pc. For example:
subroutine PUSH {r5‑r7,lr} ; Push work registers and lr
; code
BL somewhere_else
; code
POP {r5‑r7,pc} ; Pop work registers and pc
NoteUse this with care in mixed ARM and Thumb systems. In ARMv4T systems, you cannot change state by popping directly into pc. In these cases you must pop the address into a temporary register and use the In ARMv5T and above, you can change state in this way. | |||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||