如何在x86汇编中移动两个浮点数的结果? [英] How do I move the result of a mul of two floats in x86 assembly?

查看:58
本文介绍了如何在x86汇编中移动两个浮点数的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将两个浮点数相乘,一个浮点数来自一个浮点向量(地址存储在ebx中),并与我存储在ecx中的值相乘.

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.

我已经确认输入值正确,但是,例如,如果我将32和1相乘,则EAX中的值将更改为00000000,而EDX中的值将更改为105F0000.根据我对MUL的理解,发生这种情况是因为它将结果的高位存储在EDX中,将低位存储在EDX中.问题是,如何将结果移动到输出变量(returnValue)中?这是有问题的代码段:

I have confirmed that the input values are correct, however, if I multiply 32 and 1, for example, the value in EAX changes to 00000000 and the one in EDX to 105F0000. From my understanding of MUL, this happens because it is storing the high order bits of the result in EDX and the low order ones in EDX. Question is, how do I move the result into an output variable (returnValue) ? Here is the code snippet in question:

AddColumnsIteration:
    cmp esi, 4 // If we finished storing the data
    jge NextColumn  // Move to the next column
    mov eax, [ebx][esi * SIZEOF_INT] // Get the current column
    mul ecx // Multiply it by tx
    add [returnValue][esi * SIZEOF_INT], eax // Add the data pointed at by eax to the running total
    inc esi // Element x, y, z, or w of a Vec4
    jmp AddColumnsIteration // Go back to check our loop condition  

我知道,如果我使用x87命令或SSE指令,这将容易几个数量级,但是问题的约束要求使用纯x86汇编代码.抱歉,这似乎有点基本,但是我仍在学习汇编的特质.

I am aware that if I used x87 commands or SSE instructions, this would be orders of magnitude easier, but the constrains of the problem require pure x86 assembly code. Sorry if this seems kinda basic, but I am still learning the idiosyncracies of assembly.

在此先感谢您的帮助,祝您生活愉快

Thank you in advance for the help and have a nice day

推荐答案

您正在将浮点数的表示形式乘以整数,而不是浮点数本身:

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:

  • 使用x87.
  • 使用SSE.
  • 编写自己的软件乘法,将编码分成符号位,指数和有效位数,对符号位进行异或运算以得到乘积的符号位,添加指数并调整偏差以获得乘积,然后乘以进行有效取整并取整,然后将它们组合以产生结果.

很明显,前两个选项要简单得多,但是听起来由于某些原因它们不是一个选项(尽管我真的无法想象为什么不这样做; x87和SSE 纯x86汇编代码",因为它们已经成为ISA的很长时间了.

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

这篇关于如何在x86汇编中移动两个浮点数的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆