Menu
Coddy logo textTech

What is Syscall?

Part of the Fundamentals section of Coddy's Assembly journey — lesson 31 of 45.

You have written assembly instructions like mov and lea. These instructions run directly on the CPU. But what if you need to do something the CPU cannot do by itself — like print to the screen, read from the keyboard, or exit a program?

For these tasks, you need the operating system (Linux, in this course).

What is a syscall?

A syscall (system call) is a request from your program to the operating system. It is how you ask the OS to do something for you.

Why you need syscalls:

TaskCan the CPU do it alone?Need syscall?
Add two numbersYesNo
Move data between registersYesNo
Print text to screenNoYes
Read keyboard inputNoYes
Exit a programNoYes
Open a fileNoYes

How a syscall works:

  1. You put a syscall number in rax (tells the OS what you want)
  2. You put arguments in other registers (rdi, rsi, rdx, etc.)
  3. You execute the syscall instruction
  1. The CPU jumps into the OS kernel
  2. The OS performs the request
  3. The OS returns control to your program

Analogy:

Think of a syscall like calling a government office:

StepAnalogyIn assembly
1Decide what service you needChoose syscall number (put in rax)
2Fill out the formsPut arguments in registers
3Submit the requestExecute syscall
4Government processes itOS kernel does the work
5Get your result backProgram continues

Syscalls you will learn in this course:

SyscallNumberWhat it doesChapter
exit60Ends the programChapter 4
write1Prints text to screenChapter 5

The most important syscall for now: <strong>exit</strong>

Without exit, your program would keep running forever or crash. Every program you write must end with an exit syscall.

mov rax, 60    ; syscall number for exit
mov rdi, 0     ; exit code (0 = success)
syscall        ; ask the OS to exit

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals