繁体   English   中英

在MIPS Assembly中,如果浮点寄存器中有浮点值X.YZDEF,如何截断到小数点后两位?

[英]In MIPS Assembly, how do I truncate to two decimal places if I have a floating point value X.YZDEF in a floating point register?

如果我在MIPS的“ f”寄存器中有一个值,如何将其从X.YZDEF截断为X.YZ? 假设您必须将float转换为两个int并显示这些int。这是如何完成的?

您可能需要查看一下这些链接是否会对您有所帮助。

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。

最简单的事情是:

  1. 将该值乘以100( mul.d ),
  2. 四舍五入为整数( round.ld ),
  3. 转换回浮点( cvt.dl ),然后
  4. 除以100( div.d )。

为了在MIPS中实现截断(不舍入),您可以执行以下操作

# 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM