Bird
0
0

What is the problem with this ARM code snippet?

medium📝 Analysis Q7 of 15
ARM Architecture - Subroutines and Stack
What is the problem with this ARM code snippet?
func:
  PUSH {r4}
  MOV r4, #15
  BX lr

Assuming r4 is callee-saved.
Ar4 is saved but not restored before return
BPUSH instruction is invalid
CMOV instruction cannot assign immediate values
DNo problem, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check preservation completeness

    r4 is saved with PUSH but never restored with POP before returning.
  2. Step 2: Consequence of missing restore

    Without restoring, the original value of r4 is lost after function returns.
  3. Final Answer:

    r4 is saved but not restored before return -> Option A
  4. Quick Check:

    Save without restore = data loss [OK]
Quick Trick: Always restore registers after saving [OK]
Common Mistakes:
  • Assuming PUSH alone preserves registers
  • Thinking MOV cannot assign immediates
  • Ignoring missing POP instruction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes