bnez
pseudolyszt.net covers bnez and other RISC-V instructions in more detail.
Description
Branches to a label when a register holds a value other than zero. In bnez rs, label, the branch is taken when rs is non-zero. Loop bodies commonly open with it while work remains. The assembler expands it to bne rs, zero, label.
Expands to
bne rs, zero, label
The assembler replaces this pseudo-instruction with the real instruction or instructions listed above.
Official definition
All branch instructions use the B-type instruction format. The 12-bit B-immediate encodes signed offsets in multiples of 2 bytes. The offset is sign-extended and added to the address of the branch instruction to give the target address. The conditional branch range is ±4 KiB.
Branch instructions compare two registers. BEQ and BNE take the branch if registers rs1 and rs2 are equal or unequal respectively. BLT and BLTU take the branch if rs1 is less than rs2, using signed and unsigned comparison respectively. BGE and BGEU take the branch if rs1 is greater than or equal to rs2, using signed and unsigned comparison respectively. Note, BGT, BGTU, BLE, and BLEU can be synthesized by reversing the operands to BLT, BLTU, BGE, and BGEU, respectively.