我正在使用 mingw 4.7.2。
谁能告诉我这个 MACRO 有什么问题
我只想做一个简单的 asm 宏,它添加两个 int 并将结果放入 result
变量
#define add(result,a,b) \
__asm__ __volatile__( \
" movl %1, %%eax \n" \
" addl %2, %%eax \n" \
" movl %%eax, %0 \n" \
" :"=r"(result) \
:"r"(a),"r"(b) )
编译器提示error: missing terminating "character
提前致谢
最佳答案
#define add(result,a,b) \
__asm__ __volatile__( \
" movl %1, %%eax \n" \
" addl %2, %%eax \n" \
" movl %%eax, %0 \n" \
" :"=r"(result) \ // <---- This line starts with a " for no reason.
:"r"(a),"r"(b) )
标记的行以 "
开头,然后将所有其他字符串偏移到宏的末尾。只需删除它即可。
即你的最后两行实际上是:
" :"=r"(result) :"r"(a),"r"(b) )
<----str-----> <----str---> <----> <-----.... No end
当你真正想要的时候
:"=r"(result) :"r"(a),"r"(b) )
<--> <-> <->
关于c++ - 将内联汇编添加到 C 宏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980524/