Webcentive RISC-V Reference

c.beqz

Branch if Equal Zero

Extension
C
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
c.beqz xs1, imm
Length
16-bit (compressed)

Encoding

15131210976210
110imm[8|4:3]rs1′imm[7:6|2:1|5]01

Match 0xc001, mask 0xe003. Source: c.beqz rs1_p c_bimm9lo c_bimm9hi 1..0=1 15..13=6 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
imm[8|4:3]12:10c_bimm9hi
rs1′9:7rs1_p
imm[7:6|2:1|5]6:2c_bimm9lo

Description

C.BEQZ performs conditional control transfers. The offset is sign-extended and added to the pc to form the branch target address. It can therefore target a ±256 B range. C.BEQZ takes the branch if the value in register xs1' is zero. It expands to beq xs1, x0, offset.

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}
if (X[creg2reg(xs1)] == 0) {
  jump($pc + $signed(imm));
}

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages