ARM load–store and software interrupt instructions
Practical notes on ARM load–store (LDR/STR family, addressing modes, multiple-load/store) and software interrupt (SWI/SVC) instructions, how they work, syntax to remember, worked examples, common exam mistakes and practice questions.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
ARM-based embedded systems move data between registers and memory using a load–store model. An engineer uses load–store instructions (LDR/STR family) to read and write data, and uses software interrupt (SWI/SVC) to request privileged services (system calls) from supervisor code or an OS kernel. Correct use of addressing modes, write-back, and exception handling is necessary for reliable firmware and OS code.
Key ideas
Start with definitions (each bold term defined before use):
- Register: a small, fast storage location inside the CPU. ARM general-purpose registers are R0..R12; R13 is usually SP (stack pointer), R14 is LR (link register), R15 is PC (program counter).
- Word: 32 bits on classic 32-bit ARM.
- Byte: 8 bits.
- Address: numeric index to a byte in memory. An address is usually written in hexadecimal (for example 0x1000).
- Base register: the register that gives the starting memory address for an addressing mode (often called Rn in instruction syntax).
- Offset: a constant or register added to the base register to form an effective address.
- Write-back: when the base register is updated with the effective address as part of the instruction (assembler uses a '!' for pre-index write-back).
- Load–store architecture: a CPU design where only load and store instructions access memory; arithmetic instructions operate on registers only. ARM is a load–store architecture.
- Software Interrupt (SWI or SVC): an instruction that causes a controlled exception switching the processor to supervisor/exception mode; used to request services from firmware or kernel.
Exact, commonly tested rules and statements:
- The basic word load and store instructions are LDR{cond} <Rt>, [<Rn>{, #offset}] and STR{cond} <Rt>, [<Rn>{, #offset}]. These move a 32-bit word between memory and register. The assembler allows many addressing-mode variants (immediate offset, register offset, pre-indexed, post-indexed).
- Byte and halfword variants exist: LDRB / STRB for bytes (8-bit), LDRH / STRH for halfwords (16-bit). LDRSB and LDRSH sign-extend byte/halfword into 32-bit register. Some architectures also support doubleword transfers: LDRD / STRD (64-bit, usually requiring aligned addresses).
- Multiple-register versions: LDM / STM (Load/Store Multiple) move groups of registers to/from a contiguous memory block. The register list is encoded in the instruction.
- Addressing mode names used in ARM: IA (increment after), IB (increment before), DA (decrement after), DB (decrement before). Combine with LDM/STM forms like STMFD (stack full descending) used by the assembler as PUSH/POP pseudo-instructions.
- Conditional execution: almost all ARM data-transfer instructions accept a condition code suffix, e.g., LDRNE runs only if Z flag is clear. This is part of the ARM architectural conditional-execute feature.
- The assembler pseudo-instruction LDR Rt, =const loads a 32-bit constant into Rt. The assembler usually implements this by placing the constant in a literal pool and generating a PC-relative LDR to that pool, or by synthesising MOV/MVN if possible.
- SWI #imm24 (old name) / SVC #imm24 (ARMv7 recommended name) causes an exception; control transfers to the SVC/SWI vector (offset 0x08 from the vector table base). SWI is commonly used to implement system calls; the immediate can encode a syscall number. In Thumb state, SVC uses an 8‑bit immediate (imm8).
What to draw in diagrams (for exams):
- Draw a small memory map: addresses increasing left-to-right; show a word at address 0x1000 (four bytes labeled 0x1000..0x1003). Show R0..R3 as boxes. Draw an arrow for LDR R1, [R0] indicating R0 contains 0x1000 and the word at 0x1000 is copied to R1.
- For LDM/STM show memory block and multiple arrows between successive memory words and registers R4..R7.
- For SWI draw CPU mode boxes (User, Supervisor), show PC jumping from user code to the SVC/SWI vector entry at offset 0x08 from the exception vector base address (the base may be 0x00000000, 0xFFFF0000, or VBAR on ARMv7‑A/R), show LR_svc holding return address and SPSR_svc storing CPSR.
Assumptions to state: these notes assume classic 32-bit ARM (ARMv4–ARMv7 family) and little-endian memory by example; some implementation details such as unaligned access behavior and exact exception-return sequences can vary by core and ARM architecture version. Specifically, target ARMv4–ARMv7 A/R profiles (not Cortex-M); Cortex-M differs (no SPSR, different exception/return and vector model).
Formulas (syntax to remember)
LDR{cond} <Rt>, [<Rn>{, #<offset>}] — load word from memory at <Rn>+offset into <Rt>.
STR{cond} <Rt>, [<Rn>{, #<offset>}] — store word from <Rt> into memory at <Rn>+offset.
LDRB / STRB <Rt>, [<Rn>{, #<offset>}] — byte load/store.
LDRH / STRH <Rt>, [<Rn>{, #<offset>}] — halfword (16-bit) load/store.
LDR{cond} <Rt>, [<Rn>, <Rm>{, <shift> #<s>}] — register offset with optional shift (shift may be LSL/LSR/ASR/ROR).
LDR{cond} <Rt>, [<Rn>, #<offset>]! — pre-indexed addressing with write-back (update <Rn> = <Rn> + offset).
LDR{cond} <Rt>, [<Rn>], #<offset> — post-indexed addressing (use <Rn>, then <Rn> = <Rn> + offset).
STM{cond}{mode} <Rn>{!}, {<reglist>} — store multiple registers from register list to memory starting at <Rn>; optional write-back with '!'.
LDM{cond}{mode} <Rn>{!}, {<reglist>} — load multiple registers.
SWI #<imm24> or SVC #<imm24> — software interrupt / supervisor call.
Notes about symbols: { } means optional, < > placeholders. Condition code like EQ/NE/GE/GT etc. can be appended to instruction mnemonic.
Worked examples
Example 1 — Simple LDR (word)
Given: memory at 0x1000 contains bytes (little-endian) 0x44, 0x33, 0x22, 0x11 (so the 32-bit word is 0x11223344). R0 = 0x1000.
Step 1: Execute LDR R1, [R0].
Step 2: CPU forms effective address = R0 = 0x1000.
Step 3: Read 4 bytes at 0x1000..0x1003 and assemble into 32-bit little-endian word 0x11223344.
Step 4: Place 0x11223344 into R1.
Answer: R1 = 0x11223344 (registers unchanged except R1).
Example 2 — Pre-indexed store with write-back
Given: R3 = 0x2000, R2 = 0xDEADBEEF. Execute STR R2, [R3, #4]!.
Step 1: Compute effective address = R3 + 4 = 0x2004.
Step 2: Store 32-bit word 0xDEADBEEF at memory address 0x2004..0x2007 (little-endian bytes EF BE AD DE).
Step 3: Because of '!' write-back, update R3 = effective address = 0x2004.
Answer: memory[0x2004..0x2007] = 0xDEADBEEF, R3 = 0x2004.
Example 3 — Stack push/pop with STM/LDM (register multiple)
Given: SP = 0x3000, R0=1, R1=2, R2=3. Use ARM full-descending stack convention (STMFD / LDMFD). Assembler pseudo-instruction PUSH {R0-R2} expands to STMFD SP!, {R0-R2}.
Push steps:
1: STMFD SP!, {R0-R2} means write registers R0,R1,R2 to memory at addresses starting below SP (full descending). Effective result: SP = SP - 12 (3 words), memory[SP] = R0, memory[SP+4] = R1, memory[SP+8] = R2.
Pop steps (assembler POP {R0-R2} → LDMFD SP!, {R0-R2}):
1: Read back words into R0,R1,R2 from memory at SP; then SP = SP + 12.
Answer: After push then pop without modification, registers restore original values and SP returns to 0x3000.
Example 4 — SWI use (conceptual)
User code: place parameters in agreed registers then execute SWI #5 (system call 5 in this hypothetical OS).
Handler (supervisor mode): exception vector at SWI address is reached; hardware saves return info (LR_svc and SPSR_svc). OS reads the SWI immediate (the value 5) and R0..Rn registers to decide which service to run. After service, OS restores registers and returns to user code via appropriate exception return sequence.
Answer: SWI provides a controlled way to transfer to privileged code and implement system calls.
Common mistakes
- Misusing LDM/STM register list order vs memory layout: the lowest register in the list maps to the lowest address when using incrementing addressing.
- Assuming unaligned accesses always work. Some ARM cores trap or give unpredictable results on unaligned word accesses. Check the core’s manual in real projects.
- Thinking SWI immediately changes mode without saved state: hardware saves return information (LR and SPSR) — handler must restore CPSR from SPSR when returning.
For your exam
Typical question types:
- Definition/short note: define LDR/STR, explain addressing modes with examples. Full-marks answer should list syntax forms, describe pre/post-index, write-back and register-offset variants, and give a short example.
- Derivation/diagram: draw memory and registers to show results of a given instruction sequence (e.g., a trace of stack push/pop using STMFD/LDMFD). Full-marks answer shows memory addresses, bytes, register values step-by-step.
- Program/trace: given initial registers and memory, execute a small instruction sequence using LDR/STR/LDM/STM and show final values. Answer must show every effective address calculation and final register+memory states.
- Theory/essay: explain how SWI works and how it is used to implement system calls. Full-marks answer states the vector used for SWI, that LR_svc and SPSR_svc are saved, and that handler inspects registers and SWI immediate to dispatch.
When answering, always state assumption about endianness and the exact ARM architecture version if relevant.
Quick check
- What instruction stores R4 into memory at address (R5 + 8) and updates R5 to that effective address?
- Which instruction loads a signed byte from memory into R2 and sign-extends to 32 bits?
- Name the assembler pseudo-instruction commonly used to push registers onto the stack (one word).
Answers: 1)
STR R4, [R5, #8]!2)LDRSB R2, [<Rn>{, #<offset>}]3)PUSH {<reglist>}
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?