汇编代码语法:Visual Studio与G ++

编程入门 行业动态 更新时间:2024-10-27 08:37:58
本文介绍了汇编代码语法:Visual Studio与G ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将一些代码移植到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 ++

本文发布于:2023-07-30 00:19:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   代码   Studio   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!