为什么在给出L或H后,上限和下限没有正确重置,所以计算机猜测是错误的。MIPS码

为什么在给出L或H后,上限和下限没有正确重置,所以计算机猜测是错误的。MIPS码,mips,Mips,您的setHigherBound分支未考虑当前下限可能为非零。它应该是sub$t7、$t5、$t6,而不是move$t7、$t5、$t6 .data prompt : .asciiz "Enter the secret number : " prompt2 : .asciiz "\nComputer guess is : " higherLowerOrCorrect : .asciiz "\nNumber is higher (h) lower (l) or correct/exit (x) :

您的
setHigherBound
分支未考虑当前下限可能为非零。它应该是
sub$t7、$t5、$t6
,而不是
move$t7、$t5、$t6

.data
prompt : .asciiz "Enter the secret number : "
prompt2 : .asciiz "\nComputer guess is : "
higherLowerOrCorrect : .asciiz "\nNumber is higher (h) lower (l) or correct/exit (x) : "
.text

li $v0,4
la $a0,prompt #it will print prompt for year
syscall

li $v0,5
syscall #wait for user input
move $t2,$v0

li $t7,100 #higher bound
li $t6,0 #lower bound
li $t5,0 #stores guess

loop :


move $a1, $t7 #Here you set $a1 to the max bound.
li $v0, 42 #generates the random number.
syscall

add $a0,$a0,$t6
move $t5,$a0

li $v0,4
la $a0,prompt2 #it will print prompt for year
syscall

move $a0,$t5
li $v0, 1 #1 print integer
syscall

li $v0, 4
la $a0, higherLowerOrCorrect
syscall

li $v0, 12 #GET CHARACTER
syscall

beq $v0,'l',setHigherBound #IF Y DO THE LOOP
beq $v0,'h',setLowerBound #IF Y DO THE LOOP
beq $v0,'x',exit #IF Y DO THE LOOP


setHigherBound:
move $t7,$t5
j loop
setLowerBound:
add $t7,$t7,$t6
sub $t7, $t7,$t5
move $t6,$t5
j loop

exit:

output: