Search notes:

x64 assembler dialects

Here are a few example that demonstrate different assembler dialects for x64.
All sources use the syscall instruction to call the (Linux) syscall exit.

GNU assembler

AT&T syntax

.globl   _start
.text

_start:
  
  #
  # Load RAX register with syscall number
  #
    mov  $60, %rax   #  60 is syscall number for exit()
  # mov $231, %rax   # 231 is syscall number for exit_group()
  
  #
  # Load RDI (first argument), for exit(),
  # this is the status code.
  #
    mov  $42, %rdi   # exit status code

    syscall
Compile this source with
gcc -nostdlib -o prog prog.s

Intel syntax

In order to write an assembler source for the GNU assembler in intel syntax, the .intel_syntax noprefix directive is required:
.intel_syntax noprefix

.globl   _start
.text

_start:
  
    mov  rax, 60
    mov  rdi, 42
    syscall
This source is compiled with the exactly same command as the AT&T source.

nasm

section .text
global  _start

_start:

   mov  rax, 60
   mov  rdi, 42
   syscall
Compile and link with the following two commands:
nasm -felf64 prog.nasm -o prog.o
ld prog.o -o prog
The same source can also be compiled with yasm -felf64 ….

See also

gcc -masm
Assembler code to invoke a syscall on Linux.

Index