Greater than, less than equal, greater than equal in MIPS

I’m assuming that the pseudocode executes sequentially, so an earlier condition being true means you go there and never reach the later if statements. This makes the last branch guaranteed taken if it’s reached at all, so it doesn’t even need to be conditional. (Also assuming that this is a MIPS without a branch-delay slot.)

slt  $t1,$s1,$s0      # checks if $s0 > $s1
bne  $t1,$zero,label1 # if $s0 >  $s1, goes to label1
beq  $s1,$s2,label2   # if $s0 == $s2, goes to label2 
# beq  $t1,$zero,label3 # if $s0 <  $s1, goes to label3
b    label3            # only possibility left

If that’s not the case, you’ll want to implement $s0 >= $s1 as
!($s0 < $s1) with slt $t1, $s0, $s1 / beqz $t1, target, for example,
as shown in Ahmed’s answer.

Leave a Comment