Bird
0
0

Identify the error in this ARM assembly loop code:

medium📝 Analysis Q14 of 15
ARM Architecture - Control Flow Instructions
Identify the error in this ARM assembly loop code:
MOV R1, #5
loop:
SUB R1, R1, #1
BNE loop
ASUB does not update condition flags, causing an infinite loop
BMOV instruction is incorrect syntax
CBNE should be replaced with BEQ
DLoop counter should start at 0
Step-by-Step Solution
Solution:
  1. Step 1: Check SUB vs SUBS instruction

    SUB subtracts but does not update condition flags; BNE depends on flags to branch.
  2. Step 2: Understand effect on loop

    Since flags are not updated by SUB, they remain unchanged and BNE continues to branch back, causing an infinite loop.
  3. Final Answer:

    SUB does not update condition flags, causing an infinite loop -> Option A
  4. Quick Check:

    SUB vs SUBS affects flags needed for BNE [OK]
Quick Trick: Use SUBS, not SUB, to update flags for BNE [OK]
Common Mistakes:
  • Using SUB instead of SUBS
  • Changing BNE to BEQ incorrectly
  • Starting counter at zero

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes