gpt4 book ai didi

c - 在汇编中添加 float /双数

转载 作者:太空狗 更新时间:2023-10-29 17:17:22 26 4
gpt4 key购买 nike

我正在尝试使用内联汇编进行试验,我正在尝试在内联汇编中添加十进制数(不,不是整数)。问题是,当我调用以下函数时:

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

关于c - 在汇编中添加 float /双数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com