GCC was originally a GNU C Compiler that could only handle C. It has since been extended to support more programming languages, and GCC now stands for the GNU Compiler Collection.

The GCC compiler uses AT&T/UNIX assembly syntax. There are major differences between AT&T and Intel assembly syntax. Here are some of the major differences.

(Portal: Register and Memory Addressing mode for x86 assembler guide)

Order of source and target operands

The direction of the operands in AT&T syntax is the opposite of Intel. In Intel syntax, the first is the target operand and the second is the source operand. In AT&T syntax, the first is the source operand and the second is the target operand.

For example, Intel syntax:

Op-code DST SRC (opcode target operand source operand)Copy the code

Corresponding to AT&T syntax:

Op-code SRC DST (opcode source operand target operand)Copy the code

Register naming

If you want to use the EAX register, write it directly as eAX using Intel syntax.

AT&T syntax, on the other hand, prefixes the register with %, which is written as %eax.

Immediate operand

AT&T’s immediate operands are preceded by a dollar sign.

For static ‘C’ variables, it is also preceded by a dollar sign.

In Intel syntax, for hexadecimal constants, you need to add the suffix H. For example,

80h
Copy the code

For AT&T syntax, instead of suffixing, you prefix constants with 0x. So, for a hexadecimal number, it starts with a dollar sign, then 0x, and finally a constant value. For example,

$0x80
Copy the code

Operand size

In AT&T syntax, the size of the memory operand is determined by the last character of the opcode name. Use opcode suffixes ‘b’, ‘w’, and ‘L’ to specify memory references for bytes (8 bits), words (16 bits), and words (32 bits), respectively.

Intel syntax specifies memory references for bytes (8 bits), words (16 bits), and words (32 bits) by prefixing memory operands (not opcodes) with ‘byte PTR ‘, ‘word PTR ‘, and ‘dword PTR ‘.

So, Intel syntax

mov al, byte ptr foo
Copy the code

Corresponding to AT&T syntax

movb foo, %al
Copy the code

Memory operand

In Intel syntax, the base address register is contained within the brackets ‘[‘ and ‘]’, whereas in AT&T parentheses ‘(‘ and ‘)’ are used instead.

Also, in Intel syntax, indirect memory references are similar to

[base + index*scale + disp]
Copy the code

In AT&T, it is

disp(base, index, scale)
Copy the code

Note that when constant values are used for DISP or scale, they do not need to be preceded by a dollar sign.

(Refer to the memory addressing section of registers and Memory Addressing Patterns in the x86 assembler’s Guide for further information.)

Those are some of the differences between Intel syntax and AT&T syntax. For a more complete view, consult the GNU assembler documentation.

To better understand, a comparison of some instructions is given below.

reference

www.ibiblio.org/gferg/ldp/G…

www.delorie.com/djgpp/doc/b…

About me

Public number: Binary road

Blog: binarylife. Icu

Tutorial: 996 geek.com