微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – 在汇编中添加浮点/双精度数

我试图尝试内联汇编,我试图在内联汇编中添加十进制数字(不,不是整数).问题是,当我调用以下函数时:
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;}

编译器抱怨内联汇编中的操作数大小不合适(除了push和pop指令行之外的所有汇编行).所以我必须更改为整数类型,例如unsigned long,然后它可以工作,但当然只支持整数类型;小数结果四舍五入.

有没有办法添加允许像8.4这样的十进制结果的汇编?

解决方法

我在十年内没有完成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

原文地址:https://www.jb51.cc/c/115644.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐