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
2
votes
2 answers

How to get `mov rdx, symbol` to move symbol value and not value at symbol's address in clang intel-syntax?

I have the following code which I'm using with clang on macOS: .intel_syntax noprefix .data hello: .ascii "Hello world\n" hello_len = . - hello .text .globl _main _main: mov rax, 0x2000004 mov rdi, 1 lea …
Listerone
  • 1,381
  • 1
  • 11
  • 25
2
votes
1 answer

Inline assembly addressing mode

I'm trying to write a lidt instruction in inline assembly in gcc with -masm=intel and 32 bits (-m32). So I have defined the following structures: typedef struct { uint16_t length; uint32_t base; } idt_desc; static idt_desc desc = { …
wingerse
  • 3,670
  • 1
  • 29
  • 61
2
votes
1 answer

Writing Intel Syntax in Xcode 10.3

I'm writing a C project in Xcode and I'd like to link a separate assembly file to be compiled along with the project. But I need the assembly to be written in Intel syntax since I find AT&T syntax absolutely grotesque. Unfortunately, Apple's…
Irelia
  • 3,407
  • 2
  • 10
  • 31
2
votes
0 answers

fprintf in assembly and stdout

In order to call fprintf from assembly code, I write the following ; push arguments... push dword [stdout] ; given from "extern stdout" call fprintf ; clean stack.. And it works just fine. However, I would expect that I need to write push dword…
McLovin
  • 3,295
  • 7
  • 32
  • 67
2
votes
1 answer

Why does the assembly encoding of objdump vary?

I was reading this article about Position Independent Code and I encountered this assembly listing of a function. 0000043c : 43c: 55 push ebp 43d: 89 e5 mov ebp,esp 43f: e8 16 00 00 00 …
shpark
  • 369
  • 2
  • 7
2
votes
1 answer

Assembly issue with '[' in x86 syntax for GCC

to make it short: when I am trying to assemble my code I get this Error: invalid char '[' beginning operand 2 '[esp+4]' and Error: invalid char '[' beginning operand 1 '[edx]' The most relevant code is already in the error, however I got the code…
NotNik.
  • 422
  • 3
  • 14
2
votes
2 answers

Error: junk `0x7f' after expression when assembling using Gas

I'm trying to write a 64-bit shellcode to read a file called '/proc/flag'. However, I'm getting some random errors when I'm compiling the assembly and don't know why its occuring. This is my assembly file readflag.S: .intel_syntax noprefix .global…
Varun Iyer
  • 523
  • 2
  • 10
  • 25
2
votes
1 answer

Interrupt On GAS

I'm trying to convert my simple program from Intel syntax to the AT&T(to compile it with GAS). I've successfully converted a big part of my application, but I'm still getting an error with the int(the interrupts). My function is like this: printf: …
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
2
votes
1 answer

Make library in ASM access it in C?

I know you can directly put ASM in C using ASM but I wondered is it possible to make a library in Assembly, compile it and then access functions your declared in that library from C? So I know I should use pre written libraries but this is just for…
Definity
  • 691
  • 2
  • 11
  • 31
2
votes
0 answers

Create 'raw' assembly code with gcc(Intel syntax)

I want to create some assembly code with gcc. When I use gcc -masm=intel -S test.c I get assembly code full of .def and .cfi labels which I cannot assemble. Is there a way to create assembly code without this labels? E.g.: A simple c code like: int…
kaetzacoatl
  • 1,419
  • 1
  • 19
  • 27
2
votes
2 answers

NASM Prefetching

I ran across the below instructions in the NASM documentation, but I can't quite make heads or tails of them. Sadly, the Intel documentation on these instructions is also somewhat lacking. PREFETCHNTA m8 ; 0F 18 /0 [KATMAI]…
Precursor
  • 622
  • 7
  • 18
1
vote
2 answers

What does % mean on register names in assembly language?

I tried to convert and interpret C language code into assembly language with GCC -S option. What is the difference between push %rbp and push rbp?
김우진
  • 11
  • 1
1
vote
1 answer

Choose Intel syntax for perf report assembly

My perf report shows everything in AT&T syntax: ... 0,18 │ pop %rax 0,14 │ ← retq 0,18 │a9: vmovsd -0x8(%rdi,%rsi,8),%xmm0 0,12 │af: pop %rax …
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
1
vote
1 answer

why sometimes use offset flat:label and sometimes not

I'm learning assembly using GNU Assembler using the Intel syntax and there is one think that I don't really understand. Say for example this code right here : .intel_syntax noprefix .data string: .asciz "hello world" .text .global entry .type…
Liwinux
  • 87
  • 6
1
vote
0 answers

GNU AS confusion between memory and immediate depending on declaration order?

I've searched the web but haven't found anything that answers my question so hopefully someone on here will be able to answer it. Using GNU AS with Intel syntax (.intel_syntax noprefix) gives mixed results. Using: mov ax, variable variable =…
1 2 3
8 9