lw $t0,val # $t0 has the value
andi $t8,$t0,1 # one's place is zero or one
bnez $t8,odd # if even
addu $t2,$t2,$t0 # add to even sum
b endif
odd: # else
addu $t1,$t1,$t0 # add to odd sum
endif:
If a branch instruction has a second operand, it can be an immediate operand or a register. For example, from the table:
bge | s,t,label | branch if s>=t | signed |
Here are examples:
bge $t1,$t2,spot # if ( $t1 >= $t2 ) goto spot bge $t1,23,spot # if ( $t1 >= 23 ) goto spot bge $t1,-98,spot # if ( $t1 >= -98 ) goto spot bge 12,$t1,oops # WRONG: first op must be a register bge $t1,value,oops # WRONG: second op can't be a symbolic address
Is the following instruction correct?
bge $t1,-67,spot # if ( $t1 >= -67 ) goto spot