Bird
0
0

Analyze the following ARM assembly code:

medium📝 Analysis Q4 of 15
ARM Architecture - Control Flow Instructions
Analyze the following ARM assembly code:
BL subroutine
MOV R1, #3
B finish
subroutine:
MOV R1, #7
BX LR
finish:

What value will register R1 contain after execution reaches finish?
A3
B7
C0
DUndefined
Step-by-Step Solution
Solution:
  1. Step 1: Follow the flow

    The BL instruction branches to subroutine and saves the return address in LR.
  2. Step 2: Execute subroutine

    Inside subroutine, R1 is set to 7, then BX LR returns to the instruction after BL.
  3. Step 3: Continue after BL

    After returning, MOV R1, #3 executes, overwriting R1 with 3.
  4. Step 4: Branch to finish

    The B finish instruction jumps to finish.
  5. Final Answer:

    3 -> Option A
  6. Quick Check:

    Post-subroutine code overwrites R1 [OK]
Quick Trick: Post-call instructions overwrite register values [OK]
Common Mistakes:
  • Assuming R1 keeps value set inside subroutine
  • Ignoring instructions after BL
  • Confusing BX LR with unconditional branch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes