汇编代码语法:Visual Studio与G ++ [英] Assembler code syntax: Visual Studio vs G++

查看:123
本文介绍了汇编代码语法: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 ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆