ç内联汇编 - 对“FST”数类型不匹配 [英] C Inline assembly - Operand type mismatch for 'fst'
问题描述
哎我试着去学习如何编写汇编code在我的C程序。我明白在装配整数,但花车继续我绊倒。
Hey Im trying to learn how to write assembly code in my C programs. I understand integers in assembly but floats continue to trip me up.
double asmSqrt(double x) {
double o;
__asm__ ("fld %1;"
"fsqrt;"
"fst %0;"
: "=g" (o)
: "g" (x)
);
return o;
}
正如你可以看到我只是试图找到x的平方根。但每当我尝试编译它,我得到一个数类型不匹配错误。
As you can see Im just trying to find the square root of x. But whenever I try to compile it I get an operand type mismatch error.
我跟这里使用相同的语法:的http:/ /www.$c$cproject.com/KB/cpp/edujini_inline_asm.aspx?display=Print
I followed the same syntax used here: http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx?display=Print
PS:Im在Windows XP中使用的MinGW GCC
PS: Im using MinGW GCC on Windows XP
推荐答案
您需要明确指定哪些 FLD
和 FST
指令形式你想要的。否则,编译器不知道你的操作应该是什么大小为。这code对我的作品在这里:
You need to explicitly specify which fld
and fst
instruction variants you want. Otherwise, the compiler doesn't know what size your operand is supposed to be. This code works for me here:
__asm__ ("fldl %1 ;"
"fsqrt ;"
"fstl %0 ;"
: "=g" (o)
: "g" (x)
);
您可以使用反汇编要仔细检查,正确的运算codeS 64位FLD和FST( DD / 0
和 DD / 2
)越来越发出。
You can use a disassembler to double-check that the right opcodes for 64-bit FLD and FST (DD/0
and DD/2
) are getting emitted.
这篇关于ç内联汇编 - 对“FST”数类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!