How do I move the result of a mul of two floats in x86 assembly?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 07:16:15

You’re multiplying the representations of the floating-point numbers as integers, rather than the floating-point numbers themselves:

 1.0 = 0x3f800000
32.0 = 0x42000000

       0x3f800000 * 0x42000000 = 0x105f000000000000

To actually do floating-point arithmetic, you need to do one of the following:

  • Use x87.
  • Use SSE.
  • Write your own software multiplication which separates the encodings into a signbit, exponent, and significand, xors the signbits to get the sign bit of the product, adds the exponents and adjusts the bias to get the exponent of the product, multiplies the significands and rounds to get the significand of the product, then assembles them to produce the result.

Obviously, the first two options are much simpler, but it sounds like they aren’t an option for some reason or another (though I can’t really imagine why not; x87 and SSE are "pure x86 assembly code”, as they’ve been part of the ISA for a very long time now).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!