Bird
Raised Fist0
ARM Architectureknowledge~20 mins

Preserving callee-saved registers in ARM Architecture - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ARM Callee-Saved Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why preserve callee-saved registers?

In ARM architecture, why must a function preserve callee-saved registers?

ABecause the caller expects these registers to remain unchanged after the function call.
BBecause callee-saved registers are used only for temporary calculations within the function.
CBecause the operating system requires all registers to be saved by the callee.
DBecause callee-saved registers are automatically saved and restored by hardware.
Attempts:
2 left
💡 Hint

Think about who is responsible for keeping the values intact across function calls.

📋 Factual
intermediate
2:00remaining
Which ARM registers are typically callee-saved?

Identify the registers that are usually preserved by the callee in ARM calling conventions.

Ar4 to r11 and the stack pointer (sp)
Br0 to r3 and the link register (lr)
CProgram counter (pc) and r0 to r3
DOnly r0 and r1
Attempts:
2 left
💡 Hint

Consider which registers are used for passing arguments and which are preserved.

🔍 Analysis
advanced
2:00remaining
Effect of not preserving callee-saved registers

What is the likely outcome if a function modifies callee-saved registers but does not restore them before returning?

AThe function will cause a hardware exception immediately.
BThe caller may experience incorrect data or behavior due to unexpected register changes.
CThe program will automatically fix the registers after the function returns.
DThere will be no effect because callee-saved registers are not used by the caller.
Attempts:
2 left
💡 Hint

Think about the caller's expectations about register values after a function call.

🚀 Application
advanced
2:00remaining
Preserving callee-saved registers in assembly

Given this ARM assembly snippet, which option correctly preserves callee-saved registers?

ARM Architecture
push {r4, r5, lr}
// function body
pop {r4, r5, pc}
ANo push or pop instructions are needed for callee-saved registers.
BPush r0, r1 at start; pop r0, r1 at end.
CPush only lr at start; pop only lr at end.
DPush r4, r5, and lr at start; pop r4, r5, and pc at end to restore registers and return.
Attempts:
2 left
💡 Hint

Remember which registers must be saved and how to return from a function.

❓ Reasoning
expert
3:00remaining
Stack frame and callee-saved registers interaction

In ARM, when a function uses callee-saved registers and creates a stack frame, what is the correct order of operations to preserve these registers and set up the frame?

A1, 3, 2, 4
B2, 1, 3, 4
C1, 2, 3, 4
D2, 3, 1, 4
Attempts:
2 left
💡 Hint

Think about saving registers before using stack space and restoring in reverse order.

Practice

(1/5)
1. What is the main purpose of preserving callee-saved registers in ARM architecture?
easy
A. To speed up the execution of the program
B. To allow the caller to modify registers freely
C. To keep the values intact across function calls
D. To reduce the number of registers used

Solution

  1. Step 1: Understand the role of callee-saved registers

    Callee-saved registers must keep their values unchanged after a function call to avoid breaking the caller's data.
  2. Step 2: Identify the purpose of preserving these registers

    Preserving means saving and restoring their values so the caller sees no change.
  3. Final Answer:

    To keep the values intact across function calls -> Option C
  4. Quick Check:

    Preserving registers = keeping values intact [OK]
Hint: Remember: callee saves to protect caller's data [OK]
Common Mistakes:
  • Thinking callee-saved registers speed up execution
  • Confusing callee-saved with caller-saved registers
  • Believing registers can be freely modified without saving
2. Which ARM assembly instruction is commonly used to save callee-saved registers at the start of a function?
easy
A. MOV
B. ADD
C. CMP
D. PUSH

Solution

  1. Step 1: Identify instruction to save registers

    The PUSH instruction stores registers onto the stack, preserving their values.
  2. Step 2: Confirm PUSH is used at function start

    Functions use PUSH to save callee-saved registers before modifying them.
  3. Final Answer:

    PUSH -> Option D
  4. Quick Check:

    Save registers = PUSH [OK]
Hint: PUSH saves registers on stack at function start [OK]
Common Mistakes:
  • Using MOV which copies but doesn't save to stack
  • Using ADD which changes values, not saves
  • Using CMP which compares values, not saves
3. Consider this ARM function snippet:
func:
  PUSH {r4, r5}
  MOV r4, #10
  MOV r5, #20
  POP {r4, r5}
  BX lr
What will be the value of registers r4 and r5 after returning to the caller?
medium
A. r4 and r5 unchanged from caller
B. r4 and r5 contain random values
C. r4 = 0, r5 = 0
D. r4 = 10, r5 = 20

Solution

  1. Step 1: Analyze PUSH and POP effect

    PUSH saves original r4 and r5 values on stack; POP restores them before return.
  2. Step 2: Understand MOV instructions inside function

    Inside function, r4 and r5 are changed, but POP restores original values before returning.
  3. Final Answer:

    r4 and r5 unchanged from caller -> Option A
  4. Quick Check:

    Saved and restored registers = unchanged after call [OK]
Hint: PUSH then POP restores original register values [OK]
Common Mistakes:
  • Assuming MOV changes persist after POP
  • Ignoring that POP restores saved registers
  • Thinking registers reset to zero automatically
4. A function modifies callee-saved registers but forgets to restore them before returning. What problem can this cause?
medium
A. The program may crash or behave unpredictably
B. The function will run faster
C. The caller's registers remain unchanged
D. The stack pointer will not be affected

Solution

  1. Step 1: Understand callee-saved register role

    These registers must be restored to keep caller's data intact.
  2. Step 2: Consequence of not restoring

    If not restored, caller sees wrong values, causing crashes or wrong behavior.
  3. Final Answer:

    The program may crash or behave unpredictably -> Option A
  4. Quick Check:

    Not restoring callee-saved = crashes/unpredictable [OK]
Hint: Not restoring callee-saved causes crashes [OK]
Common Mistakes:
  • Thinking it improves speed
  • Believing caller's registers stay safe without restore
  • Ignoring stack pointer effects
5. You have a function that uses registers r4, r5, and r6 (all callee-saved). Which sequence correctly preserves and restores these registers?
hard
A. MOV r4, #0 MOV r5, #0 MOV r6, #0 ...function body... BX lr
B. PUSH {r4, r5, r6} ...function body... POP {r4, r5, r6}
C. PUSH {r4} PUSH {r5} PUSH {r6} ...function body... POP {r4} POP {r5} POP {r6}
D. POP {r4, r5, r6} ...function body... PUSH {r4, r5, r6}

Solution

  1. Step 1: Identify correct saving method

    Registers must be pushed together at function start to save their original values.
  2. Step 2: Identify correct restoring method

    Registers must be popped in the same order before returning to restore original values.
  3. Step 3: Check options for correct sequence

    PUSH {r4, r5, r6} ...function body... POP {r4, r5, r6} pushes all three registers at once and pops them before return, which is correct.
  4. Final Answer:

    PUSH {r4, r5, r6} ...function body... POP {r4, r5, r6} -> Option B
  5. Quick Check:

    Push all then pop all = correct preservation [OK]
Hint: Push all callee-saved at start, pop all before return [OK]
Common Mistakes:
  • Pushing and popping registers separately in wrong order
  • Using POP before PUSH
  • Overwriting registers without saving
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard