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

前端 未结 1 1692
长发绾君心
长发绾君心 2021-01-25 16:38

I am currently trying to multiply two floats, one that comes from a float vector (address stored in ebx) and against the value I stored in ecx.

I have confirmed that the

相关标签:
1条回答
  • 2021-01-25 17:03

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

    0 讨论(0)
提交回复
热议问题