bcctr

Branch Conditional to Count Register

bcctr BO, BI

Branches to the address in the Count Register (CTR) if the condition is met. Used for computed jumps and switch statements.

Details

Conditionally branches to the address in the Count Register based on the Branch Options (BO) field and the state of the condition register bit selected by BI. The link register is optionally updated if LK=1. This instruction is commonly used for computed jumps and indirect branches in switch statements and virtual function calls.

Pseudocode Operation

if (BO[0] = 0) then CTR ← CTR - 1; ctr_ok ← (BO[2] ∨ (CTR ≠ 0)); cond_ok ← (BO[4] ∨ (CR[BI] = BO[3])); if (ctr_ok ∧ cond_ok) then NIA ← CTR[0:61]; if (LK = 1) then LR ← CIA + 4;

Programming Note

When LK=1, the address of the next sequential instruction is placed in LR, making this a subroutine call. Use blr to return. CTR is decremented before the branch condition is tested; the branch is taken only if the combined CTR-and-condition test passes. Do not use this instruction inside a loop that also modifies CTR.

Example

bcctr 20, 0

// Jump to address in CTR (bctr).

Encoding

Binary Layout
19
0
BO
6
BI
11
000
16
528
21
LK
31
 
Format XL-form
Opcode 0x4C000420
Extension Base
Registers Altered CTR

Operands

  • BO
    Branch Options
  • BI
    CR Bit Index