ARM > Introduction to ARM > The Stack

by David Thomas on

The Stack

We need to store the processor state when making nested calls.

The multiple data transfer instructions provide a mechanism for storing state on the stack (pointed to by R13).

The STM and LDM instructions’ modes have aliases for accessing stacks:

  • FD = Full Descending
    • STMFD/LDMFD = STMDB/LDMIA
  • ED = Empty Descending
    • STMED/LDMED = STMDA/LDMIB
  • FA = Full Ascending
    • STMFA/LDMFA = STMIB/LDMDA
  • EA = Empty Ascending
    • STMEA/LDMEA = STMIA/LDMDB

Anything but a full descending stack is rare!

Example Stack Entry & Exit

STMFD r13!, {r4-r7} – Pushes R4,R5,R6 and R7 onto the stack.

Diagram showing STMFD operation.

LDMFD r13!, {r4-r7} – Pops R4,R5,R6 and R7 from the stack.

Diagram showing LDMFD operation.