Bird
0
0

Given the ARM code snippet:

medium📝 Analysis Q4 of 15
ARM Architecture - Control Flow Instructions
Given the ARM code snippet:
CMP r0, r1
BNE label
MOV r2, #1
label:
MOV r2, #0

What will be the value in r2 if r0 equals r1?
A1
B0
CUndefined
DThe program will crash
Step-by-Step Solution
Solution:
  1. Step 1: Analyze CMP and BNE behavior

    CMP compares r0 and r1; if equal, zero flag is set, so BNE (branch if not equal) is not taken.
  2. Step 2: Trace instruction execution

    Since BNE is not taken, MOV r2, #1 executes, then label is reached and MOV r2, #0 executes, overwriting r2.
  3. Final Answer:

    r2 will be 0 -> Option B
  4. Quick Check:

    Equal values skip BNE, final MOV sets r2=0 [OK]
Quick Trick: BNE skips if equal, final MOV sets r2=0 [OK]
Common Mistakes:
  • Assuming MOV r2, #1 remains
  • Ignoring label execution
  • Confusing BNE with BEQ

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes