cbnz
Compare and Branch Non-Zero (Thumb)
CBNZ <Rn>, <label>
Branches to label if register is not zero (Thumb-only).
Details
Compares the value in Rn with zero and branches to the label if not equal. The branch offset is encoded as an unsigned 6-bit immediate (i and imm5 combined, shifted left by 1 to form a 7-bit address offset). This instruction is T32 (Thumb)-only and does not affect condition flags. If the branch is not taken, execution continues sequentially.
Pseudocode Operation
if Rn != 0 then PC ← PC + (i:imm5:0 << 1) else PC ← PC + 2
Example
CBNZ r1, label
Encoding
Binary Layout
1011
1
0
i
1
imm5
Rn
Operands
-
Rn
Register -
label
Label
Reference (Arm AArch32 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0xB900 | CBNZ{<q>} <Rn>, <label> | T32 | 1011 | 1 | 0 | i | 1 | imm5 | Rn |
Description
Compare and Branch on Nonzero and Compare and Branch on Zero compare the value in a register with zero, and conditionally branch forward a constant value. They do not affect the condition flags.
Operation
EncodingSpecificOperations();
if nonzero != IsZero(R[n]) then
CBWritePC(PC + imm32);