如何使用VC ++在宏中添加多个内联汇编指令?

时间:2011-08-11 13:22:55

标签: visual-studio-2010 compiler-construction compiler-errors inline-assembly

为什么下面的宏用1个内联汇编指令编译但不用2编译?

此代码编译正常:

#define foo(x,output,ctx) {\
    __asm\
    {\
        mov eax, 0xCAFEBEE1\
    }\
} 

但是这段代码会产生错误:

#define foo(x,output,ctx) {\
    __asm\
    {\
        mov eax, 0xCAFEBEE1\
        add eax, 5\
    }\
}

2 个答案:

答案 0 :(得分:1)

试试这个:

#define foo(x,output,ctx) {\
    __asm mov eax, 0xCAFEBEE1 \
    __asm add eax, 5\
}

答案 1 :(得分:1)

每当预处理器出现问题时,请务必使用Project + Properties,C / C ++,Preprocessor,Preprocess to a file = Yes。构建,您将在构建目录中找到.i文件。这在您的代码段中显示了这一点:

int wmain(int argc, _TCHAR* argv[])
{
    { __asm { mov eax, 0xCAFEBEE1 add eax, 5 }};
    return 0;
}

现在很明显,宏线上没有行结尾。诅咒预处理器有点让你感觉更好。然后每行修一个__asm。