bc
Branch Conditional
bc BO,BI,target_addr (AA=1 LK=0)
bc BO,BI,target_addr (AA=0 LK=1)
bc BO,BI,target_addr (AA=1 LK=1)
Branches conditionally based on the Count Register (CTR) and/or a bit in the Condition Register (CR).
Details
Branches conditionally based on the state of the Count Register (CTR) and/or a bit in the Condition Register (CR), as controlled by the BO field. The AA field determines absolute vs. relative addressing; LK=1 saves the return address in LR. This is the fundamental conditional branch instruction.
Pseudocode Operation
ctr_ok ← (BO[2] = 1) | (CTR ≠ 0 ⊕ BO[3])
if BO[2] = 0 then CTR ← CTR - 1
cr_ok ← (BO[0] = 1) | (CR[BI] = BO[1])
if ctr_ok & cr_ok then
if AA = 0 then NIA ← CIA + (BD || 0b00) else NIA ← (BD || 0b00)
if LK = 1 then LR ← CIA + 4
Programming Note
The bc instruction branches to a target address based on the condition bits in the Condition Register (CR). Ensure that the branch condition and target address are correctly set. The instruction operates at user privilege level, but care must be taken with conditional logic to avoid unintended execution paths.
Extended Mnemonics
| Extended Mnemonic | Equivalent Instruction |
|---|---|
Example
// Branch if CR bit 2 is set (beq).
Encoding
Operands
-
BO
Branch Options (5 bits) -
BI
CR Bit Index (5 bits) -
BD
14-bit Signed Displacement -
target_addr
Target address