beqlr
Branch if Equal to Link Register - 4D 82 00 20
beqlr
Instruction Syntax
Mnemonic | Format | Flags |
beqlr | LK = 0 | |
beqlrl | LK = 1 |
Instruction Encoding
0
1
0
0
1
1
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
LK
Field | Bits | Description |
Primary Opcode | 0-5 | 010011 (0x13) |
BO | 6-10 | 01010 (Branch Option) |
BI | 11-15 | 00000 (Branch Input - CR0[EQ]) |
BD | 16-29 | 00000000000000 (unused) |
LK | 31 | Link bit |
Operation
if CR0[EQ] = 1 then NIA ← LR if LK = 1 then LR ← CIA + 4
BEQLR branches to the address stored in the Link Register if the Equal (EQ) bit in Condition Register field 0 is set.
- Checks if the Equal bit (EQ) in CR0 is set
- If equal, branches to the address in LR
- Optionally saves the return address in LR if LK=1
Note: BEQLR is a derived form of the BCLR (Branch Conditional to Link Register) instruction with BO=01010 and BI=00000.
Affected Registers
Link Register (LR)
(if LK = 1)
- LR - Set to CIA + 4 (return address)
Next Instruction Address (NIA)
- NIA - Set to LR if condition is met
Examples
Conditional Function Return
# Return from function if condition is met cmpwi r3, 0 # Check return value beqlr # Return if r3 == 0 # Continue execution if condition not met # ... more code ... blr # Unconditional return
Early Exit from Function
# Exit function early if error condition cmpwi r3, -1 # Check for error code beqlr # Return immediately if error # Process normal case # ... normal processing ... blr # Normal return
Validation and Return
# Validate input and return if invalid cmpwi r3, 0 # Check if input is zero beqlr # Return if input is zero (invalid) # Process valid input # ... processing ... blr # Return after processing
Loop Exit Condition
# Exit loop if condition met loop_start: # ... loop body ... cmpwi r3, 0 # Check exit condition beqlr # Return if condition met # Continue loop b loop_start
Error Handling with Return
# Handle different error conditions cmpwi r3, 1 # Check for error type 1 beqlr # Return if error type 1 cmpwi r3, 2 # Check for error type 2 beqlr # Return if error type 2 # Handle normal case # ... normal processing ... blr # Normal return
Recursive Function Exit
# Recursive function with early exit recursive_function: cmpwi r3, 1 # Check base case beqlr # Return if base case reached # Recursive case # ... recursive processing ... subi r3, r3, 1 # Decrement counter bl recursive_function # Recursive call blr # Return from recursive call
Related Instructions
bclr (Branch Conditional to Link Register), blr (Branch to Link Register)