# `syscall`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/syscall

**Fast system call to the operating system**

Category: System

Asks the operating system to do something.

x86-64 and later

[Intel's reference: SYSCALL](https://intel.github.io/SDM/instruction/SYSCALL.html)

Used in: [Getting started with x86-64](https://asm-editor.specy.app/learn/courses/x86/introduction/getting-started.md) (x86-64 assembly), [The 16 registers and their halves](https://asm-editor.specy.app/learn/courses/x86/introduction/the-16-registers-and-their-halves.md) (x86-64 assembly), [Memory, little endian and sizes](https://asm-editor.specy.app/learn/courses/x86/introduction/memory-little-endian-and-sizes.md) (x86-64 assembly), [Bytes, words, dwords and qwords](https://asm-editor.specy.app/learn/courses/x86/introduction/bytes-words-dwords-and-qwords.md) (x86-64 assembly), [The x86-64 instruction set](https://asm-editor.specy.app/learn/courses/x86/introduction/the-x86-instruction-set.md) (x86-64 assembly), [Effective addresses](https://asm-editor.specy.app/learn/courses/x86/introduction/effective-addresses.md) (x86-64 assembly), [The flags register](https://asm-editor.specy.app/learn/courses/x86/introduction/the-flags-register.md) (x86-64 assembly), [Sections, directives and labels](https://asm-editor.specy.app/learn/courses/x86/introduction/sections-directives-and-labels.md) (x86-64 assembly), [Memory regions and executable files](https://asm-editor.specy.app/learn/courses/x86/introduction/memory-regions-and-executable-files.md) (x86-64 assembly), [cmp and the conditional jumps](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/cmp-and-the-conditional-jumps.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

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`

## Description

`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](https://asm-editor.specy.app/documentation/x86/syscall.md) lists the calls this emulator implements.

## Example

```x86
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
```
