我正在尝试使用堆栈指针将浮点数从寄存器 $f1 存储到堆栈中。我总是收到地址超出范围的错误。在我这样做之后,我想从堆栈中弹出单词并将它们打印到屏幕上。我正在使用火星。这是一些示例代码。
示例代码
li, $t3, 0 # set counter register
l.s $f1, zero # load floating point 0.00 into $f1
li $sp, 252 # start the stack size
swc1 $f1, ($sp) # store the floating point as a word in the stack
loop:
addi $sp, $sp, -4 # decrement the stack pointer
swc1 $f1, ($sp) # store the floating point as a word in the stack
bgt $sp, $t3, loop # continue loop until all stack is populated
print to screen after this line
li $t2, 7
li $sp, 252 # start the stack size
lwc1 $f12, ($sp) # pop from stack
li $v0, 2
syscall
printloop:
addi $sp, $sp, -4 # decrement the stack pointer
lwc1 $f12, ($sp) # pop from stack
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop2:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop2
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop3:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop3
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop4:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop4
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop5:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop5
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop6:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop6
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop7:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop7
lw $a0, newline
li $v0, 4
syscall
li $t2, 7
printloop8:
addi $sp, $sp, -4
lwc1 $f12, ($sp)
li $v0, 2
syscall
addi $t2, $t2, -1
bnez $t2, printloop8
li $v0, 10
syscall