Course: Computer Architectures
Source lesson: ARM Stack and Multiple-Register Transfers
Multiple-register transfers
STM means Store Multiple: registers to memory. LDM means Load Multiple: memory to registers.
STMIA r8, {r1, r5, r7}
LDMIA r8, {r1, r5, r7}The register list is sorted numerically. With 4-byte words, {r1, r5, r7} occupies three consecutive words. The lowest register goes at the lowest memory address.
Addressing modes
| Mode | Meaning | First action |
|---|---|---|
IA | Increment After | Use current address, then add 4 bytes |
DB | Decrement Before | Subtract 4 bytes, then use the new address |
For three registers, the base address changes by 3 × 4 = 12 bytes when write-back is enabled.
The write-back marker
Without !, the base register keeps its original value:
LDMIA r8, {r1, r5, r7}With !, it receives the final updated address:
LDMIA r8!, {r1, r5, r7}The same rule applies to STM.
Trace
Assume r8 = 1000 and memory contains three words.
LDMIA r8!, {r1, r5, r7}| Transfer | Address used | Destination |
|---|---|---|
| 1 | 1000 | r1 |
| 2 | 1004 | r5 |
| 3 | 1008 | r7 |
Afterward, r8 = 1012. Without !, r8 would remain 1000.
For DB, the address is reduced before the first transfer. If r8 = 1000:
LDMDB r8!, {r1, r5, r7}uses 996, 992, and 988, then leaves r8 = 988.
Common confusion
The order in {r7, r1, r5} does not reverse the memory layout. ARM sorts the list as r1, r5, r7. Also, LDM versus STM tells the data direction, while IA versus DB tells address timing; they answer different questions.
Retrieval questions
- In
LDMIA r8!, {r1, r5, r7}, which register receives the word at the lowest address?r1. - If the list has five registers, how far does the base move? 20 bytes, assuming write-back.
- Which mode creates space before a push on a full descending stack?
DB, decrement before.