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
1
vote
1 answer

NASM/Yasm drops CALL after comment ending with backslash

I am currently trying to built my own boot loader and noticed something peculiar. When below code is assembled with NASM or Yasm without the marked NOP command the following CALL is missing from the binary. With the NOP included the CALL is…
Schnusch
  • 31
  • 3
1
vote
1 answer

Compile Kernel Modules with inline assembly in Intel Syntax

I wan't to write a kernel module which uses quite a lot of inline assembly. Since I am used to Intel Syntax I would like to avoid AT&T Syntax completely. One way of doing this is shown in the following minimal example: samplemodule.c #include…
user1658887
  • 449
  • 4
  • 15
1
vote
2 answers

Effective Address Calculation with 16 bit register as offset

With the following code, I attempt to "store" the lower two bytes of ebx in the two higher bytes, then use the lower order bx as a temporary variable for accessing an offset into "pool". Finally, I restore the original value (it only used the lower…
Precursor
  • 622
  • 7
  • 18
0
votes
1 answer

How do I modify x86 assembly flags for conditional jumps?

_Str_compare proc ; (byte * str1, byte * str2, DWORD str1_len, DWORD str2_len) :: Returns -1, 0, or 1 for str1 is lexiographically before, equivalent to, or after str2, respectively. Also modifies the carry and zero flags so that cmp can be used…
0
votes
0 answers

I dont understand the output of my code written in GNU Assembler. What happens to the stack after I call printf?

I am trying to code a program which prints the squares between 1 and 5 in assembly. But the output is not as expected. The function calling conventions used are those of UNIX. My code: .intel_syntax noprefix .data msg: …
Daniel
  • 1
  • 2
0
votes
0 answers

Junks ax after expression

This code works as a IN func for i/o ports in inline c: int func(short port) { short data; __asm__( ".intel_syntax \n\t" "in byte %0, %1\n\t" ".att_syntax\n\t" :"=a" (data) :"dN" (port) : …
Programmerabc
  • 329
  • 2
  • 10
0
votes
0 answers

How to assign to global variables in x86 intel syntax assembly

In the x86 intel syntax, global variable values can be accessed with [rip+a], but when I try to assign a new value to a global variable address, like mov [rip+a], 4, a Segmentation Fault occurs. I was trying to write the above code in the same way…
0
votes
1 answer

Accessing "array" data in GNU assembler using Intel syntax

I am tasked to write a GNU assembly program using Intel syntax which counts numbers in array which are <= 6 I came up with the following code: .intel_syntax noprefix .data n: .word 5 a: .word 1, 6, 7, 4, 8 r: .word 0 .text .global…
H4kt
  • 133
  • 7
0
votes
0 answers

gcc inline assembly: how to use intel syntax temporarily with constraint 'm' under 'gcc -masm=att'

I'd like to use intel syntax gcc inline assembly, leaving gcc's default -masm=att dialect untouched. The following code works fine: #include int main(int argc, char *argv[]) { int a = 123; int b = 0; printf("before: a = %d\n",…
Wot
  • 102
  • 11
0
votes
0 answers

Syntax for indirect jump in GAS (Intel syntax): double brackets and/or OFFSET as part of the addressing mode?

For an indirect jump to the address stored in L + 8 in 64-bit mode, nasm accepts, jmp [L + 8] jmp qword [L + 8] GNU as accepts, jmp [L + 8] jmp qword ptr [L + 8] and also, jmp [[L + 8]] jmp [qword ptr [L + 8]] even more, jmp qword ptr [offset L +…
xiver77
  • 2,162
  • 1
  • 2
  • 12
0
votes
0 answers

GAS Intel Syntax won't assemble mov rdi, offset:symbol

I'm new to x86 assembly and I'm following a practical work for the basics. I have 2 equivalent sample codes: One in AT&T syntax and the other on Intel syntax. When compiling theses with GCC, everything works fine for the AT&T syntax, but GCC gives…
JM445
  • 168
  • 1
  • 12
0
votes
1 answer

Is it possible to disassemble C code into intel assembly using an m1 mac?

I've been trying to disassemble C code into intel assembly code on my m1 macbook pro but can't find any way to do it (i've tried to look up how to do it using gdb, lldb, objdump, but no succes so far). So my question is: is it possible and if so,…
user17156350
0
votes
0 answers

Assembly x86-64 | Segmentation fault

I have a task like this: Implement the function with the signature in x86-64 assembly language: extern int * A; extern void func(size_t N); The function in the loop N times: Enters a signed 32-bit integer from the keyboard; Multiplies it by the…
AshGi
  • 13
  • 3
0
votes
2 answers

x86 real mode function calls not executing

I have some x86 realmode assembly code which isn't behaving exactly as expected. I believe the issue relates to an incorrectly calculated jmp/call offset, but I might be mistaken. Here is the assembler language code: [org 0x7c00] mov ah, 0x0e mov…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
0
votes
1 answer

Intel x86 asm print string function

I attempted to write a print string function; 45 ; the address is stored in si 46 print_string: …
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
1 2 3
8 9