What is the Link Register (LR) in ARM architecture?
The Link Register (LR), also known as R14, is a special register in ARM processors that stores the return address when a function call is made. It helps the processor know where to continue after a function finishes.
Click to reveal answer
beginner
How does the Link Register (LR) help during a function call?
When a function is called, the address of the next instruction (after the call) is saved in the LR. This allows the program to return to the correct place after the function completes.
Click to reveal answer
intermediate
What happens to the Link Register (LR) during nested function calls?
In nested calls, the LR is often saved (pushed) to the stack before calling another function to avoid losing the return address. After the nested call finishes, the LR is restored to return correctly.
Click to reveal answer
intermediate
Why is the Link Register (LR) important for efficient function calls?
Using the LR avoids the need to use memory to store return addresses for simple calls, making function calls faster and saving memory access time.
Click to reveal answer
beginner
Which ARM register number corresponds to the Link Register?
The Link Register corresponds to register number 14, often written as R14 or LR.
Click to reveal answer
What does the Link Register (LR) store in ARM architecture?
AThe stack pointer address
BThe current instruction being executed
CThe return address after a function call
DThe value of the program counter
✗ Incorrect
The LR stores the return address so the program knows where to continue after a function finishes.
Which register number is the Link Register in ARM?
AR14
BR12
CR15
DR13
✗ Incorrect
The Link Register is register number 14, called R14 or LR.
What must happen to the Link Register during nested function calls?
AIt is ignored
BIt is saved to the stack and restored later
CIt is overwritten without saving
DIt is cleared to zero
✗ Incorrect
To keep the correct return address, LR is saved to the stack before nested calls and restored after.
Why is using the Link Register efficient for function calls?
AIt avoids using memory for return addresses
BIt speeds up arithmetic operations
CIt stores function parameters
DIt controls interrupts
✗ Incorrect
LR stores return addresses in a register, avoiding slower memory access.
What happens if the Link Register is not saved during nested calls?
ANothing, it works fine
BThe program crashes immediately
CThe function executes twice
DThe return address may be lost, causing incorrect program flow
✗ Incorrect
Not saving LR can overwrite the return address, leading to wrong program behavior.
Explain the role of the Link Register (R14/LR) in ARM function calls.
Think about how the processor remembers where to go back after a function.
You got /3 concepts.
Describe what must be done with the Link Register during nested function calls and why.
Consider what happens if multiple functions call each other.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of the link register (R14/LR) in ARM architecture?
easy
A. To manage stack pointer operations
B. To hold the current instruction being executed
C. To store general-purpose data temporarily
D. To store the return address during function calls
Solution
Step 1: Understand the role of the link register
The link register (R14/LR) is specifically designed to hold the return address when a function call is made.
Step 2: Differentiate from other registers
Other registers like the program counter hold the current instruction, and the stack pointer manages the stack, but LR stores the return address.
Final Answer:
To store the return address during function calls -> Option D
Quick Check:
Link register = return address storage [OK]
Hint: LR always holds return address after a function call [OK]
Common Mistakes:
Confusing LR with the program counter
Thinking LR stores general data
Mixing LR with stack pointer
2. Which ARM instruction saves the return address into the link register (LR)?
easy
A. BL
B. ADD
C. MOV
D. STR
Solution
Step 1: Identify the instruction for function calls
The BL (Branch with Link) instruction branches to a function and saves the return address in LR.
Step 2: Understand other instructions
MOV moves data, ADD adds values, and STR stores data to memory; none save return addresses.
Final Answer:
BL -> Option A
Quick Check:
BL saves return address in LR [OK]
Hint: BL means branch and link (save return) [OK]
Common Mistakes:
Choosing MOV as it moves data
Confusing STR with saving return address
Thinking ADD saves addresses
3. Consider this ARM code snippet: BL function ... function: MOV R0, #5 BX LR What happens when the instruction BX LR executes?
medium
A. The program jumps back to the instruction after BL
B. The program jumps to the start of function
C. The program halts execution
D. The program jumps to an undefined address
Solution
Step 1: Understand what BL does
BL saves the return address (next instruction after BL) into LR and jumps to 'function'.
Step 2: Analyze BX LR instruction
BX LR branches to the address stored in LR, which is the return address after BL.
Final Answer:
The program jumps back to the instruction after BL -> Option A
Quick Check:
BX LR returns to caller address [OK]
Hint: BX LR returns to saved return address [OK]
Common Mistakes:
Thinking BX LR jumps to function start
Assuming program halts on BX LR
Believing BX LR jumps to random address
4. In this ARM code, what is the error? BL function ... function: MOV R0, #10 MOV PC, R0
medium
A. BL instruction is invalid
B. MOV PC, R0 does not return to caller correctly
C. MOV R0, #10 is not allowed
D. Function label is missing
Solution
Step 1: Check the return method
To return from a function, the program must jump to the address in LR, not to a fixed value in R0.
Step 2: Identify the problem with MOV PC, R0
MOV PC, R0 sets the program counter to 10, which is not a valid return address, causing incorrect behavior.
Final Answer:
MOV PC, R0 does not return to caller correctly -> Option B
Quick Check:
Return must use LR, not arbitrary register [OK]
Hint: Return by jumping to LR, not arbitrary register [OK]
Common Mistakes:
Thinking BL is invalid
Assuming MOV R0, #10 is wrong
Ignoring the need to use LR for return
5. You want to write a function in ARM that calls another function and then returns correctly. Which sequence correctly uses the link register (LR)?
hard
A. Use B to call the function, then return with BX R14
B. Use B to call the function, then return with MOV PC, LR
C. Use BL to call the function, then return with BX LR
D. Use BL to call the function, then return with MOV PC, R0
Solution
Step 1: Understand function call with BL
BL saves the return address in LR and branches to the called function.
Step 2: Understand correct return instruction
Returning is done by branching to LR using BX LR, which jumps back to the saved return address.
Step 3: Evaluate other options
B does not save return address in LR; MOV PC, R0 returns to wrong place; BX R14 is equivalent to BX LR but using B (not BL) means LR is not saved.
Final Answer:
Use BL to call the function, then return with BX LR -> Option C
Quick Check:
BL + BX LR = correct call and return [OK]
Hint: Call with BL, return with BX LR always [OK]
Common Mistakes:
Using B instead of BL for calls
Returning with MOV PC, R0 instead of BX LR
Confusing BX R14 and BX LR usage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.