Adding floating point/double numbers in assembly

佐手、 提交于 2019-12-05 07:18:05

I haven't done x87 assembly in a decade, but it should be something like:

fld num1   ; load num1 and push it onto the fpu stack
fld num2   ; load num2 and push it onto the fpu stack
faddp      ; pop two numbers, add them, push sum on the stack
fstp res   ; pop sum from the stack and store it in res

The instruction you probably want is ADDSD, but I don't know for sure.

Here's the link to Intel's instruction set manuals. http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html/

They used to mail you hard copies for free, but it looks like that's no longer true.

You need a different set of instructions to manipulate floating point numbers. Here's an introduction that should help: x86 Assembly: Floating Point

The answer, above, that you have to push the operands onto the FP stack and pop the result is correct.

However, the proximate cause of the "improper operand size" errors is that "extended" registers, "e__" (e.g. eax) are 32-bit and double-precision floating-point numbers are 64-bit.

huseyin tugrul buyukisik

Try this:

_asm{

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