mtlr
Move to Link Register - 7C 08 03 A6
mtlr
Instruction Syntax
Mnemonic | Format | Description |
mtlr | rS | Move to Link Register |
Instruction Encoding
0
1
1
1
1
1
S
S
S
S
S
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Field | Bits | Description |
Primary Opcode | 0-5 | 011111 (0x1F) |
rS | 6-10 | Source register |
Reserved | 11-15 | 00000 |
Reserved | 16-20 | 00000 |
Reserved | 21-29 | 000000000 |
Reserved | 30 | 0 |
SPR | 31-31 | Special Purpose Register (8 = LR) |
Operation
LR ← (rS)
The contents of register rS are copied into the Link Register (LR).
Affected Registers
Link Register (LR)
(always)
- Updated with the value from rS
Examples
Basic Move to Link Register
mtlr r3 # Copy value from r3 to LR
Save and Restore Link Register
# Save LR before function call mflr r10 # Save current LR value bl function # Call function (LR gets return address) mtlr r10 # Restore original LR value
Custom Return Address
# Set custom return address lis r3, return_addr@ha addi r3, r3, return_addr@l mtlr r3 # Set LR to custom return address blr # Return to custom address
Function Pointer Return
# Return to address stored in register mflr r10 # Save original return address mtlr r3 # Set LR to function pointer address blr # Return to function pointer
Exception Handler Setup
# Set up exception handler return lis r3, handler_return@ha addi r3, r3, handler_return@l mtlr r3 # Set LR to handler return address # ... exception handling code ... blr # Return to handler return address
Nested Function Calls
# Handle nested function calls mflr r10 # Save current return address bl inner_func # Call inner function mtlr r10 # Restore outer function return address blr # Return to outer function