MIPS(或SPIM):加载浮点数 [英] MIPS (or SPIM): Loading floating point numbers
问题描述
我正在尝试使用一些小型编译器,同时尝试在此处学习一些MIPS.这是我的问题:
I am working on a little mini compiler while trying to learn some MIPS here. Here's my issue:
MIPS的li指令(立即加载)会像这样
MIPS has an instruction li (load immediate) which would work like this
li $5,100
这会将100加载到寄存器5中.
which would load 100 into register 5.
但是,我现在需要将浮点数加载到寄存器中,并且正在努力寻找一种方法来做...因为$ 5,2.5的li无效.
However, I need to load floats into registers right now and am struggling with figuring out a way to do it...since li $5,2.5 does not work.
有人有什么建议吗?
我正在C语言中工作,我想我可以以某种方式获取正在使用的float的整数表示形式(即,float二进制表示== ints二进制表示),然后将整数"加载到寄存器中并从那时起就把它当作浮游物来对待.
I am working in C, I was thinking I could somehow get the integer representation of the float I am working with (i.e. so the floats binary representation == the ints binary representation) then load the "integer" into the register and treat it like a float from then on.
也许为时已晚,但我现在停滞了.
Maybe its too late but Im stuck right now.
推荐答案
您将需要使用浮点寄存器来加载浮点数.
You will need to use the floating point registers to load your floats.
代替:
li $5,2.5
尝试:
li.s $f5,2.5
看看在整数和浮点寄存器之间移动的mfc1和mtc1指令.
Take a look at mfc1 and mtc1 instructions to move between integer and floating point registers.
这篇关于MIPS(或SPIM):加载浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!