Questions tagged [intel-syntax]

Intel syntax (as opposed to AT&T syntax) is an x86 assembly syntax using "opcode dst, src", square brackets for memory operands, and keywords to set the size of an operand: e.g. add dword [eax], 123. There are two main flavours of Intel syntax: NASM-style and MASM/TASM-style.

Intel Syntax is used in Intel's (and AMD's) manuals, and by many assemblers. See the tag wiki for links to those and to assembler manuals.

The other major syntax for x86 assembly is AT&T (). Other syntaxes include HLA, and the Go assembler's x86 syntax (which looks like 16-bit, using AX to actually mean AL/AX/EAX/RAX depending on the operand-size).

All flavours of Intel Syntax share these characteristics:

  • Parameter order: destination <- source. pinsrd xmm0, eax, 2
  • Square brackets indicate a memory operand: add eax, [esi] (but beware the differences between NASM and MASM for symbols, offset vs. just omitting the []).
  • Operand size: implied by a register name, or specified explicitly with dword (NASM) or dword ptr (MASM) in instructions with no register operand.
    add qword [fs:rdi + r10], 123. (Put the size operator on the memory operand.)
  • Immediate values and other numeric constants: No $ prefix. For hex, use a trailing h, and make sure the number starts with a 0. e.g. 0deadbeefH. Some Intel-syntax assemblers (e.g. NASM) also support C-style 0xdeadbeef constants, but all support trailing-h. Binary constants can use a b suffix.

The two major flavours of Intel syntax are NASM-style and MASM/TASM style.
How to know if an assembly code has particular syntax (emu8086, NASM, TASM, ...)?
and x86, difference between BYTE and BYTE PTR

The GNU assembler, as/gas (and compatible ones like clang's built-in assembler) supports a .intel_syntax noprefix directive to switch to a mode with MASM-like syntax. There isn't official documentation for GAS's intel-syntax. See also Distinguishing memory from constant in GNU as .intel_syntax. If you're not sure, encode the machine-code you want somehow (e.g. using another assembler) and disassemble in Intel syntax with objdump -drwC -Mintel.


131 questions
180
votes
3 answers

How do you use gcc to generate assembly code in Intel syntax?

The gcc -S option will generate assembly code in AT&T syntax, is there a way to generate files in Intel syntax? Or is there a way to convert between the two?
hyperlogic
  • 7,525
  • 7
  • 39
  • 32
97
votes
7 answers

Limitations of Intel Assembly Syntax Compared to AT&T

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)?…
oevna
  • 1,246
  • 1
  • 11
  • 10
51
votes
3 answers

What does the dollar sign ($) mean in x86 assembly when calculating string lengths like "$ - label"?

For example, if we were writing a simple hello world type program, the .data section might contain something like: section .data msg db 'Enter something: ' len equ $ - msg What does the $ in this example represent, and why does $…
InvalidBrainException
  • 2,312
  • 8
  • 32
  • 41
45
votes
2 answers

What do square brackets mean in x86 assembly?

I'm very new to assembly, and have some very basic questions. What is the difference between these four commands? mov ebx, eax mov [ebx], eax mov ebx, [eax] mov [ebx], [eax] They say that the brackets mean "get the value of the address". But what,…
ineedahero
  • 715
  • 1
  • 5
  • 10
23
votes
4 answers

Questions about AT&T x86 Syntax design

Can anyone explain to me why every constant in AT&T syntax has a '$' in front of it? Why do all registers have a '%'? Is this just another attempt to get me to do a lot of lame typing? Also, am I the only one that finds: 16(%esp) really…
Skeen
  • 4,614
  • 5
  • 41
  • 67
22
votes
1 answer

A couple of questions about [base + index*scale + disp] and AT&T disp(base, index, scale)

The general form for memory addressing in Intel and AT&T Syntax is the following: [base + index*scale + disp] # Intel, including GAS .intel_syntax noprefix disp(base, index, scale) # AT&T My questions are the following: Can base and…
user4344762
17
votes
3 answers

How to set a variable in GCC with Intel syntax inline assembly?

Why doesn't this code set temp to 1? How do I actually do that? int temp; __asm__( ".intel_syntax;" "mov %0, eax;" "mov eax, %1;" ".att_syntax;" : : "r"(1), "r"(temp) : "eax"); printf("%d\n", temp);
user541686
  • 205,094
  • 128
  • 528
  • 886
14
votes
3 answers

Commenting syntax for x86 AT&T syntax assembly

The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments. What is the comment syntax for AT&T assembly?
ihsoy ih
  • 1,008
  • 2
  • 10
  • 20
11
votes
3 answers

NASM (Intel) versus AT&T Syntax: what are the advantages?

I'm going through the Intel processor documentation and writing some basic assembly code at the same time. I have both nasm and as (GAS) on my server and I understand the basic differences of both assemblers. In the long run: Focusing on which of…
user613857
11
votes
1 answer

Using ".intel_syntax noprefix" how can I get memory address of a label?

I'm learning how to create real mode programs assembled and linked with: GCC Assembler version 2.25 Binutils version 2.25 GCC version 5.2.0 I use Intel syntax without prefixes specified with .intel_syntax noprefix I want to load the address of a…
TheDome
  • 343
  • 3
  • 10
9
votes
1 answer

Distinguishing memory from constant in GNU as .intel_syntax

I have an instruction written in Intel syntax (using gas as my assembler) that looks like this: mov rdx, msg_size ... msg: .ascii "Hello, world!\n" .set msg_size, . - msg but that mov instruction is being assembled to mov 0xe,%rdx, rather than…
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
9
votes
2 answers

Intel x86 to ARM assembly conversion

I am currently learning ARM assembly language; To do so, I am trying to convert some x86 code (AT&T Syntax) to ARM assembly (Intel Syntax) code. __asm__("movl $0x0804c000, %eax;"); __asm__("mov R0,#0x0804c000"); From this document, I learn that…
pistal
  • 2,310
  • 13
  • 41
  • 65
8
votes
1 answer

How to determine if the registers are loaded right to left or vice versa

When reviewing gdb output and looking at the assembly calls, usually I can find a command using hard-coded values to determine whether the registers are being loaded right to left or vice versa. Usually something like the following: sub rsp,…
Unhandled Exception
  • 1,427
  • 14
  • 30
8
votes
2 answers

Memory addressing with GNU Assember Intel Syntax

I read this page containing a good list of differences between Intel and AT&T syntax for GAS but it did not cover the case of specifying an address with a displacement only. Here I've assembled four lines with AT&T syntax: …
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
7
votes
1 answer

GCC inline ASM with variable

I'm trying to use the following ASM inline code in my C++ source, given for Visual Studio : __asm { mov ecx,target } where target is a void* pointer. I don't know how to convert this into GCC-compatible code. I know that GCC use synthax like…
MadMass
  • 313
  • 3
  • 10
1
2 3
8 9