ARM VERSION 1.2 Computer Hardware User Manual


 
Writing ARM and Thumb Assembly Language
2-42 Copyright © 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B
2.8.3 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 load and store multiple 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:
Descending or ascending
The stack grows downwards, starting with a high address and progressing
to a lower one (a descending stack), or upwards, starting from a low
address and progressing to a higher address (an ascending stack).
Full or empty
The stack pointer can either point to the last item in the stack (a full
stack), or the next free space on the stack (an empty 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. Refer to Table 2-5 for a list of
stack-oriented suffixes.
For example:
STMFD r13!, {r0-r5} ; Push onto a Full Descending Stack
LDMFD r13!, {r0-r5} ; Pop from a Full Descending Stack.
Note
The ARM-Thumb Procedure Call Standard (ATPCS), and ARM and Thumb C and C++
compilers always use a full descending stack.
Table 2-5 Suffixes for load and store multiple instructions
Stack type Push Pop
Full descending
STMFD (STMDB) LDMFD (LDMIA)
Full ascending
STMFA (STMIB) LDMFA (LDMDA)
Empty descending
STMED (STMDA) LDMED (LDMIB)
Empty ascending
STMEA (STMIA) LDMEA (LDMDB)