Почему верхняя и нижняя границы не сбрасываются должным образом после задания L или H, поэтому компьютерные догадки отключены.Код MIPS - PullRequest
0 голосов
/ 18 сентября 2018
.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:

1 Ответ

0 голосов
/ 19 сентября 2018

Ваша ветвь setHigherBound не учитывает, что текущая нижняя граница может быть ненулевой.Вместо move $t7,$t5 должно быть sub $t7,$t5,$t6.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...