【问题标题】:divide float point number as integer in MIPS在 MIPS 中将浮点数除为整数
【发布时间】:2015-03-27 14:17:44
【问题描述】:

我已经在两个 $t 寄存器中加载了一个浮点双精度数,现在我想将它除以 (-4)(不使用 fp 指令)并将其存储回 $f 寄存器。

mfc1 $t0, $f0  #$f0 = 0x00000000
mfc1 $t1, $f1  #$f1 = 0x40240000
div $t1, $t1, -4
mfhi $t0 #move the remainder to $t0
mflo $t1 #move the quotient to $t1

mtc1 $t0, $f0
mtc1 $t1, $f1


# store the $f0 result in memory
# print X/(-4)


mov.d $f12, $f0
li $v0, 3
syscall

但这会产生非常意外的结果,即 -2.231744757682269E231

我们将不胜感激。

【问题讨论】:

    标签: assembly floating-point mips cpu-registers


    【解决方案1】:

    显然,您不能只使用整数除法。在一般情况下,您必须将数字分解为它们的组成部分,即符号、尾数和指数,然后用整数运算实现除法。

    如果你特别想除以 -4,你可以利用它是 2 的幂的事实,所以你只需要翻转符号位并从指数中减去 2。

    也许读过floating point representations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多