12.11 Difference Between AT&T and Intel Assembly Syntax

The syntax for assembly language used by us is known as the AT&T syntax. It is the one supported by the GNU tool chain that comes as a standard with every Linux distribution. However, the official syntax for x86 assembly language (known as the Intel syntax) is different. It is the same assembly language for the same platform, but it looks different. Some of the major differences between the two syntaxes are as follows. In Intel syntax:

  • Registers are not prefixed with the percent sign (%).
  • A dollar sign ($) is not required to do immediate-mode addressing. Instead, non-immediate addressing is accomplished by surrounding the address with brackets ([]).
  • The instruction name does not include the size of data being moved. If that is ambiguous, it is explicitly stated as BYTE, WORD or DWORD immediately after the instruction name.
  • The way that memory addresses are represented is much different (shown below).
  • Because the x86 processor line originally started out as a 16-bit processor, most literature about x86 processors refer to “words” as 16-bit values, and call 32-bit values “double words”. However, we use the term “word” to refer to the standard register size on a processor, which is 32-bits on a modern x86 processor. The syntax also keeps this naming convention – DWORD stands for “double word” in Intel syntax and is used for standard-sized registers, which we would call simply a “word”.
  • Intel assembly language has the ability to address memory as a segment/offset pair. We did not mention this because Linux does not support segmented memory, rather it uses a flat memory model and is therefore irrelevant to normal Linux programming.
  • Other differences are of rather minor nature.

To show some of the differences, consider the following instruction:

movl %eax, 8(%ebx,%edi,4)

In Intel syntax, this would be written as:

mov [8 + %ebx + 4 * edi], eax

The memory reference is a bit easier to read than its AT&T counterpart because it spells out exactly how the address will be computed. However, the order of operands in Intel syntax can be confusing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36