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

发布于 2024-08-27 23:23:50 字数 90 浏览 3 评论 0原文

如果我在 MIPS 中的“f”寄存器中有一个值,如何将其从 X.YZDEF 截断为 X.YZ?据说,您必须从浮点数转换为两个整数并显示它们......这是如何完成的?

If I have a value in an "f" register in MIPS, how do I truncate this down to X.YZ from X.YZDEF? Supposedly, you must convert from the float to two ints and display those... How is this done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长亭外,古道边 2024-09-03 23:23:50

您可能想查看这些链接是否对您有帮助。

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。

You may want to look and see if these links will help you.

http://en.wikipedia.org/wiki/MIPS_architecture#MIPS_Assembly_Language

http://chortle.ccsu.edu/AssemblyTutorial/index.html#part8

You may also find this helpful:
http://www.uni-koblenz.de/~avolk/MIPS/Material/MIPSFloatingPointInstructions.pdf

It has been a long time since I did assembly programming, but, if you multiply by 100 <mul.s>, then you will copy the number to an integer register, then if you divide by 100 <div> then you will have just the two digits on the right. The number to the left of the decimal will be in LO and the number to the right should be in HI, I expect.

末骤雨初歇 2024-09-03 23:23:50

最简单的方法是:

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

The easiest thing to do is:

  1. multiply the value by 100 (mul.d),
  2. round to an integer, (round.l.d),
  3. convert back to floating point (cvt.d.l), and
  4. divide by 100 (div.d).
·深蓝 2024-09-03 23:23:50

为了在 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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文