3. 3
Interrupt-Driven I/O
Evaluating arithmetic expressions
Store intermediate results on stack instead of in registers
Data type conversion
2’s comp binary to ASCII strings
Function calls
Context switches
Exception handlers
4. 4
stacks can ascend or descend memory
stacks can be full or empty
ARM multiple register transfers support all
forms of the stack
5. 5
Ascending stack: grows up
Descending stack: grows down
A stack pointer (sp) holds the address
of the current top of the stack
Full stack: sp is pointing to the last
valid data item pushed onto the
stack
Empty stack: sp is pointing to the
vacant slot where the next data item
will be placed
6. 6
Stack Processing
ARM support for all four forms of stacks
• Full ascending (FA): grows up; stack pointer points to the
highest address containing a valid data item
• Empty ascending (EA): grows up; stack pointer points to
the first empty location
• Full descending (FD): grows down; stack pointer points to
the lowest address containing a valid data item
• Empty descending (ED): grows down; stack pointer points
to the first empty location below the stack
Two main operations:
PUSH: add an item to the stack
POP: remove an item from the stack
8. A Physical Stack
1995 1996
1998
1982
1995
1998
1982
1995
Initial State After
One Push
After Three
More Pushes
After
One Pop
9. A Hardware Implementation
• Data items move between registers
/ / / / / /
/ / / / / /
/ / / / / /
/ / / / / /
/ / / / / /
YesEmpty:
TOP #18
/ / / / / /
/ / / / / /
/ / / / / /
/ / / / / /
NoEmpty:
TOP #12
#5
#31
#18
/ / / / / /
NoEmpty:
TOP #31
#18
/ / / / / /
/ / / / / /
/ / / / / /
NoEmpty:
TOP
Initial State After
One Push
After Three
More Pushes
After
Two Pops
10. 10
Stack-oriented suffix For store or push
instructions
For load or pop
instructions
FD (Full Descending
stack)
DB (Decrement
Before)
IA (Increment After)
FA (Full Ascending
stack)
IB (Increment Before) DA (Decrement After)
ED (Empty
Descending stack)
DA (Decrement After) IB (Increment Before)
EA (Empty Ascending
stack)
IA (Increment After) DB (Decrement
Before)
11. Load and Store Multiples
IA
r1 Increasing
Address
r4
r0
r1
r4
r0
r1
r4
r0 r1
r4
r0
r10
IB DA DB
LDMxx r10, {r0,r1,r4}
STMxx r10, {r0,r1,r4}
Base Register (Rb)
12. 12
Stack type Store Load
Full descending STMFD (STMDB,
Decrement Before)
LDMFD (LDM,
increment after)
Full ascending STMFA (STMIB,
Increment Before)
LDMFA (LDMDA,
Decrement After)
Empty descending STMED (STMDA,
Decrement After)
LDMED (LDMIB,
Increment Before)
Empty ascending STMEA (STM,
increment after)
LDMEA (LDMDB,
Decrement Before)
The Procedure Call Standard for the ARM Architecture (AAPCS),
and armcc always use a full descending stack.
The PUSH and POP instructions assume a full descending stack. They
are the preferred synonyms for STMDB and LDM with writeback.
13. Stack push & pop operation: stmed
subr1:
stmed r13!, {r0-r2, r14}
(r1)
(r2)
(r14)
when return from SUB1
high
low
r13'
(r0)
r1
r2
r14
on entry to SUB1
low
r13'
r0
highr13
r13
SP moves
down
STMEDr13!, {r0-r2, r14} LDMED r13!, {r0-r2, r14}
13
Old
New
“Empty” means Stack Pointer is
pointing to an empty location
Old
New
Store multiple empty descending instruction
ED (Empty
Descending
stack)
DA (Decrement
After)
IB (Increment
Before)
14. Stack push & pop operation
14
STMFD r13!, {r4-r7} – Push R4,R5,R6 and R7 onto the stack.
LDMFD r13!, {r4-r7} – Pop R4,R5,R6 and R7 from the stack
FD (Full Descending
stack)
DB (Decrement
Before)
IA
(Increment
After)