c.bnez

Branch if NOT Equal Zero

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 NOT zero. It expands to beq xs1, x0, offset.

Assembly format

c.bnez xs1, imm

Decode Variables

signed Bits<9> imm = sext({$encoding[12], $encoding[6:5], $encoding[2], $encoding[11:10], $encoding[4:3], 1'd0}, 9);
Bits<3> xs1 = $encoding[9:7];

Execution

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

Exceptions

This instruction may result in the following synchronous exceptions:

  • IllegalInstruction

  • InstructionAddressMisaligned

Encoding

svg

Defining extension

Zca

Access

M

Always

Containing profiles

  • Mandatory: None

  • Optional: RVA20S64, RVA20U64, RVA22S64, RVA22U64, RVA23S64, RVA23U64, RVB23S64, RVB23U64, RVI20U32, RVI20U64