NASM VS GAS(实际差异) [英] NASM Vs GAS (Practical differences)

查看:288
本文介绍了NASM VS GAS(实际差异)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是要引发一场Intel与AT& T之战(无论如何,现在都是话题点,因为它们都支持Intel语法),或者问哪一个本质上更好",我只是想知道两者之间的实际差异.选择一个.

I'm not trying to prompt an Intel vs AT&T war (moot point anyway, now that they both support Intel syntax) or ask which one is "better" per se, I just want to know the practical differences in choosing one or the other.

基本上,几年前当我拿起一些基本的x86组件时,除了我读过的书外,我无缘无故地使用了NASM,这使我坚定而自愿地进入了NASM阵营.从那时起,使用组装的原因就很少了,因此我没有机会尝试使用GAS.

Basically, when I was picking up some basic x86 assembly a few years back, I used NASM for no reason other than the book I was reading did too -- which put me firmly but involuntarily in the NASM camp. Since then, I've had very few causes to use assembly so I haven't had the opportunity to try GAS.

请记住,它们都支持Intel语法(我个人更喜欢),并且至少在理论上应生成相同的二进制文件(我知道它们可能不会,但不应更改其含义),这是什么?赞成一个或另一个的理由?

Bearing in mind that they both support Intel syntax (which I personally prefer) and should, theoretically at least, produce the same binary (I know they probably won't but the meaning shouldn't be changed), what are the reasons to favour one or the other?

是命令行选项吗?宏?非助记关键字?还是其他?

Is it command line options? Macros? Non-mnemonic keywords? Or something else?

谢谢:)

推荐答案

NASM实际上使用了自己的Intel语法变体,与Intel官方文档中使用的MASM语法不同.操作码名称和操作数顺序与Intel中的相同,因此乍一看这些指令看起来是相同的,但是任何重要的程序都会有所不同.例如,对于MASM,MOV ax, foo使用的指令取决于foo的类型,而NASM没有类型,并且总是汇编成立即移动指令.当无法隐式确定操作数的大小时,MASM要求使用类似DWORD PTR的名称,而NASM使用DWORD表示相同的名称.除了指令助记符,基本操作数格式和顺序以外,大多数语法都是不同的.

NASM actually uses its own variation of Intel syntax, different from the MASM syntax used in Intel's official documentation. The opcode names and operand orders are the same as in Intel so the instructions look the same at first glance, but any significant program will have differences. For example with MASM the instruction used by MOV ax, foo depends on the type of foo, while NASM doesn't have types and this always assembles to a move immediate instruction. When the size of an operand can't be determined implicitly MASM requires something like DWORD PTR to be used where NASM uses DWORD to mean the same thing. Most of the syntax beyond the instruction mnemonics and basic operand format and ordering is different.

就功能而言,NASM和GAS几乎相同.两者都具有汇编宏设施,尽管NASM的设施更广泛,更成熟.许多GAS源代码文件使用C预处理程序,而不是GAS自己的宏支持.

In terms of functionality NASM and GAS are pretty much the same. Both have assembler macro facilities, though NASM's is more extensive and more mature. Many GAS source code files use the C preprocessor instead of GAS's own macro support.

两个汇编器之间的最大区别是它们对16位代码的支持. GAS不支持定义x86段.使用GAS,您只能创建简单的单段16位二进制映像,基本上只需要引导扇区和.COM文件即可. NASM完全支持段,并支持OMF格式的目标文件,您可以将其与合适的链接器一起使用,以创建分段的16位可执行文件.

The biggest difference between the two assemblers is their support for 16-bit code. GAS doesn't have any support for defining x86 segments. With GAS you're limited to creating simple single-segment 16-bit binary images, basically just boot sectors and .COM files. NASM has full support for segments and supports OMF format object files which you can use with a suitable linker to create segmented 16-bit executables.

除了OMF目标文件格式外,NASM还支持GAS不支持的多种格式. GAS通常仅支持其运行的计算机的本机格式,基本上是ELF,PE-COFF或MACH-O.如果要支持其他格式,则需要为该格式构建GAS的交叉编译"版本.

In addition to the OMF object file format, NASM supports a number of formats that GAS doesn't. GAS normally only supports the native format for the machine its running on, basically ELF, PE-COFF, or MACH-O. If you want to support a different format you need to build a "cross-compiling" version of GAS for that format.

另一个显着区别是,GAS支持创建DWARF和Windows 64位展开信息(Windows x64 ABI要求后者),而使用NASM,则必须自己创建部分并填写数据.

Another notable difference is that GAS has support for creating DWARF and Windows 64-bit unwind information (the later required by the Windows x64 ABI) while with NASM you have to create the sections and fill in the data yourself.

这篇关于NASM VS GAS(实际差异)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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