if ( !( a < 0 ) ) { ... } if ( a >= 0 ) { ... }
The two operators
<
and >=
cover all possible integer values.
set instructions set a register to 1 or 0 to show the relation between two values. They are used to implement relational operators. However, they do not in themselves alter the flow of control.
The slt
instruction is used with
two's complement integers:
# $s and $t contain # signed integers # slt d,s,t # if ( $s < $t ) # d = 1 # else # d = 0
The sltu
instruction is used with
unsigned integers:
# $s and $t contain # unsigned integers # sltu d,s,t # if ( $s < $t ) # d = 1 # else # d = 0
(Trick Question)
A. After the following code executes, what value is in register $7
?
addiu $5,$0,-25 addiu $6,$0,25 slt $7,$5,$6
B. After the following code executes, what value is in register $7
?
addiu $5,$0,-25 addiu $6,$0,25 sltu $7,$5,$6