MIPS 输入浮点数

MIPS Input floating point number

在MIPS中如何接受浮点数的输入?我试过使用:

li.s $f0, 6 
syscall

但我一直发现线路有误。

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

也可以将float放在数据段中:

.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