Bird
0
0

Given the following ARM assembly code snippet, what will be the value in register r2 after execution?

medium📝 Analysis Q13 of 15
ARM Architecture - Control Flow Instructions
Given the following ARM assembly code snippet, what will be the value in register r2 after execution?
CMP r0, r1
BEQ equal_label
MOV r2, #0
B end_label
equal_label:
MOV r2, #1
end_label:

Assume r0 = 5 and r1 = 5.
AUndefined
B0
C5
D1
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the CMP and BEQ instructions

    CMP compares r0 and r1. Since both are 5, they are equal, so the zero flag is set. BEQ will branch to equal_label.
  2. Step 2: Follow the branch and MOV instructions

    The code jumps to equal_label and executes MOV r2, #1, setting r2 to 1. The instructions after BEQ are skipped.
  3. Final Answer:

    1 -> Option D
  4. Quick Check:

    Equal values cause BEQ to set r2 to 1 [OK]
Quick Trick: If CMP finds equal, BEQ jumps to set r2=1 [OK]
Common Mistakes:
  • Ignoring the branch and setting r2 to 0
  • Confusing BEQ with BNE
  • Assuming MOV after BEQ always runs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes