Bird
0
0

You want to implement a nested subroutine call where funcA calls funcB, and funcB calls funcC. funcC modifies R2 and returns. How should you preserve R2's original value across these calls?

hard📝 Application Q8 of 15
ARM Architecture - Subroutines and Stack
You want to implement a nested subroutine call where funcA calls funcB, and funcB calls funcC. funcC modifies R2 and returns. How should you preserve R2's original value across these calls?
AOverwrite R2 directly without saving
BPush R2 onto the stack at funcB start and pop before returning
CUse MOV to copy R2 to R3 in funcC only
DDo nothing; R2 is preserved automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand register preservation in nested calls

    Registers like R2 can be overwritten in nested calls, so saving/restoring is needed.
  2. Step 2: Use stack to save R2 in funcB

    Push R2 onto the stack at funcB start and pop it before returning preserves original value across calls.
  3. Final Answer:

    Push R2 onto the stack at funcB start and pop before returning -> Option B
  4. Quick Check:

    Save registers on stack to preserve values in nested calls [OK]
Quick Trick: Save registers on stack to keep values safe [OK]
Common Mistakes:
  • Assuming registers auto-preserve
  • Only copying registers without saving original

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More ARM Architecture Quizzes