b
Branch - 48 00 00 00
b

Instruction Syntax

Mnemonic Format Flags
b target_addr AA = 0, LK = 0
ba target_addr AA = 1, LK = 0
bl target_addr AA = 0, LK = 1
bla target_addr AA = 1, LK = 1

Instruction Encoding

0
1
0
0
1
0
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
L
A
L

Field Bits Description
Primary Opcode 0-5 010010 (0x12)
LI 6-29 24-bit signed branch displacement
AA 30 Absolute Address
LK 31 Link Register Update

Operation

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

If AA = 0 (relative branch), the branch target address is computed by adding the sign-extended displacement to the current instruction address. If AA = 1 (absolute branch), the target address is the sign-extended displacement itself.

Note: The displacement is shifted left 2 bits (multiplied by 4) to maintain word alignment.

Affected Registers

Link Register (LR)

(if LK = 1)

For more information on branching see Section 2.3, "Branch Processor," in the PowerPC Microprocessor Family: The Programming Environments manual.

Examples

Basic Unconditional Branch

b loop_start       # Branch to loop_start label (relative)
ba 0x1000          # Branch to absolute address 0x1000

Branch with Link (Function Calls)

bl function_call   # Call function, save return address in LR
bla 0x8000         # Call function at absolute address 0x8000

Infinite Loop

loop:
    # some code here
    b loop             # Branch back to loop label

Function Call and Return

# Calling function
bl my_function     # Call function, LR = return address

# In function
my_function:
    # function code
    blr               # Return using LR (branch to link register)

Long Distance Branching

# Relative branch (limited range)
b near_label       # ±32MB range

# Absolute branch (anywhere in 32-bit space)  
ba 0x80001000      # Jump to specific address

Related Instructions

bc, bcctr, bclr

Back to Index