如果我在 MIPS 的“f”寄存器中有一个值,我如何将它从 X.YZDEF 截断为 X.YZ?据说,您必须将浮点数转换为两个整数并显示它们……这是怎么做到的?
问问题
6768 次
3 回答
2
最简单的做法是:
- 将该值乘以 100 (
mul.d
), - 四舍五入为整数 (
round.l.d
), - 转换回浮点数 (
cvt.d.l
),并且 - 除以 100 (
div.d
)。
于 2010-04-06T01:58:14.983 回答
2
您可能想看看这些链接是否会对您有所帮助。
http://en.wikipedia.org/wiki/MIPS_architecture#MIPS_Assembly_Language
http://chortle.ccsu.edu/AssemblyTutorial/index.html#part8
您可能还会发现这很有帮助: http ://www.uni-koblenz.de/~avolk/MIPS/Material/MIPSFloatingPointInstructions.pdf
很久没有做汇编编程了,但是,如果你乘以 100 < mul.s
>,那么你会将数字复制到一个整数寄存器,然后如果你除以 100 < div
>,那么你将只有两个数字正确的。我希望小数点左边的数字是 LO,右边的数字应该是 HI。
于 2010-04-06T01:10:32.393 回答
1
In order to implement a truncation (not rounding) in MIPS, you can do the following
# Note: The number you want to truncate is in $f12
##### Load 100 #####
li $t5,100 # t5 = 100 (word), t5 (word)
mtc1 $t5,$f5 # f5 = t5 (word), f5 (word)
cvt.s.w $f5,$f5 # f5 = wordToSingle(f5), f5 (single)
##### Multiply f12(single) by 100 (single) #####
mul.s $f12,$f12,$f5 # f12 = f12 (single) * f5 (single), f12 (single)
##### Truncate single to word #####
trunc.w.s $f12,$f12 # f12 = truncWordToSingle(f12 (single)), f12 (word)
##### Convert from word to single #####
cvt.s.w $f12,$f12 # f12 = convertWordToSingle(f12 (word)), f12 (single)
##### Divide by 100 #####
div.s $f12,$f12,$f5 # f12 = f12 (single) / f5 (single), f12 (single)
于 2013-07-07T21:11:47.810 回答