与AT&T相比,Intel汇编语法的局限性

时间:2022-05-25 03:19:14

To me, Intel syntax is much easier to read. If I go traipsing through assembly forest concentrating only on Intel syntax, will I miss anything? Is there any reason I would want to switch to AT&T (outside of being able to read others' AT&T assembly)? My first clue is that gdb uses AT&T by default.

对我来说,英特尔语法更容易阅读。如果我在汇编森林中闲逛,只专注于英特尔语法,我会错过什么吗?我有什么理由想转到AT&T(除了能够阅读别人的AT&T汇编之外)?我的第一个线索是gdb默认使用AT&T。

If this matters, my focus is only on any relation assembly and syntax may have to Linux/BSD and the C language.

如果这很重要,我只关注Linux/BSD和C语言的任何关系组装和语法。

7 个解决方案

#1


63  

There is really no advantage to one over the other. I agree though that Intel syntax is much easier to read. Keep in mind that, AFAIK, all GNU tools have the option to use Intel syntax also.

一个人比另一个人没有任何优势。我同意Intel语法更容易阅读。记住,AFAIK,所有GNU工具都可以选择使用Intel语法。

It looks like you can make GDB use Intel syntax with this:

看起来你可以让GDB使用Intel语法:

set disassembly-flavor intel

GCC can do Intel syntax with -masm=intel.

GCC可以用-masm= Intel处理Intel语法。

#2


35  

The primary syntax for the GNU assembler (GAS) is AT&T. Intel syntax is a relatively new addition to it. x86 assembly in the Linux kernel is in AT&T syntax. In the Linux world, it's the common syntax. In the MS world, Intel syntax is more common.

GNU汇编程序(GAS)的主要语法是AT&T。Intel语法是相对较新的添加。在Linux内核中的x86汇编是在AT&T语法中。在Linux世界中,这是常见的语法。在MS世界中,Intel语法更常见。

Personally, I hate AT&T syntax. There are plenty of free assemblers (NASM, YASM) along with GAS that support Intel syntax too, so there won't be any problems doing Intel syntax in Linux.

我个人讨厌AT&T语法。有很多免费的汇编程序(NASM, YASM)和支持Intel语法的GAS,所以在Linux中使用Intel语法不会有任何问题。

Beyond that, it's just a syntactic difference. The result of both will be the same x86 machine code.

除此之外,这只是语法上的差异。两者的结果都是相同的x86机器代码。

#3


31  

There is really no advantage to one over the other. I disagree though that Intel syntax is much easier to read, because personally I hate Intel syntax. Keep in mind that, AFAIK, all GNU tools have the option to use Intel syntax also.

一个人比另一个人没有任何优势。我不同意Intel语法更容易阅读,因为我个人讨厌Intel语法。记住,AFAIK,所有GNU工具都可以选择使用Intel语法。

at&t noprefix                   intel
mov eax, -4(ebp,edx,4)          mov DWORD PTR[-4 +ebp +edx *4], eax
mov eax, -4(ebp)                mov DWORD PTR[-4 +ebp], eax
mov edx, (ecx)                  mov DWORD PTR[ecx], edx
lea (   ,eax,4), eax            lea eax, DWORD PTR[8 + eax*4]
lea (eax,eax,2), eax            lea eax, DWORD PTR[eax*2+eax]

...and it gets more complicated with more complex instructions

…更复杂的指令会更复杂。

'nuff said.

足够地说。

PS: This answer exists mainly for the reason of highlighting (IMHO) weaknesses in some other answers, which are actually not answers, but opinions. And of course this answer in reality is only my humble opinion.

PS:这个答案存在的主要原因是在其他一些答案中突出(IMHO)的弱点,这些弱点实际上不是答案,而是观点。当然,这个答案在现实中只是我的拙见。

PPS: I do not hate Intel syntax, I just don't care.

我不讨厌英特尔语法,我不在乎。

#4


19  

It's the "same language", in that it compiles down to the same machine code, has the same opcodes, etc. On the other hand, if you are using GCC at all, you will probably want to learn AT&T syntax, just because it's the default--no changing compiler options, etc. to get it.

它是“相同的语言”,因为它编译成相同的机器代码,拥有相同的操作码等等。另一方面,如果您使用GCC,您可能想学习AT&T语法,因为它是默认的——没有修改编译器选项等等来获得它。

I too cut my teeth on Intel-syntax x86 ASM (on DOS, too) and found it more intuitive initially when switching to C/UNIX. But once you learn AT&T it'll look just as easy.

我也在Intel-syntax x86(也在DOS上)上有所建树,在切换到C/UNIX时,我发现它更直观。但是一旦你学会了AT&T,它就会变得很简单。

I wouldn't give it that much thought---it's easy to learn AT&T once you know Intel, and vice-versa. The actual language is much harder to get in your head than the syntax. So by all means just focus on one and then learn the other when it comes up.

我不会多想的---一旦你了解了英特尔,学习AT&T很容易,反之亦然。实际的语言比语法更难理解。所以无论如何,只要关注其中一个,然后在它出现时学习另一个。

#5


16  

It's a sign of professionalism that you are willing to adjust to whatever is in use. There is no real advantage to one or the other. The intel syntax is common in the Microsoft world, AT&T is the standard in Linux/Unix. Since there's no advantage to either one, people tend to imprint on whatever they saw first. That said, a professional programmer raises above things like that. Use whatever they use at work, or in the domain that you're working in.

这是一种职业精神的表现,你愿意去适应任何正在使用的东西。两者之间没有真正的优势。英特尔的语法在微软世界中很常见,AT&T是Linux/Unix中的标准。因为两者都没有优势,所以人们往往会在他们最先看到的东西上留下印记。也就是说,一个专业的程序员会提出这样的问题。使用他们在工作中使用的任何东西,或者在你工作的领域中使用的任何东西。

#6


6  

Intel syntax covers everything (assuming the assembler/disassembler is up to date with the latest junk Intel added to their instruction set). I'm sure at&t is the same.

Intel语法涵盖了所有内容(假设汇编/反汇编程序是最新的,最新的垃圾处理器添加到他们的指令集)。我相信at&t也一样。

at&t                             intel
movl -4(%ebp, %edx, 4), %eax     mov eax, [ebp-4+edx*4]
movl -4(%ebp), %eax              mov eax, [ebp-4]
movl (%ecx), %edx                mov edx, [ecx]
leal 8(,%eax,4), %eax            lea eax, [eax*4+8]
leal (%eax,%eax,2), %eax         lea eax, [eax*2+eax]

...and it gets more complicated with more complex instructions

…更复杂的指令会更复杂。

'nuff said.

足够地说。

#7


3  

My first assembly language was MIPS, which I've noticed is very similar to the ATT syntax. So I prefer the ATT syntax, but it doesn't really matter as long as you can read it.

我的第一种汇编语言是MIPS,我注意到它与ATT语法非常相似。所以我更喜欢ATT语法,但只要你能读懂它就无所谓了。

#1


63  

There is really no advantage to one over the other. I agree though that Intel syntax is much easier to read. Keep in mind that, AFAIK, all GNU tools have the option to use Intel syntax also.

一个人比另一个人没有任何优势。我同意Intel语法更容易阅读。记住,AFAIK,所有GNU工具都可以选择使用Intel语法。

It looks like you can make GDB use Intel syntax with this:

看起来你可以让GDB使用Intel语法:

set disassembly-flavor intel

GCC can do Intel syntax with -masm=intel.

GCC可以用-masm= Intel处理Intel语法。

#2


35  

The primary syntax for the GNU assembler (GAS) is AT&T. Intel syntax is a relatively new addition to it. x86 assembly in the Linux kernel is in AT&T syntax. In the Linux world, it's the common syntax. In the MS world, Intel syntax is more common.

GNU汇编程序(GAS)的主要语法是AT&T。Intel语法是相对较新的添加。在Linux内核中的x86汇编是在AT&T语法中。在Linux世界中,这是常见的语法。在MS世界中,Intel语法更常见。

Personally, I hate AT&T syntax. There are plenty of free assemblers (NASM, YASM) along with GAS that support Intel syntax too, so there won't be any problems doing Intel syntax in Linux.

我个人讨厌AT&T语法。有很多免费的汇编程序(NASM, YASM)和支持Intel语法的GAS,所以在Linux中使用Intel语法不会有任何问题。

Beyond that, it's just a syntactic difference. The result of both will be the same x86 machine code.

除此之外,这只是语法上的差异。两者的结果都是相同的x86机器代码。

#3


31  

There is really no advantage to one over the other. I disagree though that Intel syntax is much easier to read, because personally I hate Intel syntax. Keep in mind that, AFAIK, all GNU tools have the option to use Intel syntax also.

一个人比另一个人没有任何优势。我不同意Intel语法更容易阅读,因为我个人讨厌Intel语法。记住,AFAIK,所有GNU工具都可以选择使用Intel语法。

at&t noprefix                   intel
mov eax, -4(ebp,edx,4)          mov DWORD PTR[-4 +ebp +edx *4], eax
mov eax, -4(ebp)                mov DWORD PTR[-4 +ebp], eax
mov edx, (ecx)                  mov DWORD PTR[ecx], edx
lea (   ,eax,4), eax            lea eax, DWORD PTR[8 + eax*4]
lea (eax,eax,2), eax            lea eax, DWORD PTR[eax*2+eax]

...and it gets more complicated with more complex instructions

…更复杂的指令会更复杂。

'nuff said.

足够地说。

PS: This answer exists mainly for the reason of highlighting (IMHO) weaknesses in some other answers, which are actually not answers, but opinions. And of course this answer in reality is only my humble opinion.

PS:这个答案存在的主要原因是在其他一些答案中突出(IMHO)的弱点,这些弱点实际上不是答案,而是观点。当然,这个答案在现实中只是我的拙见。

PPS: I do not hate Intel syntax, I just don't care.

我不讨厌英特尔语法,我不在乎。

#4


19  

It's the "same language", in that it compiles down to the same machine code, has the same opcodes, etc. On the other hand, if you are using GCC at all, you will probably want to learn AT&T syntax, just because it's the default--no changing compiler options, etc. to get it.

它是“相同的语言”,因为它编译成相同的机器代码,拥有相同的操作码等等。另一方面,如果您使用GCC,您可能想学习AT&T语法,因为它是默认的——没有修改编译器选项等等来获得它。

I too cut my teeth on Intel-syntax x86 ASM (on DOS, too) and found it more intuitive initially when switching to C/UNIX. But once you learn AT&T it'll look just as easy.

我也在Intel-syntax x86(也在DOS上)上有所建树,在切换到C/UNIX时,我发现它更直观。但是一旦你学会了AT&T,它就会变得很简单。

I wouldn't give it that much thought---it's easy to learn AT&T once you know Intel, and vice-versa. The actual language is much harder to get in your head than the syntax. So by all means just focus on one and then learn the other when it comes up.

我不会多想的---一旦你了解了英特尔,学习AT&T很容易,反之亦然。实际的语言比语法更难理解。所以无论如何,只要关注其中一个,然后在它出现时学习另一个。

#5


16  

It's a sign of professionalism that you are willing to adjust to whatever is in use. There is no real advantage to one or the other. The intel syntax is common in the Microsoft world, AT&T is the standard in Linux/Unix. Since there's no advantage to either one, people tend to imprint on whatever they saw first. That said, a professional programmer raises above things like that. Use whatever they use at work, or in the domain that you're working in.

这是一种职业精神的表现,你愿意去适应任何正在使用的东西。两者之间没有真正的优势。英特尔的语法在微软世界中很常见,AT&T是Linux/Unix中的标准。因为两者都没有优势,所以人们往往会在他们最先看到的东西上留下印记。也就是说,一个专业的程序员会提出这样的问题。使用他们在工作中使用的任何东西,或者在你工作的领域中使用的任何东西。

#6


6  

Intel syntax covers everything (assuming the assembler/disassembler is up to date with the latest junk Intel added to their instruction set). I'm sure at&t is the same.

Intel语法涵盖了所有内容(假设汇编/反汇编程序是最新的,最新的垃圾处理器添加到他们的指令集)。我相信at&t也一样。

at&t                             intel
movl -4(%ebp, %edx, 4), %eax     mov eax, [ebp-4+edx*4]
movl -4(%ebp), %eax              mov eax, [ebp-4]
movl (%ecx), %edx                mov edx, [ecx]
leal 8(,%eax,4), %eax            lea eax, [eax*4+8]
leal (%eax,%eax,2), %eax         lea eax, [eax*2+eax]

...and it gets more complicated with more complex instructions

…更复杂的指令会更复杂。

'nuff said.

足够地说。

#7


3  

My first assembly language was MIPS, which I've noticed is very similar to the ATT syntax. So I prefer the ATT syntax, but it doesn't really matter as long as you can read it.

我的第一种汇编语言是MIPS,我注意到它与ATT语法非常相似。所以我更喜欢ATT语法,但只要你能读懂它就无所谓了。