Basic Syntax


An assembly program typically consits of three parts -
1. data section - This section is used to declare initialized data or constants, whose values would remain fixed during program run. It is declared as section.data

2. bss section - BSS stands for block started by symbol. This section is used to declare variables whose values can change during program run. It is declared as section.bss

3. text section - This section stores the actual code. This section must begin with the declaration global _start, which tells the kernel where the program execution begins.
section.text
  global _start
_start:


To give comment in assembly program semicolon ; is used.
Hence general syntax of Assembly intruction is [label] mnemonic [operands] [;comment]

System Calls

In order to make system calls, perform the following operations -

  • Insert the system call number in the EAX register.
  • Store the arguments to the system call in order in following registers - EBX, ECX, EDX, ESI, EDI and EBP.
  • Call the relevant interrupt (80h).
Some common System calls are -

EAX System Call EBX ECX EDX ESI EDI EBP
1 sys_exit int - - - - -
2 sys_fork struct pt_regs - - - - -
3 sys_read unsigned int char* size_t - - -
4 sys_write unsigned int const char* size_t - - -
5 sys_open const char* int int - - -
6 sys_close unsigned int - - - - -


All the syscalls are listed in /usr/include/asm/unistd.h.
Now let's begin practising some examples.