The BL instruction helps the program jump to a different part of the code to run a subroutine, then come back to continue where it left off.
Branch and link (BL) for subroutines in ARM Architecture
BL label
BL stands for Branch and Link.
The label is the address or name of the subroutine to jump to.
subroutine_start and saves the return address.BL subroutine_start
0x1000 and saves the return address.BL 0x1000This program starts by putting 5 into register R0. Then it calls the subroutine multiply_by_two using BL. The subroutine doubles the value in R0 and returns. After returning, R0 holds 10.
AREA Example, CODE, READONLY
ENTRY
start MOV R0, #5 ; Load 5 into R0
BL multiply_by_two ; Call subroutine
; After return, R0 has the result
END
multiply_by_two
ADD R0, R0, R0 ; Multiply R0 by 2
BX LR ; Return to callerThe BL instruction saves the return address in the link register (LR), so you can return with BX LR.
Always use BX LR or similar to return from the subroutine to the caller.
BL is different from B (branch) because B does not save the return address.
BL jumps to a subroutine and saves the return address automatically.
Use BL to call functions or reusable code blocks in ARM assembly.
Return from subroutines using BX LR to continue execution after the BL call.
Practice
BL instruction do in ARM architecture?Solution
Step 1: Understand the purpose of BL
The BL instruction is used to jump to a subroutine while saving the return address.Step 2: Identify where the return address is saved
The return address is saved in the link register (LR) to allow returning after the subroutine finishes.Final Answer:
It jumps to a subroutine and saves the return address in the link register. -> Option AQuick Check:
BL saves return address in LR [OK]
- Confusing BL with simple jump instructions
- Thinking BL does not save return address
- Mixing BL with data load instructions
Solution
Step 1: Identify the instruction to return from subroutine
Returning from a subroutine requires branching to the address stored in the link register (LR).Step 2: Choose the correct instruction
The instructionBX LRbranches to the address in LR, effectively returning control.Final Answer:
BX LR -> Option CQuick Check:
Return uses BX LR [OK]
- Using BX PC instead of BX LR
- Confusing BL with return instruction
- Using MOV PC, LR which is valid but less common
BL subroutine MOV R0, #0 B end subroutine: MOV R0, #1 BX LR end:
What value will register R0 hold after execution?
Solution
Step 1: Follow the BL instruction
The BL instruction jumps tosubroutineand saves the return address (address ofMOV R0, #0) in LR.Step 2: Execute subroutine and return
Insidesubroutine,MOV R0, #1sets R0 to 1, thenBX LRreturns toMOV R0, #0.Step 3: Continue after BL
MOV R0, #0overwrites R0 to 0, followed byB end.Final Answer:
0 -> Option BQuick Check:
Post-returnMOV R0, #0overwrites subroutine value [OK]
MOV R0, #0 overwriting subroutine's R0=1 [OK]- Assuming R0 remains 1 after subroutine return
- Misidentifying the BL return address
- Thinking instructions after BL are skipped
BL subroutine MOV R0, #5 B end subroutine: MOV R0, #10 BX PC end:
Solution
Step 1: Check return instruction in subroutine
The subroutine usesBX PCto return, which branches to the current PC, not the saved return address.Step 2: Understand correct return usage
Correct return usesBX LRto jump back to the caller address saved by BL.Final Answer:
Using BX PC instead of BX LR to return causes incorrect return. -> Option DQuick Check:
Return must use BX LR, not BX PC [OK]
- Using BX PC to return from subroutine
- Ignoring the link register usage
- Assuming BL needs no label
Solution
Step 1: Understand BL saves return address in LR
Each BL saves the return address in LR, so calling BL twice in a row overwrites LR.Step 2: Preserve return addresses by nesting calls
Calling the second BL inside the first subroutine preserves the first return address until both return.Step 3: Avoid overwriting LR by sequential BL calls without return
Calling BL twice in sequence without returning overwrites LR, losing the first return address.Final Answer:
Use BL to first subroutine, then BL to second subroutine inside the first subroutine before returning. -> Option AQuick Check:
Nest BL calls to preserve return addresses [OK]
- Calling BL twice in a row without nesting
- Using BX LR to call subroutines
- Ignoring LR overwrite on multiple BL calls
Ready to prove it?
Pass the test and this pattern moves unknown
