MIPS 分支问题



我正在用MIPS做一个项目;我们可以创建任何我们想要的东西,只要它满足某些要求。无论如何,我选择做一个琐事程序,这很困难,但并非不可能。今天我的分支遇到了问题。

incrEScore:
    add     $t9, $t9, 1             #increment incr. counter
    add     $t8, $t8, 1             #increment counter
    move    $v0, $t8                    #move to $v0
    beq     $v0, $s2, eQTwo         #counter=2, question 2
    beq     $v0, $s3, eQThree           #counter=3, question 3
    beq     $v0, $s4, eQFour            #counter=4, question 4
    beq     $v0, $s5, eQFive            #counter=5, question 5
    bgt     $v0, $t8, eTally            #counter>5, eTally
decrEScore:
    add     $a3, $a3, 1             #increment decr. counter
    add     $t8, $t8, 1             #increment counter
    move    $v0, $t8                    #move to $v0
    beq     $v0, $s2, eQTwo         #counter=2, question 2
    beq     $v0, $s3, eQThree           #counter=3, question 3
    beq     $v0, $s4, eQFour            #counter=4, question 4
    beq     $v0, $s5, eQFive            #counter=5, question 5
    bgt     $v0, $t8, eTally            #counter>5, eTally
eTally:
    beq     $t9, $s5, eWin          #if increment counter = 5, branch to Easy Win
    bltu    $a3, $s5, eLoss         #if decrement counter < 5, branch to Easy Loss

在我的主变量中初始化的变量:

    li  $s0, 0                      #init score
    li  $s1, 1                      #constant; menu num; answer num
    li  $s2, 2                      #constant; menu num; answer num
    li  $s3, 3                      #constant; menu num; answer num
    li  $s4, 4                      #constant; menu num; answer num
    li  $s5, 5                      #constant; counter compare point
    li  $s6, 6                      #constant
    li  $s7, 7                      #constant
    li  $t0, 8                      #constant
    li  $t1, 9                      #constant
    li  $t2, 10                 #constant; counter compare point
    li  $t3, 11                 #constant
    li  $t4, 12                 #constant
    li  $t5, 13                 #constant
    li  $t6, 14                 #constant
    li  $t7, 15                 #constant; counter compare point
    li  $t8, 0                      #question counter
    li  $t9, 0                      #increment counter
    li  $a3, 0                      #decrement counter
    li  $a1, 100                    #constant

现在出现的问题是,如果任何时候一个问题出错,而不是所有问题(即 eQNums)都在运行它们的过程,计数器完全增加或减少,eTally 将立即分支到亏损。这会导致其余问题被切断/不运行,主菜单重新弹出。我尝试使用"blt"而不是"bltu",我也尝试仅使用增量计数器而不是增量和递减计数器,但发现这些都不能解决问题。

代码几乎是 1k 行,所以这里是完整源代码的链接。简易部分是第 165 行到 299 行。

在一些帮助下想通了!小丑你是对的 - $t 8 被初始化为 0 而不是 1,它把一切都扔掉了!

最新更新