syscall

Fast system call to the operating system

Asks the operating system to do something.

x86-64 and later

Intel's reference: SYSCALL

CFPFAFZFSFDFOF –––––––
  • Changes no flag
  • The processor masks the flags on its way into the kernel and Linux restores them on the way out, so after the call they are as the program left them; `r11` holds the copy saved on entry.

Forms

  • syscall

rax holds the call number, the arguments go in rdi, rsi, rdx, r10, r8 and r9 in that order, and the result comes back in rax, with a small negative number meaning an error. rcx and r11 are destroyed by the call itself, so anything kept in them has to be saved first.

Programs here run as Linux programs, so this is the only way a program reaches the console or the file system. The syscall page lists the calls this emulator implements.

global _start

section .data
message: db "hello, world", 10, 0

section .text
_start:
        mov rax, 1          ; syscall 1: write
        mov rdi, 1          ; to standard output
        mov rsi, message    ; from this address
        mov rdx, 14         ; this many bytes
        syscall

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall