Assembly System Calls
System calls are APIs for the interface between user space and kernel space. We have already used the system cal s sys_write and sys_exit for writing into the screen and exiting from the program respectively.
Linux System Calls
You can make use of Linux system cal s in your assembly programs. You need to take the following steps for using Linux system calls in your program:
Put the system call number in the EAX register.
Store the arguments to the system call in the registers EBX, ECX, etc.
Call the relevant interrupt (80h)
The result is usual y returned in the EAX register
There are six registers that stores the arguments of the system cal used. These are the EBX, EC X, EDX, ESI, EDI, and EBP. These registers take the consecutive arguments, starting with the EBX register. If there are more than six arguments then the memory location of the first argument is stored in the EBX register.
The following code snippet shows the use of the system call sys_exit:
The following code snippet shows the use of the system call sys_write:
All the syscalls are listed in /usr/include/asm/unistd.h, together with their numbers (the value to put in EAX before you call int 80h).
The following table shows some of the system cal s used in this tutorial:
Example
The following example reads a number from the keyboard and displays it on the screen:
When the above code is compiled and executed, it produces fol owing result: