问题描述
我试图用内联汇编实验,和我试图内联汇编加入十进制数(不,不是整数)。问题是,当我打电话下面的函数:
I am trying to experiment with inline assembly, and I am trying to add decimal numbers (no, NOT integers) in inline assembly. Issue is, when I call the following function:
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指令行大会的所有行)。所以,我必须改变为整数类型,如无符号长,然后它的作品,当然,只支持整数类型;小数结果四舍五入。
The compiler complains of improper operand size at the inline assembly (ALL lines of assembly excluding the push and pop instruction lines). So I have to change to an integer type, such as unsigned long, and then it works, but of course only supports integer types; decimal results are rounded.
有没有办法在程序集添加,允许像8.4小数的结果?
Is there any way to add in assembly that allows for decimal results like 8.4?
推荐答案
我没有做过的x87装配了十年,但它应该是这样的:
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
这篇关于添加汇编浮点/双号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!