汇编语言猜谜游戏。我的代码一直在循环,即使猜测应该是正确的?

Assembly language guessing game. My code kept looping even though the guess should be correct?

我在这方面真的很陌生,所以甚至不确定我是否正确编码。事实上我是第一次。 所以,我想我做的每一个正确的?我不确定为什么它不会退出循环,因为 beq $t1, $t0, winExit 应该让它退出我的循环。 loseExit 也有同样的问题。也许这都是错的...如果是我的错>.>

# The program will ask the player to try to guess the secret number 
# and receive a numerical input from the players.

    .data

# constant strings

prompt1:    .asciiz "Please guess the secret number (up to 10 tries): "
tooHigh:    .asciiz "Incorrect: Number is too high\n"
tooLow:     .asciiz "Incorrect: Number is too low\n"
userWin:    .asciiz "Congratulation! You guessed the secret number! :D"
userLose:   .asciiz "Sorry, You lose :/"

    .text

main:
#start of the loop
loop:
#Set secret number
    li $t0,4            #$t0 hold the secret number: 4
    li $t1,9            #$t1 hold the maximum number of tries: 10
    li $t2,0            #$t2 hold the number of tries. (counter)

#Prompt user for a number
    li $v0,4            #code for print_string
    la $a0,prompt1      #point to $a0 to prompt strings
    syscall             #print prompt

#Get integer from user
    li $v0,5            #code for read_int
    syscall             #get integer from user --> returned in $v0
    move    $s0,$v0     #move the resulting int to $s0

#$s0 hold the guess number

#check if it is equal, if it is then exit loop
    beq $t1, $t0, winExit       #Brand if Equal. User guess the correct number.

    addi $t2,$t2,1              # +1 to counter
    beq  $t2,$t1, loseExit      #check if counter reach the maximum number

    blt $s0,$t0, lessThan       #Branch on Lower Than. check if guess number is less than secret number
    bgt $s0,$t0, greaterThan    #Branch on Greater Than. check if guess number is higher than secret number
    j loop                      #goes back to loop

#prompt guess number is too high then loop
greaterThan:    
    li  $v0,4           #code for print_string
    la  $a0, tooHigh    #point $a0 to tooLow string
    syscall             #print prompt
    j loop      
    #go back to loop

#prompt guess number is too low then loop
lessThan:               
    li  $v0,4           #code for print_string
    la  $a0, tooLow     #point $a0 to tooLow string
    syscall             #print prompt
    j loop      #go back to loop

#print userWin to congratulate user
winExit:
    li  $v0,4           #code for print_string
    la  $a0, userWin    #point $a0 to userWin string
    syscall             #print prompt
    j exitProgram

#print userLose to user
loseExit:

    li  $v0,4           #code for print_string
    la  $a0, userLose   #point $a0 to userLose string
    syscall             #print prompt
    j exitProgram

#Exit program
exitProgram:
    li $v0,10           #code for exit
    syscall             #exit program
#$s0 hold the guess number

#check if it is equal, if it is then exit loop
    beq $t1, $t0, winExit       #Brand if Equal. User guess the correct number.

检查是否相等?不是$s0所以不是猜的数,可能试的次数等于密数?除了这些变量在t(临时)寄存器中,所以系统调用可能没有保留它们,或者它可能有,这取决于,但只要遵循调用约定。

loop:
#Set secret number
    li $t0,4            #$t0 hold the secret number: 4
    li $t1,9            #$t1 hold the maximum number of tries: 10
    li $t2,0            #$t2 hold the number of tries. (counter)

如果其他问题得到解决,这仍然会给玩家无限重试次数,因为每次迭代时尝试次数都会重置为零。