MIPS输入浮点数

时间:2017-09-14 04:25:37

标签: mips

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

li.s $f0, 6 
syscall

但我一直认为线路有误。

3 个答案:

答案 0 :(得分:1)

li $ v0,6

<强>系统调用

//读取的浮点值将在$ f0寄存器

答案 1 :(得分:1)

您不能将数字立即加载到浮点寄存器中

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

答案 2 :(得分:1)

您还可以将浮点数放在数据段中:

.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
相关问题