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
3
votes
1 answer

Table with addresses or registers, assembler x86

I have to write destinations and values of registers after operations. Fields written in italics are written by me. Fields written in bold (like the instructions) were written by my professor. I had tried to fill all fields but not really sure…
Orzelke
  • 71
  • 1
  • 6
3
votes
2 answers

Assembly (Intel syntax + NASM) Error: attempt to define a local label before any non-local labels

I am quite new regarding the assembly and I am trying to work with a program. So whenever I try to compile it, I get the error for the line, as listed under the comments in the code. I am wondering if anyone has any ideas why NASM detects this…
C-PROG
  • 113
  • 3
  • 12
3
votes
1 answer

GNU assembler errors on intel syntax code that used to work in 2007

I'm finally getting back to my colorforth project, which I gave up on years ago when an update to binutils broke all my sources. here's an example of what's happening: jcomeau@aspire:~$ cat /tmp/test.as .intel_syntax .arch i386 .code32 …
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
3
votes
1 answer

Position independent addressing in GNU assembler with Intel syntax

On x86-64, how do I load an address from the .data section in a position independent manner (PIC and PIE compatible) when using the GNU assembler with intel syntax. For example, using AT&T syntax, you can do this: leaq mystring(%rip), %rdi Is…
Edd Barrett
  • 3,425
  • 2
  • 29
  • 48
3
votes
2 answers

Whats is equivalent of REP stosl in intel x86

I am trying to run an instruction which I took from GAS style but when I ported this instruction to intel style, I get error like: "error: parser: instruction expected" I tried with various combination like REP movsl, REP loadsl but all giving the…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199
2
votes
1 answer

GNU as: Escape symbol names in intel_syntax

With GNU as .intel_syntax, some identifiers apparently become keywords, and writing e.g. call and to invoke a function called and results in Error: invalid use of operator "and" How do you circumvent this?
Tau
  • 496
  • 4
  • 22
2
votes
0 answers

Why can't I store data on the stack properly?

I'm writing a compiler, and it emitted the following (Intel-syntax) assembly code for Linux (x86-64): lea r13, _s1 mov qword ptr [rbp + -2*8], r13 mov r10, qword ptr [rbp + -2*8] lea r13, qword ptr [r10 + 8] If I'm reading this correctly, this code…
laptou
  • 6,389
  • 2
  • 28
  • 59
2
votes
2 answers

How to convert Intel Assembly C to AT&T C++

I trying to convert function "__cpuid" from С language to C++. I have a problem that the g++ compiler does not work with Intel assembler. I'm trying to translate this code: __asm { mov esi, CPUInfo mov eax, InfoType …
2
votes
1 answer

What is the syntax of "align" keyword/instruction in x86 assembly?

As far as I understand, some objects in the "data" section sometimes need alignment in x86 assembly. An example I've come across is when using movaps in x86 SSE: I need to load a special constant for later xors into an XMM register. The XMM register…
1ncend1ary
  • 23
  • 6
2
votes
1 answer

How to inline-assembly with Clang 11, intel syntax and substitution variables

I have a lot of trouble to make it work: I have tried the following ways: uint32_t reverseBits(volatile uint32_t n) { uint32_t i = n; __asm__ (".intel_syntax\n" "xor eax, eax \n" "inc eax \n" "myloop:…
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
2
votes
0 answers

How to create a C-callable function in assembly

I am learning assembly using Jeff Duntemann's book. I am trying to figure out how to write function that can be called in C. Say for example that I want to implement the following function in assembly: int my_function(int a, int b) { return…
tst
  • 1,117
  • 2
  • 10
  • 21
2
votes
2 answers

Intel Assembly ljmp syntax from AT&T syntax

I am trying to convert the xv6 boot code from At&t syntax to Intel syntax and I have a problem with the ljmp instruction. I am trying to learn the boot process of Intel computers and I am not particularly strong with Intel assembly. The original…
cbot
  • 117
  • 6
2
votes
1 answer

Telling GAS to use semicolons for comments in Intel syntax mode

Can I use semicolons in GAS for comment characters? I am using GAS 2.30 with the Intel syntax as below. .intel_syntax noprefix .section .text # Program entry point .globl _start _start: # Put the code number for system call mov eax, 1 …
user14222280
2
votes
0 answers

clang doesn't use intel assembly syntax

I'm trying to compile an inline assembly code in clang (Windows). So,I have the following code: int main(int, char **) { asm("mov %eax,$4;"); } I tried compiling it using clang++ -masm=intel main.cpp but it complains about mnemonic operand size…
0xDEADC0DE
  • 323
  • 3
  • 12
2
votes
0 answers

How to pass function parameters into inline assembly blocks without assigning them to register variables in c++

I am trying to write a function, which prints string to stdout without importing or . For this I am trying to pass 2 parameters (const char* and const unsigned) to the asm(...) section in c++ code. And calling write syscall. This…
a_girl
  • 959
  • 7
  • 22
1 2
3
8 9