GCC uses at&t's Assembly format, also known as the gas format (GNU asembler GNU Assembler), while Microsoft uses Intel's Assembly format.
Basic syntax
There are several differences in syntax.
1. Register naming principles
At&t |
Intel |
Description |
% Eax |
Eax |
Intel does not contain a percentage sign |
2. source/destination operand order
At&t |
Intel |
Description |
Movl % eax, % EBX |
MoV EBX, eax |
The destination operand of Intel is first, and the source operand is later |
3. Constant/immediate Number Format
At&t |
Intel |
Description |
Movl $ _ value, % EBX |
MoV eax, _ value |
Intel immediate number without the $ symbol |
Movl $ 0xd00d, % EBX |
MoV EBX, 0xd00d |
The rule also applies to the hexadecimal instant number. |
4. operand length identifier
At&t |
Intel |
Description |
Movw % ax, % BX |
MoV BX, ax |
In Intel assembly, the length of an operand is not identified by a directive symbol. |
In at&t format, each operation has a character suffix, indicating the size of the operand. For example, the mov command has three forms:
Movb transfer bytes
Movw
Movl dual-character Transfer
In many machines, 32 digits are called long words, which are caused by the historical habits of the era in which 16 characters are used as the standard.
--------- Excerpt from deep understanding of computer systems
5. Addressing Mode
At&t |
Intel |
Imm32 (basepointer, indexpointer, indexscale) |
[Basepointer + indexpointer * indexscale + imm32) |
The actual results of the two types of addressing should be
Imm32 + basepointer + indexpointer * indexscale
In at&t's Assembly format, jump commands are a bit special.
Directly jump, that is, the jump target is encoded as part of the instruction.
Example: JMP label_1
Indirect jump, that is, the jump target is read from the register or memory location. The statement is followed by an operand indicator after.
For example, JMP * % eax uses the value in register % eax as the jump target.
JMP * (% eax) uses the value in % eax as the read address and reads the jump target from the memory.
-------- From deep understanding of computer systems
The following are some examples of addressing:
At&t :' -4 (% EBP)'Equivalent to Intel :' [EBP-4]'
At&t :' Foo (, % eax, 4)'Equivalent to Intel :' [Foo + eax * 4]'
At&t :' Foo (, 1)'Equivalent to Intel' [Foo]'
At&t :' % GS: foo'
Equivalent to Intel' GS: foo'
Example from http://sourceware.org/binutils/docs/as/i386_002dMemory.html#i386_002dMemory