我在 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
在我的 main 中初始化的变量:
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 行。