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.

Encoding

Binary Layout
19
0:5
BO
6:10
BI
11:15
000
16:20
528
21:30
LK
31
 
Format XL-form
Opcode 0x4C000420
Extension Base

Operands

  • BO
    Branch Options
  • BI
    CR Bit Index

Example

bcctr 20, 0

// Jump to address in CTR (bctr).

Registers Altered

CTR

Related

More in Base

Reference

Description

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.

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.