cbz

Compare and Branch Zero (Thumb)

CBZ <Rn>, <label>

Branches to label if register is zero (Thumb-only, does not affect flags).

Pseudocode Operation

if Rn == 0 then PC ← PC + (i:imm5:0 << 1) else PC ← PC + 2

Example

CBZ r1, label

Encoding

Binary Layout
1011
15:12
0
11
0
10
i
9
1
8
imm5
7:3
Rn
2:0
 
Format Thumb Branch
Opcode 0xB100
Extension T32 (Thumb)

Operands

  • Rn
    Register
  • label
    Label

Related

Other forms of cbz

  • cbz Compare and Branch Zero
  • cbz Compare and Branch Zero (64-bit)

Across architectures

Compare and Branch : how x86, ARM, RISC-V, and PowerISA each do this.

More in T32 (Thumb)

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0xB100 CBZ{<q>} <Rn>, <label> T32 1011 | 0 | 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);