Bird
0
0

Which ARM assembly code correctly sums numbers from 1 to 5 using a loop?

hard📝 Application Q8 of 15
ARM Architecture - Control Flow Instructions
Which ARM assembly code correctly sums numbers from 1 to 5 using a loop?
MOV R0, #5
MOV R1, #0
loop:
ADD R1, R1, R0
SUBS R0, R0, #1
BNE loop
ACorrectly sums 5+4+3+2+1 in R1
BAdds only 5 to R1 repeatedly
CDoes not decrement R0, infinite loop
DSkips adding when R0 is 1
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop logic

    R0 starts at 5, decrements each iteration, adding to R1.
  2. Step 2: Confirm loop exit

    SUBS updates flags; BNE loops until R0 is zero.
  3. Step 3: Verify sum correctness

    Sum is 5+4+3+2+1 = 15 stored in R1.
  4. Final Answer:

    Correctly sums 5+4+3+2+1 -> Option A
  5. Quick Check:

    Decrement and add each loop iteration [OK]
Quick Trick: Decrement counter and add in loop for sum [OK]
Common Mistakes:
  • Not decrementing counter causing infinite loop
  • Adding constant instead of counter
  • Incorrect loop exit condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes