syscall
Fast system call to the operating system
Asks the operating system to do something.
x86-64 and later
Used in
- Getting started with x86-64x86-64 assembly
- The 16 registers and their halvesx86-64 assembly
- Memory, little endian and sizesx86-64 assembly
- Bytes, words, dwords and qwordsx86-64 assembly
- The x86-64 instruction setx86-64 assembly
- Effective addressesx86-64 assembly
- The flags registerx86-64 assembly
- Sections, directives and labelsx86-64 assembly
- Memory regions and executable filesx86-64 assembly
- cmp and the conditional jumpsx86-64 assembly
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