In a recursive ARM assembly function calculating factorial, what is the purpose of the base case?
Think about how recursion ends to avoid infinite loops.
The base case stops recursion by returning a fixed value when the input reaches 0 or 1, preventing infinite calls.
What happens to the stack pointer (SP) during each recursive call in an ARM assembly function?
Consider how the stack grows when functions call themselves.
Each recursive call pushes data onto the stack, so SP decreases to allocate space.
Which registers must be preserved (saved and restored) by a recursive ARM assembly function to maintain correct execution?
Think about which registers the function must keep unchanged across calls.
Callee-saved registers (R4-R11 and LR) must be preserved to avoid corrupting data during recursion.
Given an ARM assembly recursive factorial function called with input 4, what is the returned result?
Input: R0 = 4
Function: factorial(n) returns n! recursivelyRecall the factorial values for small numbers.
Factorial of 4 is 4 × 3 × 2 × 1 = 24.
What error will occur if the link register (LR) is not saved before a recursive call in ARM assembly?
Recursive call without pushing LR onto stack
Consider what happens to LR during nested calls.
Not saving LR causes it to be overwritten on recursive calls, so the function returns to wrong address.