我正在写一个MIPS程序来评估3ab - 2bc - 5a + 20ac - 16.我的程序爆炸了
lw $ t1,($ sp)。 #pop 20ac。我把“< - ”放在了爆炸的地方
这是我的整个计划。任何帮助将不胜感激
li.s $f7, 16.0
li.s $f0, 0.0
li.s $f1, 0.0
li.s $f2, 0.0
la $a0, prompt # print prompt
li $v0, 4
syscall
li $v0, 6
syscall # get a
s.s $f0 , x # store in x
nop
li $v0, 4
syscall # print prompt again
li $v0, 6
syscall
s.s $f0, y # store in y
nop
li $v0, 4
syscall # print prompt again
li $v0, 6
syscall
s.s $f0, z # store in z
nop
# get x, y, and z
l.s $f1, x
l.s $f2, y
l.s $f3, z
li.s $f4, 3.0
mul.s $f5, $f1, $f2 # a * b
mul.s $f5, $f5, $f4 # 3ab
addi $sp, $sp, -4
mfc1 $t1, $f5 # $t1 = f1
sw $t1, ($sp) # push 3ab onto stack
nop
li.s $f4, -2.0
mul.s $f5, $f2, $f3 # b * c
mul.s $f5, $f5, $f3 # -2bc
addi $sp, $sp, -4
mfc1 $t1, $f5 # $t1 = f1
sw $t1, ($sp) # push -2bc onto stack
nop
li.s $f4, -5.0
mul.s $f5, $f4, $f1 # 5 * a
addi $sp, $sp, -4
mfc1 $t1, $f5 # $t1 = f1
sw $t1, ($sp) # push -5a onto stack
nop
li.s $f4, 20.0
mul.s $f5, $f1, $f3 # a * c
mul.s $f5, $f5, $f4 # 20ac
addi $sp, $sp, -4
mfc1 $t1, $f5 # $t1 = f1
sw $t1, ($sp) # push 20ac onto stack ( top of stack )
nop
li.s $f4, -16.0
lw $t1, (sp) # pop 20ac<---- THIS WHERE IT BLOWS UP
nop
mtc1 $t1, $f5 # $f5 = $t1
addu $sp, $sp, 4
addu $f4, $f5, $f4 # 20ac - 16
lw $t1, (sp) # pop -5a
nop
mtc1 $t1, $f5 # $f5 = $t1
addu $sp, $sp, 4
addu $f4, $f5, $f4 # - 5a + 20ac - 16
lw $t1, (sp) # pop -2bc
nop
mtc1 $t1, $f5 # $f5 = $t1
addu $sp, $sp, 4
addu $f4, $f5, $f4 # - 2bc - 5a + 20ac - 16
lw $t1, (sp) # pop 3ab
nop
mtc1 $t1, $f5 # $f5 = $t1
addu $sp, $sp, 4
addu $f4, $f5, $f4 # 3ab - 2bc - 5a + 20ac - 16
li $v0, 10
syscall # exit
答案 0 :(得分:2)
你错过了sp。
上的美元符号