0

我正在编写一个 MIPS 程序来评估 3ab - 2bc - 5a + 20ac - 16。我的程序在

lw $t1, ($sp)。# 流行 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
4

1 回答 1

2

您在 sp 上缺少一个美元符号。

于 2013-11-13T06:37:55.853 回答