1
我試圖使用堆棧指針將浮點數從存儲器$ 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