Bird
0
0

Given the following ARM assembly snippet, what is the final value in register R0 after execution?

medium📝 Analysis Q13 of 15
ARM Architecture - Subroutines and Stack
Given the following ARM assembly snippet, what is the final value in register R0 after execution?
main:
  MOV R0, #1
  BL sub1
  BX LR

sub1:
  ADD R0, R0, #2
  BL sub2
  BX LR

sub2:
  ADD R0, R0, #3
  BX LR
A1
B3
C0
D6
Step-by-Step Solution
Solution:
  1. Step 1: Trace main and sub1 execution

    Start with R0=1 in main. Then BL sub1 calls sub1. In sub1, R0 = 1 + 2 = 3.
  2. Step 2: Trace sub1 calling sub2

    sub1 calls sub2. In sub2, R0 = 3 + 3 = 6. Then sub2 returns, sub1 returns, main returns.
  3. Final Answer:

    6 -> Option D
  4. Quick Check:

    1 + 2 + 3 = 6 [OK]
Quick Trick: Add values stepwise through nested calls [OK]
Common Mistakes:
  • Ignoring sub2 addition
  • Not updating R0 after each call
  • Confusing return with call instructions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes