Given two registers $s0
, $s1
, how can I convert the following pseudocode into MIPS assembly language using only the slt
(set on less than) and beq
and bne
(branch if equal, branch if not equal) instructions.
if ($s0 > $s1) { goto label1 }
if ($s0 >= $s1) { goto label2 }
if ($s0 <= $s1) { go to label3 }
slt $t1,$s1,$s0 # checks if $s0 > $s1
beq $t1,1,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
I'm assuming that the pseudocode executes sequentially, and that you can't go to two different labels.