bl
Branch and Link - 48 00 00 00
bl

Instruction Syntax

Mnemonic Format Flags
bl target LK = 1

Instruction Encoding

0
1
0
0
1
0
L
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I

Field Bits Description
Primary Opcode 0-5 010010 (0x12)
LK 6 Link bit (1 for BL)
LI 7-29 Signed immediate offset (24-bit)
AA 30 Absolute Address (0 = relative)

Operation

LR ← CIA + 4
if (AA = 0) then NIA ← CIA + EXTS(LI || '00')
else NIA ← EXTS(LI || '00')

BL branches to a target address AND saves the return address in the Link Register (LR).

  1. Saves the address of the next instruction in the Link Register (LR)
  2. Branches to the target address (relative or absolute)
  3. Used for function calls - you can return with blr

Note: This is the primary instruction for calling functions in PowerPC. The return address is automatically saved in LR.

Affected Registers

Link Register (LR)

Program Counter

Examples

Basic Function Call

# Call a function
bl my_function    # Branch to my_function, save return address
# ... function returns here ...

my_function:
# ... function code ...
blr               # Return to caller

Nested Function Calls

# Call function that calls another function
bl outer_function
# ... back here ...

outer_function:
# ... some code ...
bl inner_function  # Call inner function
# ... back here ...
blr                # Return to main

inner_function:
# ... inner function code ...
blr                # Return to outer_function

System Call

# Make a system call
li r3, 1           # System call number
li r4, 42          # Parameter
bl syscall         # Call system function
# ... back here after system call ...

Conditional Function Call

# Call function only if condition is met
cmpwi r3, 0        # Compare r3 with 0
beq skip_call      # Skip if equal
bl my_function     # Call function
skip_call:
# ... continue here ...

Function with Parameters

# Call function with parameters
li r3, 10          # First parameter
li r4, 20          # Second parameter
bl add_numbers     # Call function
# r3 now contains result

add_numbers:
add r3, r3, r4     # Add parameters
blr                # Return with result in r3

Related Instructions

b (Branch), blr (Branch to Link Register), bclr (Branch Conditional to Link Register), bc (Branch Conditional)

Back to Index