在MIPS中将整数转换为双精度 [英] Convert Integer to Double in MIPS
问题描述
我想划分两个值,分别位于 $ tn
中。
值得到双重结果,但函数 div
只返回该分区的整数部分,任何人都可以帮助?
我需要转换 $ t1
和 $ t2
到 $ f0
和 $ f2
?
我该怎么做?
li $ t1,2
li $ t2,5
div $ f0,$ t2,$ t1
这给我一个错误,因为它期望一个 $ tn
值不是一个 $ fn
值..
您必须将存储在通用寄存器中的整数移动并转换为浮点或双寄存器。 >
假设您的号码存储在 $ a1
中,要转换为双对( $ f12
, $ f13
)您必须发行:
mtc1.d $ a1,$ f12
cvt.dw $ f12,$ f12
并将其转换为单精度浮点数( $ f12
),您可以执行以下操作:
mtc1 $ a1,$ f12
cvt.sw $ f12,$ f12
I want to divide two values that are in $tn
registers.
I have to divide these two values to get a double result but the function div
only returns the integer part of that division can anyone help out?
Do i need to convert $t1
and $t2
to $f0
and $f2
?
How do i do that?
li $t1,2
li $t2,5
div $f0,$t2,$t1
This gives me an error because it expects a $tn
value not a $fn
value...
You have to move and convert the integer stored in a general purpose register to floating point or double register.
Assuming your number is stored in $a1
, To convert to a double pair ($f12
, $f13
) you have to issue:
mtc1.d $a1, $f12
cvt.d.w $f12, $f12
And to convert it to a single precision float ($f12
) you'd do:
mtc1 $a1, $f12
cvt.s.w $f12, $f12
这篇关于在MIPS中将整数转换为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!