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