开发者

How can I add more than one inline assembly instruction in a macro with VC++?

开发者 https://www.devze.com 2023-03-27 22:58 出处:网络
Why does the following macro compile with 1 inline assembly instruction but not with 2? This code compiles OK:

Why does the following macro compile with 1 inline assembly instruction but not with 2?

This code compiles OK:

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

but this code produces an err开发者_运维问答or:

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


Try this:

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


Whenever you have a problem with the pre-processor, be sure to use Project + Properties, C/C++, Preprocessor, Preprocess to a file = Yes. Build and you'll find a .i file in the build directory. Which shows this on your snippet:

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

Now it is obvious, there are no line endings on the macro lines. Curse at the preprocessor a bit to make you feel better. Then one __asm per line to fix.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号