bnez
Branch if not equal to zero
Branches to label if t1 is nonzero.
Used in
- LoopsRISC-V assembly
- Arithmetic, logic and bitsRISC-V assembly
- Arrays and stringsRISC-V assembly
- Floating point and the F and D extensionsRISC-V assembly
- The bitmap display and the keyboard registersRISC-V assembly
- Fill an array with the numbers from 1 to 10RISC-V assembly
- Even or odd, count the set bits, multiply by shiftingRISC-V assembly
- Bubble sortRISC-V assembly
- A 2D arrayRISC-V assembly
- Print a nonnegative number in bases 2–36RISC-V assembly
Forms
Operands
t1- Any integer register,
x0tox31, or its named alias, such aszero,t0ort6. label- A named address in the program, such as the start of a loop or a variable in
.data.
# First bnez case is taken; second is not. t2 ends at 11 (10 + 1).
.text
li t2, 0
li t0, 7
bnez t0, taken
addi t2, t2, 1
j first_done # Skip the other marker unconditionally.
taken:
addi t2, t2, 10
first_done:
li t0, 0
bnez t0, missed
addi t2, t2, 1
j second_done # Skip the other marker unconditionally.
missed:
addi t2, t2, 10
second_done:
# t2=11 proves one taken and one untaken path.