我正在将一些代码移植到Linux(无论如何,还是要在Linux上构建),但是遇到了问题. 在VS中,您可以像这样标记出一些嵌入式asm:
I''m porting some code over to Linux (well, building it on Linux anyway) and I''ve hit a problem. In VS you mark out some inline asm like this:
__asm { mov eax, something }但对于G ++,则需要:
but for G++ it would need:
asm ( "mov eax, something" );两个编译器似乎都无法使用其他语法,是否有什么办法可以避免使用语法稍有不同的重复副本? 注意:我也知道Intel/AT& T的语法差异,我已经可以为其设置选项.
Neither compiler seems to be able to use the other syntax, is there anything I can do to avoid having duplicate copies with slightly different syntax? Note: I''m also aware of the Intel / AT&T syntax differences, which I can already set options for.
推荐答案有些像... something as crusty as ... // ASM abstracting header #ifdef GPLUSPLUS #define BEGIN_INLINE_ASM asm{ #define END_INLINE_ASM }; #define MNEM2(a,b) "a,b" #endif #ifdef VSTUDIO #define BEGIN_INLINE_ASM __asm{ #define END_INLINE_ASM } #define MNEM2(a,b) a,b #endif
然后在您的代码"中
then in your ''code''
BEGIN_INLINE_ASM MNEM(mov eax,something) END_INLINE_ASM..也许吗? 如果失败,将asm放在另一个扩展名的文件中,并使用一个解析器将其分类为"c",并建立在编译器之前运行该解析器的规则? 确实取决于您内联多少代码
.. maybe? Failing that, have the asm in files of another extension, and a parser that sorts them out into ''c'', and build rule that runs that parser before the compiler? Really depends how much code you''re in-lining
更多推荐
汇编代码语法:Visual Studio与G ++
发布评论