I am trying to determine the lowest of 3 numbers.
I am using slt to compare 2 numbers at a time.
I am using beq and bne, and comparing them to $zero (because the result of slt is either 0 or 1, and register $zero holds the constant 0). By using beq and bne, I am trying to jump to the specific label that will ultimately print the lowest of the three.
I am puzzled that all of the label messages are getting printed. Below is my code. Can someone help me identify why all cases are printing?
# compare $s0 < $s1
slt $t0, $s0, $s1 # if $s0 < $t1
bne $t0, $zero, compare_s0_s2 # $t0 == 1, compare $s0 < $s2
beq $t0, $zero, compare_s1_s2 # $t0 == 0, compare $s1 < $s2
# compare $s0 < $s2
compare_s0_s2:
slt $t1, $s0, $s2 # if $s0 < $s2
bne $t1, $zero, print_lowest_s0 # $t1 == 1, print $s0
beq $t1, $zero, print_lowest_s2 # $t1 == 0, print $s2
# compare $s1 < $s2
compare_s1_s2:
slt $t2, $s1, $s2 # if $s0 < $s2
bne $t2, $zero, print_lowest_s1 # $t2 == 1, print $s1
beq $t2, $zero, print_lowest_s2 # $t2 == 0, print $s2
# print $s0
print_lowest_s0:
li $v0, 1
la $a0, ($s0)
syscall
# print $s1
print_lowest_s1:
li $v0, 1
la $a0, ($s1)
syscall
# print $s2
print_lowest_s2:
li $v0, 1
la $a0, ($s2)
syscall