MIPS Input floating point number

ぐ巨炮叔叔 提交于 2020-12-26 04:33:25

问题


How do you take in an input of a floating number in MIPS? I have tried using:

li.s $f0, 6 
syscall

But I just keep getting that there is an error with the line.


回答1:


li $v0, 6

syscall

//the float value that is read will be in $f0 register




回答2:


you cannot load-immediate a number into float registers

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



回答3:


You can also place the float in the data segment:

.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

Output will be:

3.1415927
-- program is finished running


来源:https://stackoverflow.com/questions/46210517/mips-input-floating-point-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!