【发布时间】:2017-09-14 04:25:37
【问题描述】:
如何在 MIPS 中输入浮点数?我试过使用:
li.s $f0, 6
syscall
但我一直在说线路有错误。
【问题讨论】:
-
系统调用号进入
$v0,而不是$f0。它是 在 系统调用后以$f0结束的结果。
标签: assembly mips mars-simulator
如何在 MIPS 中输入浮点数?我试过使用:
li.s $f0, 6
syscall
但我一直在说线路有错误。
【问题讨论】:
$v0,而不是$f0。它是 在 系统调用后以$f0 结束的结果。
标签: assembly mips mars-simulator
li $v0, 6
系统调用
//读取的浮点值会在$f0寄存器中
【讨论】:
您不能将数字立即加载到浮点寄存器中
li $t0, 6 # load-immediate 6 into an int register
mtc1 $t0, $f0 # copies the bit pattern "...110". It is NOT 6.0!!
cvt.s.w. $f12, $f0 # convert word to (single) float. $f12 now contains 6.0
【讨论】:
你也可以将浮点数放在数据段中:
.data
pi: .float 3.1415926535 # place value of pi in the data segment
.text
lwc1 $f12, pi # load pi from data segment into $f12
li $v0, 2
syscall # print $f12
输出将是:
3.1415927
-- program is finished running
【讨论】: