我一直在研究一个非常基本的 MIPS 程序,它计算一些关于门票销售的东西。我已经实现了所有功能,但是当我执行我的 IF 语句(blt --> branch if less than)时,我遇到了一些错误。我将以下数据存储在临时寄存器中:
- $t0 = # of VIP tickets.
- $t1 = # of General Admission tickets.
- $t2 = # of Box Office tickets.
- $t4 = Average ticket sales.
我检查了值是否已相应存储,如果条件为 FALSE,代码确实有效,但如果满足条件,它将分支并仍然在分支之前打印代码。这是我的代码的一部分:
blt $t0, $t4, VIP_LESS # if $t0 < $t4 then VIP
b VIP_GREAT
VIP_LESS:
li $v0, 4
la $a0, less_avg_vip
syscall
VIP_GREAT:
li $v0, 4
la $a0, great_avg_vip
syscall
blt $t1, $t4, GEN_LESS # if $t1 < $t4 then GEN
b GEN_GREAT
GEN_LESS:
li $v0, 4
la $a0, less_avg_general
syscall
GEN_GREAT:
li $v0, 4
la $a0, great_avg_general
syscall
blt $t2, $t4, BOX_LESS # if $t2 < $t4 then BOX_LESS
b BOX_GREAT
BOX_LESS:
li $v0, 4
la $a0, less_avg_box
syscall
BOX_GREAT:
li $v0, 4
la $a0, great_avg_box
syscall
li $v0, 4
la $a0, endl
syscall
谁能明白我为什么会遇到这个问题?我的程序的输出如下所示:
VIP: 1349 tickets
General: 5278 tickets
Box: 4367 tickets
Average: 3215 tickets
VIP: Less than average.
General: Greater than average.
General: Less than average.
Box: Greater than average.
Box: Less than average.
编辑:工作代码。
blt $t0, $t4, VIP_LESS # if $t0 < $t4 then VIP
li $v0, 4
la $a0, great_avg_vip
syscall
j GENERAL_IF
VIP_LESS:
li $v0, 4
la $a0, less_avg_vip
syscall
GENERAL_IF:
blt $t1, $t4, GEN_LESS # if $t1 < $t4 then GEN
li $v0, 4
la $a0, great_avg_general
syscall
j BOX_IF
GEN_LESS:
li $v0, 4
la $a0, less_avg_general
syscall
BOX_IF:
blt $t2, $t4, BOX_LESS # if $t2 < $t4 then BOX_LESS
li $v0, 4
la $a0, great_avg_box
syscall
j END_IF
BOX_LESS:
li $v0, 4
la $a0, less_avg_box
syscall
END_IF:
li $v0, 4
la $a0, endl
syscall