Bird
Raised Fist0
ARM Architectureknowledge~10 mins

Load and store instructions (LDR, STR) in ARM Architecture - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Load and store instructions (LDR, STR)
Start
↓
STR Instruction
↓
Store Register Value to Memory Address
↓
LDR Instruction
↓
Load Memory Value to Register
↓
End
The flow shows storing a register value into memory with STR, then loading it back into a register with LDR.
Execution Sample
ARM Architecture
STR R1, [R0]
LDR R2, [R0]
Store the value in R1 into the memory address pointed by R0, then load that memory value into R2.
Analysis Table
StepInstructionRegisters BeforeMemory BeforeActionRegisters AfterMemory After
1STR R1, [R0]R0=1000, R1=42, R2=0{1000: 0}Store value 42 from R1 into memory at address 1000R0=1000, R1=42, R2=0{1000: 42}
2LDR R2, [R0]R0=1000, R1=42, R2=0{1000: 42}Load value 42 from memory address 1000 into R2R0=1000, R1=42, R2=42{1000: 42}
3EndR0=1000, R1=42, R2=42{1000: 42}Execution completeR0=1000, R1=42, R2=42{1000: 42}
💡 All instructions executed; final register and memory states shown.
State Tracker
VariableStartAfter Step 1After Step 2Final
R01000100010001000
R142424242
R2004242
Memory[1000]0424242
Key Insights - 3 Insights
Why does the value in R2 change only after the LDR instruction?
Because LDR loads data from memory into R2. Before LDR, R2 remains unchanged as shown in execution_table step 1.
Does the STR instruction change any register values?
No, STR only writes the value from a register to memory. Registers remain the same after STR, as seen in execution_table step 1.
What happens if the memory at address in R0 was uninitialized before STR?
STR overwrites memory at that address with the register value, so previous memory content is replaced, as shown by memory changing from 0 to 42.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the value of R2 after the LDR instruction?
A0
B42
C1000
DUndefined
💡 Hint
Check the 'Registers After' column for step 2 in execution_table.
At which step does the memory at address 1000 get updated?
AStep 3
BStep 2
CStep 1
DNever
💡 Hint
Look at the 'Memory After' column in execution_table for when memory changes.
If R1 had the value 55 instead of 42, what would be the value in memory at address 1000 after step 1?
A55
B42
C0
D1000
💡 Hint
STR stores the value from R1 into memory; see variable_tracker for memory updates.
Concept Snapshot
LDR and STR are ARM instructions to load from and store to memory.
STR stores a register's value into a memory address.
LDR loads a value from memory into a register.
Memory address is given by a register (e.g., [R0]).
STR does not change registers; LDR updates the target register.
Used for moving data between CPU and memory.
Full Transcript
This visual execution trace shows how ARM load (LDR) and store (STR) instructions work step-by-step. First, STR stores the value from register R1 into the memory address pointed to by R0. Then, LDR loads the value from that memory address back into register R2. The execution table tracks register and memory states before and after each instruction. Key moments clarify that STR changes memory but not registers, while LDR updates the target register. The visual quiz tests understanding of register and memory changes at each step. The concept snapshot summarizes the purpose and behavior of LDR and STR instructions in ARM architecture.

Practice

(1/5)
1. What does the LDR instruction do in ARM architecture?
easy
A. Stores data from a register into memory
B. Loads data from memory into a register
C. Performs arithmetic operations on registers
D. Jumps to a different instruction address

Solution

  1. Step 1: Understand the purpose of LDR

    The LDR instruction is used to read or load data from a memory address into a CPU register.
  2. Step 2: Differentiate from STR

    STR is the opposite; it stores data from a register back into memory.
  3. Final Answer:

    Loads data from memory into a register -> Option B
  4. Quick Check:

    LDR = Load from memory [OK]
Hint: LDR loads from memory, STR stores to memory [OK]
Common Mistakes:
  • Confusing LDR with STR
  • Thinking LDR performs arithmetic
  • Assuming LDR changes program flow
2. Which of the following is the correct syntax to store the value of register R1 into the memory address pointed by R0?
easy
A. STR R0, [R1]
B. LDR R1, [R0]
C. STR R1, [R0]
D. LDR R0, [R1]

Solution

  1. Step 1: Identify the store instruction

    STR is used to store data from a register into memory.
  2. Step 2: Match registers to syntax

    STR R1, [R0] means store the value in R1 into the memory address held in R0.
  3. Final Answer:

    STR R1, [R0] -> Option C
  4. Quick Check:

    STR stores register to memory [OK]
Hint: STR stores register to memory address in brackets [OK]
Common Mistakes:
  • Swapping register and address in syntax
  • Using LDR instead of STR for storing
  • Confusing source and destination registers
3. Given the following ARM instructions:
STR R2, [R3]
LDR R4, [R3]

What will be the value in register R4 after execution if R2 = 10 and the memory at address in R3 initially contains 5?
medium
A. 10
B. 5
C. Undefined
D. 0

Solution

  1. Step 1: Execute STR instruction

    STR R2, [R3] stores the value 10 (from R2) into the memory address pointed by R3, replacing the initial 5.
  2. Step 2: Execute LDR instruction

    LDR R4, [R3] loads the updated memory value (now 10) into R4.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    Store then load updates R4 to 10 [OK]
Hint: Store first, then load from same address updates register [OK]
Common Mistakes:
  • Assuming memory value stays 5 after STR
  • Confusing source and destination registers
  • Ignoring instruction order
4. Identify the error in the following ARM assembly snippet:
LDR R1, R2
STR R3, [R4]
medium
A. LDR syntax is incorrect; missing brackets around R2
B. STR syntax is incorrect; missing brackets around R3
C. Both instructions are correct
D. LDR should use STR instead

Solution

  1. Step 1: Check LDR syntax

    LDR loads from memory address, so the source must be in brackets like [R2]. Here, R2 is missing brackets, so syntax is wrong.
  2. Step 2: Check STR syntax

    STR R3, [R4] is correct because it stores R3's value into memory at address in R4.
  3. Final Answer:

    LDR syntax is incorrect; missing brackets around R2 -> Option A
  4. Quick Check:

    LDR needs brackets for memory address [OK]
Hint: LDR and STR need brackets for memory addresses [OK]
Common Mistakes:
  • Omitting brackets for memory operands
  • Confusing register direct with memory access
  • Thinking STR needs brackets on source register
5. You want to copy a block of 4 words from memory starting at address in R5 to another location starting at address in R6 using ARM instructions. Which sequence correctly uses LDR and STR to achieve this?
hard
A. Use LDR R0, [R5, #4]; STR R0, [R6, #4] once
B. Use LDR R0, [R5]; STR R0, [R6] once only
C. Use STR R0, [R5]; LDR R0, [R6] repeated 4 times
D. Use a loop: LDR R0, [R5], #4; STR R0, [R6], #4 repeated 4 times

Solution

  1. Step 1: Understand block copy requirement

    Copying 4 words means loading each word from source and storing it to destination, advancing addresses each time.
  2. Step 2: Analyze Use a loop: LDR R0, [R5], #4; STR R0, [R6], #4 repeated 4 times

    Use a loop: LDR R0, [R5], #4; STR R0, [R6], #4 repeated 4 times uses LDR and STR with post-increment addressing ([R5], #4 and [R6], #4) inside a loop repeated 4 times, correctly copying each word and moving pointers.
  3. Step 3: Analyze other options

    Use LDR R0, [R5]; STR R0, [R6] once only copies only one word. Use STR R0, [R5]; LDR R0, [R6] repeated 4 times reverses load/store roles. Use LDR R0, [R5, #4]; STR R0, [R6, #4] once copies only one word with offset but no loop.
  4. Final Answer:

    Use a loop: LDR R0, [R5], #4; STR R0, [R6], #4 repeated 4 times -> Option D
  5. Quick Check:

    Loop with LDR/STR and address increment copies block [OK]
Hint: Use loop with LDR/STR and post-increment for block copy [OK]
Common Mistakes:
  • Copying only one word instead of all 4
  • Mixing load and store instructions
  • Not incrementing addresses after each word
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard