bc
Branch Conditional - 40 00 00 00
bc
Instruction Syntax
| Mnemonic | Format | Flags |
| bc | BO,BI,target_addr | AA = 0, LK = 0 |
| bca | BO,BI,target_addr | AA = 1, LK = 0 |
| bcl | BO,BI,target_addr | AA = 0, LK = 1 |
| bcla | BO,BI,target_addr | AA = 1, LK = 1 |
Instruction Encoding
0
1
0
0
0
0
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
A
L
| Field | Bits | Description |
| Primary Opcode | 0-5 | 010000 (0x10) |
| BO | 6-10 | Branch Options |
| BI | 11-15 | Branch Condition Index |
| BD | 16-29 | 14-bit signed branch displacement |
| AA | 30 | Absolute Address |
| LK | 31 | Link Register Update |
Operation
if ((BO[2] = 0) & (CTR ≠ 0)) then CTR ← CTR - 1 ctr_ok ← BO[2] | ((CTR ≠ 0) ⊕ BO[3]) cond_ok ← BO[0] | (CR[BI] ≡ BO[1]) if ctr_ok & cond_ok then if AA = 0 then NIA ← CIA + EXTS(BD || '00') else NIA ← EXTS(BD || '00') if LK = 1 then LR ← CIA + 4
Branch conditional instruction tests a condition and branches if the condition is met. The condition is determined by the BO (Branch Options) and BI (Branch Index) fields.
Affected Registers
Count Register (CTR)
(if BO[2] = 0)
- CTR ← CTR - 1 (decremented before testing)
Link Register (LR)
(if LK = 1)
- LR ← CIA + 4 (return address)
For more information on branching see Section 2.3, "Branch Processor," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Basic Conditional Branches
cmpwi r3, 0 # Compare r3 with 0 bc 12, 2, positive # Branch if equal (cr0[eq] = 1) bc 4, 1, negative # Branch if greater than (cr0[gt] = 1)
Loop with Counter
li r3, 10 # Load loop counter
mtctr r3 # Move to count register
loop:
# loop body here
bc 16, 0, loop # Branch if CTR ≠ 0 (decrement and branch)
Extended Mnemonics (more readable)
# Instead of: bc 12, 2, target beq target # Branch if equal (extended mnemonic) # Instead of: bc 4, 1, target bgt target # Branch if greater than # Instead of: bc 16, 0, target bdnz target # Branch if CTR decremented and non-zero
Function Call with Condition
cmpwi r3, 0 # Test if r3 is zero bcl 12, 2, subroutine # Call subroutine if equal (saves LR)
Absolute Branch
cmpwi r3, 1 # Compare with 1 bca 12, 2, 0x8000 # Branch to absolute address if equal