The ARM supports four different stack implementations. These are categorised by two axes, namely Ascending versus Descending and Empty versus Full.
An Ascending stack grows upwards. It starts from a low memory address and, as items are pushed onto it, progresses to higher memory addresses.
A Descending stack grows downwards. It starts from a high memory address, and as items are pushed onto it, progresses to lower memory addresses. The previous examples have been of a Descending stack.
In an Empty stack, the stack pointers points to the next free (empty) location on the stack, i.e. the place where the next item to be pushed onto the stack will be stored.
In a Full stack, the stack pointer points to the topmost item in the stack, i.e. the location of the last item to be pushed onto the stack.
As matching these four distinct stack implementations to multiple-register loads and stores has the potential for confusion, the ARM assembly language has specific stack manipulation instructions that indicate through their mnemonic the type of stack involved.
STMEA | r13!, {r0-r2} | ; Push data onto an Empty Ascending Stack |
LDMEA | r13!, {r0-r2} | ; Pop data off an Empty Ascending Stack |
STMED | r13!, {r0-r2} | ; Push data onto an Empty Descending Stack |
LDMED | r13!, {r0-r2} | ; Pop data off an Empty Descending Stack |
STMFA | r13!, {r0-r2} | ; Push data onto a Full Ascending Stack |
LDMFA | r13!, {r0-r2} | ; Pop data off a Full Ascending Stack |
STMFD | r13!, {r0-r2} | ; Push data onto a Full Descending Stack |
LDMFD | r13!, {r0-r2} | ; Pop data off a Full Descending Stack |
These stack manipulation instructions should be used in preference to the standard multiple-register load and store instructions. However, all of the stack manipulation instructions can be mapped to standard forms:
Stack | Standard | Type |
STMFA | STMIB | Pre-increment store |
STMEA | STMIA | Post-increment store |
STMFD | STMDB | Pre-decrement store |
STMED | STMDA | Post-decrement store |
LDMED | LDMIB | Pre-increment load |
LDMFD | LDMIA | Post-increment load |
LDMEA | LDMDB | Pre-increment load |
LDMFA | LDMDA | Pre-increment load |
References:
http://www-mdp.eng.cam.ac.uk/web/library/enginfo/mdp_micro/lecture5/lecture5-4-2.html