1

我尝试了以下代码,对于前两个整数,它工作正常。但是当我们在第三个提示中取最小数字时,它不会被视为最小数字。这是我的代码。我犯的那个错误在哪里。(对不起我的英语不好)

多谢..

    .text
.align 2 
.globl main 

main: 
# this program prints out the lowest value of three numbers input 

li $v0, 4 
la $a0, prompt1 
syscall 

li $v0, 5 # read keyboard into $v0 (number x is number to test) 
syscall 
move $t0,$v0 # first number in $t0 

li $v0, 4 
la $a0, prompt2 
syscall 

li $v0, 5 # read keyboard into $v0 (number x is number to test) 
syscall 
move $t1,$v0 # second number in $t1 

li $v0, 4 
la $a0, prompt3 
syscall 

li $v0, 5 # read keyboard into $v0 (number x is number to test) 
syscall 
move $t2,$v0 # third number in $t2 

blt $t1, $t0, L1 
move $t1, $t0 # smallest number in $t1 

blt $t2, $t1, L1 
move $t2, $t1

L1: 
li $v0, 4 # print answer 
la $a0, answer 
syscall 

li $v0, 1 # print integer function call 1 
move $a0, $t1 # integer to print 
syscall 

end: jr $ra 

.data 
prompt1: .asciiz "Enter the first number " 
prompt2: .asciiz "Enter the second number " 
prompt3: .asciiz "Enter the third number " 
answer: .asciiz "\nThe smallest number is "
4

1 回答 1

0

您尝试选择最小数字的位:

blt $t1, $t0, L1 
move $t1, $t0 # smallest number in $t1 

blt $t2, $t1, L1 
move $t2, $t1

L1: 

您只有一个标签,因此如果遵循第一个分支,则完全跳过与第三个数字的比较。

你需要更多类似的东西:

blt $t1, $t0, L1 
move $t1, $t0 # smallest number in $t1 

L1: 

blt $t2, $t1, L2
move $t2, $t1

L2: 
于 2012-12-30T15:33:24.393 回答