当我尝试编译这段代码时:
#include <stdio.h>
main(int argc, char *argv[]) {
double y = 0;
__asm__ ("fldl $150;"
"fsqrt;"
"fstl %0;" : : "g" (y) );
printf("%f\n", y);
return 0;
}
我收到这个错误:
sqrt.c: Assembler messages:
sqrt.c:6: Error: suffix or operands invalid for `fld'
为什么这行不通?为什么我不能将数字“150”压入堆栈进行浮点运算?
最佳答案
我不知道有哪一种汇编语言支持立即使用的文字浮点常量。通常的方法是声明包含浮点常量的初始化存储并引用它:
const1: dq 1.2345
...
fldl const1
对于你给出的例子,可以更直接地做到这一点:
printf ("%f\n", sqrt (150));
否则,这一定是一个人为复杂的项目,也许是家庭作业。
关于c - 如何使用内联汇编指定立即 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6514537/