bnez
Branch if not equal to zero
Branches to label if $t1 is not zero.
Used in
- Arrays and stringsMIPS assembly
- The bitmap display and keyboard registersMIPS assembly
- Masks, shifts, popcount, and leading zeroesMIPS assembly
- Bubble sortMIPS assembly
- A 2D arrayMIPS assembly
- Print a number in any base without helpMIPS assembly
- Drawing shapes on the screenMIPS assembly
- A bouncing ballMIPS assembly
- Move a square with the keyboardMIPS assembly
- The snake gameMIPS assembly
Forms
Operands
$t1- Any general-purpose register,
$0to$31, using its numeric or named spelling, such as$8or$t0($zerois$0;$rais$31). label- A named address in the program, such as the start of a loop or a variable in
.data.
# Run bnez with one true and one false condition. A taken branch skips the assignment of 1; inspect $t2=2 for taken and $t3=1 for fall-through.
li $t0, 2
li $t2, 0
bnez $t0, taken_one
li $t2, 1
b first_done # Skip the other marker unconditionally.
taken_one: li $t2, 2
first_done:
li $t0, 0
li $t3, 0
bnez $t0, taken_two
li $t3, 1
b second_done # Skip the other marker unconditionally.
taken_two: li $t3, 2
second_done: