MIPS - 从堆栈读取双倍
MIPS - Reading double from stack
我对 MIPS 有疑问。我可以毫无问题地在堆栈上存储和写入浮点数。但是如果我尝试用双打做同样的事情,则会出现以下消息:
Error in line 12: Runtime exception at 0x0040001c: address not aligned on doubleword boundary 0x7fffeff4
#Line12:#
ldc1 $f12, 0($sp) # Pop from stack
这是我的代码
.data
test: .double 22.75
.text
.globl main
main:
l.d $f4, test # Value to $f4
mfc1 $t0,$f4 # $f4 to $t0
addi $sp, $sp, -8 # Decrease SP
sw $t0, 4($sp) # Store first word
mfc1 $t0,$f5 # $f5 to $t0
sw $t0, 0($sp) # Store second word
ldc1 $f12, 0($sp) # Pop from stack
li $v0, 3 # Call API StdOut
syscall # Print result
li $v0, 10 # Call API
syscall # End of program
我真的不知道该怎么办。我是否使用了错误的函数来恢复双精度值?
正如杰斯特所说:
ldc1 $f12, -4($sp) # Pop from stack
有效,但是
l.d $f4, test
mfc1 $t0,$f4
addi $sp, $sp, -16
andi $sp, $sp, 0xFFFFFFF8
sw $t0, 8($sp)
mfc1 $t0,$f5
sw $t0, 0($sp)
ldc1 $f12, 0($sp) # Pop from stack
确实修复了错误,但是 $f12 中写入的值不正确。
22.75 变成 5.322717027E-315.
我想通了。
mfc1.d $t0,$f4
而不是
mfc1 $t0,$f4
解决了问题。
我对 MIPS 有疑问。我可以毫无问题地在堆栈上存储和写入浮点数。但是如果我尝试用双打做同样的事情,则会出现以下消息:
Error in line 12: Runtime exception at 0x0040001c: address not aligned on doubleword boundary 0x7fffeff4
#Line12:#
ldc1 $f12, 0($sp) # Pop from stack
这是我的代码
.data
test: .double 22.75
.text
.globl main
main:
l.d $f4, test # Value to $f4
mfc1 $t0,$f4 # $f4 to $t0
addi $sp, $sp, -8 # Decrease SP
sw $t0, 4($sp) # Store first word
mfc1 $t0,$f5 # $f5 to $t0
sw $t0, 0($sp) # Store second word
ldc1 $f12, 0($sp) # Pop from stack
li $v0, 3 # Call API StdOut
syscall # Print result
li $v0, 10 # Call API
syscall # End of program
我真的不知道该怎么办。我是否使用了错误的函数来恢复双精度值?
正如杰斯特所说:
ldc1 $f12, -4($sp) # Pop from stack
有效,但是
l.d $f4, test
mfc1 $t0,$f4
addi $sp, $sp, -16
andi $sp, $sp, 0xFFFFFFF8
sw $t0, 8($sp)
mfc1 $t0,$f5
sw $t0, 0($sp)
ldc1 $f12, 0($sp) # Pop from stack
确实修复了错误,但是 $f12 中写入的值不正确。 22.75 变成 5.322717027E-315.
我想通了。
mfc1.d $t0,$f4
而不是
mfc1 $t0,$f4
解决了问题。