← All posts

Intel vs AT&T Syntax

Intel syntax

1.In Intel syntax, the destination operand comes before the source operand. For example, in the “mov” instruction, the destination is where the data will be moved to, and the source is where the data will be taken from.

When moving a value between registers, the syntax is as follows:

mov destination, source

For instance, if you want to move the value of the stack pointer (rsp) into the base pointer (rbp), the instruction would be written as:

mov rbp, rsp

Regarding moving an immediate value into a register, you don’t need any special prefix. You simply specify the register and the immediate value.

mov rax, 42 ; Moves the immediate value 42 into the RAX register

This syntax is designed to make the assembly code more readable and intuitive, allowing programmers to better understand the flow of data within the instructions.

2.In Intel syntax, the size of the data being manipulated is often indicated using size specifiers. These specifiers provide additional information about the size of the data involved in an instruction, such as bytes, words, double words, or quad words.

For instance, consider the “mov” instruction:

mov qword ptr[rax],rbx

In this example, the qword ptr is a size specifier that indicates the size of the memory operand. It tells the assembler that the operation involves a quad word (64 bits) of data. The qword ptr doesn’t directly correspond to a mnemonic operation; rather, it provides crucial information about the size of the operation.

3.In Intel syntax, memory operands are represented using a structured format enclosed in square brackets: [base + index * scale + displacement]. This format provides a clear and organized way to indicate the memory location involved in an instruction.

Consider the following examples:

call qword ptr[rbx+rsi*4-0xe8]

In this instance, the instruction uses the “call” operation. The memory operand is represented within the square brackets. Here, rbx serves as the base register, rsi as the index register, and 4 as the scaling factor for the index. The displacement is -0xe8. Together, these components specify the precise memory location where the target procedure’s address is stored.

AT&T Syntax

In AT&T syntax , the source operand comes before the destination operand. For the “mov” instruction, this means that the source of the data is specified before the destination where the data will be moved to.

mov source, destination

For example, if you intend to move the value of the stack pointer (%rsp) into the base pointer (%rbp), the instruction would be written as:

mov %rsp, %rbp

Similarly, when moving an immediate value into a register, you use the $ prefix before the immediate value.

mov $42, %rax ; Moves the immediate value 42 into the RAX register

2.In AT&T syntax the size of the memory operands is determined from the last character of the instruction mnemonic only when there is no other way to disambiguate an instruction

movb # operates on bytes
movw # operates on word (2 bytes)
movl # operates on long (4 bytes)
movq # operate on quad word (8 bytes)

3.In AT&T syntax, memory operands are represented using a well-structured format: displacement(base,index,scale). This format offers a systematic approach to specifying memory locations within an instruction.

Here are examples that illustrate this format:

  1. Call Instruction Example:
callq *-0xe8(%rbx,%rsi,$4)

In this example, the “callq” instruction utilizes the displacement/base/index/scale format. The rbx register serves as the base, rsi as the index, and 4 as the scaling factor. The displacement of -0xe8 contributes to the complete memory address. This instruction essentially directs the program to a procedure stored at a memory location calculated using these components.In Intel it is

call qword ptr[rbx+rsi*4-0xe8]

Thank you for taking the time to read this post.