Bird
Raised Fist0
ARM Architectureknowledge~10 mins

General purpose registers (R0-R12) in ARM Architecture - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - General purpose registers (R0-R12)
Start Instruction
↓
Fetch Instruction
↓
Decode Instruction
↓
Identify Registers R0-R12
↓
Read/Write Data in Registers
↓
Execute Operation
↓
Store Result in Register
↓
Next Instruction or End
This flow shows how ARM instructions use general purpose registers R0 to R12 to hold data during execution.
Execution Sample
ARM Architecture
MOV R0, #5
MOV R1, #10
ADD R2, R0, R1
SUB R3, R2, #3
This code moves values into registers R0 and R1, adds them into R2, then subtracts 3 from R2 storing result in R3.
Analysis Table
StepInstructionRegisters BeforeOperationRegisters After
1MOV R0, #5R0=0, R1=0, R2=0, R3=0Set R0 to 5R0=5, R1=0, R2=0, R3=0
2MOV R1, #10R0=5, R1=0, R2=0, R3=0Set R1 to 10R0=5, R1=10, R2=0, R3=0
3ADD R2, R0, R1R0=5, R1=10, R2=0, R3=0Add R0 + R1, store in R2R0=5, R1=10, R2=15, R3=0
4SUB R3, R2, #3R0=5, R1=10, R2=15, R3=0Subtract 3 from R2, store in R3R0=5, R1=10, R2=15, R3=12
💡 All instructions executed, final register values updated.
State Tracker
RegisterStartAfter Step 1After Step 2After Step 3After Step 4
R005555
R100101010
R20001515
R3000012
Key Insights - 3 Insights
Why does R2 remain 0 after step 2 even though R0 and R1 have values?
Because step 2 only sets R1; R2 is updated only in step 3 when the ADD instruction executes (see execution_table row 3).
Why can we use immediate values like #5 and #10 in MOV instructions?
MOV allows loading a constant number directly into a register, so #5 and #10 are immediate values assigned to R0 and R1 respectively (see execution_table rows 1 and 2).
What happens if we try to use a register outside R0-R12 here?
This example focuses on R0-R12 which are general purpose; other registers like R13 (stack pointer) have special roles and are not used for general data storage in this context.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table at step 3. What is the value of R2 after the ADD instruction?
A5
B10
C15
D0
💡 Hint
Check the 'Registers After' column in row 3 of the execution_table.
At which step does R3 get its first non-zero value?
AStep 2
BStep 4
CStep 3
DStep 1
💡 Hint
Look at the 'Registers After' column for R3 in the execution_table rows.
If the instruction 'SUB R3, R2, #3' was changed to 'SUB R3, R1, #3', what would be the value of R3 after step 4?
A7
B12
C15
D10
💡 Hint
Subtract 3 from R1's value after step 2 (see variable_tracker).
Concept Snapshot
General purpose registers R0-R12 hold data for ARM instructions.
MOV loads values into registers.
ADD and SUB perform arithmetic using registers.
Registers store intermediate and final results.
R0-R12 are used for general data operations.
Full Transcript
This visual execution trace shows how ARM general purpose registers R0 to R12 are used in simple instructions. We start with all registers at zero. The MOV instructions load immediate values 5 and 10 into R0 and R1. Then ADD adds R0 and R1, storing 15 in R2. Finally, SUB subtracts 3 from R2, storing 12 in R3. The execution table tracks register values before and after each step. The variable tracker shows how each register changes over time. Key moments clarify common confusions about when registers update and the use of immediate values. The quiz tests understanding of register values at specific steps and effects of instruction changes. This helps beginners see how data moves and changes inside ARM CPU registers during execution.

Practice

(1/5)
1. Which of the following registers are considered general purpose registers in ARM architecture?
easy
A. R0 to R12
B. R13 to R15
C. Program Counter and Status Register
D. Floating Point Registers

Solution

  1. Step 1: Identify general purpose registers in ARM

    Registers R0 through R12 are used for general data storage and manipulation.
  2. Step 2: Differentiate special registers

    Registers R13 to R15 and others like Program Counter are special purpose, not general.
  3. Final Answer:

    R0 to R12 -> Option A
  4. Quick Check:

    General purpose registers = R0-R12 [OK]
Hint: General purpose registers are R0 to R12 only [OK]
Common Mistakes:
  • Confusing R13-R15 as general purpose
  • Including special registers like Program Counter
  • Thinking floating point registers are general purpose
2. Which of the following is the correct way to refer to the 5th general purpose register in ARM assembly?
easy
A. R6
B. R5
C. R4
D. R7

Solution

  1. Step 1: Understand register numbering

    Registers start at R0, so the 1st is R0, 2nd is R1, and so on.
  2. Step 2: Count to the 5th register

    Counting from R0: R0(1), R1(2), R2(3), R3(4), R4(5). So the 5th register is R4.
  3. Step 3: Verify options

    R5 is R5, which is actually the 6th register, so the correct is R4 (R4).
  4. Final Answer:

    R4 -> Option C
  5. Quick Check:

    5th register = R4 [OK]
Hint: Count from R0 to find the register number [OK]
Common Mistakes:
  • Starting count from R1 instead of R0
  • Mixing register numbers with their positions
  • Choosing R5 thinking it is the 5th register
3. Given the ARM assembly instructions:
MOV R0, #10
ADD R1, R0, #5
SUB R2, R1, R0

What is the final value stored in register R2?
medium
A. 5
B. 15
C. 10
D. 0

Solution

  1. Step 1: Execute MOV and ADD instructions

    MOV R0, #10 sets R0 = 10. ADD R1, R0, #5 sets R1 = 10 + 5 = 15.
  2. Step 2: Execute SUB instruction

    SUB R2, R1, R0 sets R2 = 15 - 10 = 5.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    R2 = R1 - R0 = 15 - 10 = 5 [OK]
Hint: Calculate step-by-step register values [OK]
Common Mistakes:
  • Mixing up source and destination registers
  • Forgetting immediate values in ADD
  • Assuming R2 equals R1 or R0 directly
4. Identify the error in the following ARM assembly snippet:
MOV R13, #20
ADD R0, R13, #5

What is the issue?
medium
A. ADD instruction requires three registers, not two registers and an immediate
B. Immediate value #5 is invalid
C. MOV instruction cannot move immediate values
D. R13 is not a general purpose register and should not be used like this

Solution

  1. Step 1: Check register usage

    R13 is the stack pointer, a special purpose register, not general purpose.
  2. Step 2: Validate instruction correctness

    Using R13 like a general purpose register is incorrect; MOV and ADD with immediate values are valid.
  3. Final Answer:

    R13 is not a general purpose register and should not be used like this -> Option D
  4. Quick Check:

    R13 is special purpose, not general [OK]
Hint: Remember R13-R15 are special, not general registers [OK]
Common Mistakes:
  • Assuming R13 is general purpose
  • Thinking immediate values are invalid
  • Believing ADD can't use immediate values
5. You want to swap the values of registers R2 and R3 using only R0 as a temporary register. Which sequence of instructions correctly achieves this?
hard
A. MOV R2, R3
MOV R3, R2
MOV R0, R2
B. MOV R0, R2
MOV R2, R3
MOV R3, R0
C. MOV R0, R3
MOV R3, R2
MOV R3, R0
D. MOV R0, R2
MOV R3, R2
MOV R2, R0

Solution

  1. Step 1: Save R2 value temporarily

    MOV R0, R2 stores R2's value in R0 to keep it safe.
  2. Step 2: Move R3 value to R2

    MOV R2, R3 copies R3's value into R2, overwriting original R2.
  3. Step 3: Restore original R2 value to R3

    MOV R3, R0 moves saved R2 value from R0 into R3, completing the swap.
  4. Final Answer:

    MOV R0, R2; MOV R2, R3; MOV R3, R0 -> Option B
  5. Quick Check:

    Use temp register R0 to swap R2 and R3 [OK]
Hint: Use R0 as temp: save R2, copy R3 to R2, restore R2 to R3 [OK]
Common Mistakes:
  • Overwriting R2 before saving it
  • Swapping without a temporary register
  • Mixing source and destination registers
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