Course: Computer Architectures

Source: R. Ferrero, Politecnico di Torino, 8_stack.pdf, 23 PDF pages. The source is a PowerPoint deck licensed CC BY-SA; the local PDF remains in Downloads/Architecture/8_stack.pdf. Page references below use PDF order.

Why this lesson matters

A function often needs to save several registers before it uses them. ARM’s multiple-register transfer instructions make this efficient, and its stack suffixes describe exactly how the stack pointer moves. The central discipline is to track two things separately: which memory address is used and whether the base register is updated.

Learning route

  1. Review Stack for LIFO behavior and why a stack pointer moves before saving a new value.
  2. Learn the stack conventions and SP meaning in ARM Stack Conventions and PUSH POP.
  3. Trace address movement and register ordering in ARM LDM and STM Addressing Modes.

Source coverage by PDF page

PDF pagesMaterial
1-2Stack definition, LIFO, PUSH, POP, and stack pointer
3-5Ascending/descending and empty/full stacks; push/pop traces
6-8LDM/STM, base-register write-back, register lists and ordering
9-10IA and DB addressing modes
11-18LDMIA, STMIA, LDMDB, and STMDB examples, with and without !
19Exercise: identify PUSH and POP for a full descending stack
20-23FD/EA stack suffixes and final PUSH/POP equivalences

Core result

For the standard ARM full descending stack:

PUSH {r0, r1}    ; same as STMDB SP!, {r0, r1}
POP  {r0, r1}    ; same as LDMIA SP!, {r0, r1}

STMDB decrements before storing, so it creates a new slot. LDMIA loads from the current top and increments afterward, so it releases that slot.

Source examples and added trace

The source’s multiple-register examples use {r1, r5, r7}. Registers are sorted by number, so the lowest memory address receives r1, then r5, then r7, regardless of the order typed in the list. Each word is 4 bytes.

Added trace: if SP = 1000 and the stack is full descending, then PUSH {r0, r1} first changes SP to 992, stores r0 at 992 and r1 at 996, and leaves SP = 992. A later POP {r0, r1} loads those values and restores SP = 1000.

Review questions

  • Why does STMIA SP! overwrite the current top of a full descending stack?
  • What does ! change in LDMIA r8!, {r1, r5, r7}?
  • Why does PUSH use DB while POP uses IA?

Answers and detailed traces are in the linked concept notes.