-->

添加在装配浮点/双号(Adding floating point/double numbers in

2019-09-20 23:44发布

我试图用内联汇编进行试验,我试图内联汇编添加十进制数(不,不是整数)。 问题是,当我拨打下列功能:

inline double ADD(double num1, double num2) {
  double res;
_asm{

    push eax; push the former state of eax onto stack
    mov eax, num1;
    add eax, num2;
    mov res, eax;
    pop eax; restore the former state of eax now that we are done   
     }  return res;}

编译器会抱怨在联汇编不当操作数大小(不包括推入和弹出指令行组件的ALL线)。 所以我不得不改变为整数类型,如无符号长,然后它的工作原理,但当然只支持整数类型; 小数结果四舍五入。

有什么办法来组装,允许像8.4小数结果补充的吗?

Answer 1:

我没有做过的x87汇编了十年,但它应该是这样的:

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


Answer 2:

你可能想的指令是ADDSD,但我不知道。

这里的链接英特尔指令集手册。 http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html/

他们用来寄给你免费硬拷贝,但看起来这不再是真实的。



Answer 3:

你需要一个不同的指令集来处理浮点数。 这里的介绍应该帮助: x86汇编:浮点



Answer 4:

答案上面,你必须操作数推到FP堆栈,弹出的结果是正确的。

然而,“不正确的操作数大小”错误的近因是“扩展”寄存器,“e__”(例如EAX)是32位和双精度浮点数是64位。



Answer 5:

尝试这个:

_asm{

movq xmm0,[num1]
addpd xmm0, [num2];
movq [res],xmm0
// sse2
 }


文章来源: Adding floating point/double numbers in assembly
标签: c assembly x86 x87