Given the two registers $s0 , $s1 , how can I convert the following pseudo-code to the MIPS assembly language using only slt (set less) and beq and bne (branch if it is equal, branch if not equal).
$s0
$s1
slt
beq
bne
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 assume that the pseudocode is executed sequentially and that you cannot go to two different shortcuts.
I think it should be:
stl $at, $s1, $s0 bne $at, $zero, label1 stl $t0, $s0, $s1 beq $t0, $zero, label2 stl $t1, $s1, $s0 beq $t1, $zero, label3 label1: label2: label3: