Assembly x86 NASM and Registers
The processor has many register that are used to perform different operations. Bellow is a list with the processor register (prefixed with %) and the operation corresponding to the data inside of it.
NR | syscall name | references | %eax | arg0 (%ebx) | arg1 (%ecx) | arg2 (%edx) | arg3 (%esi) | arg4 (%edi) | arg5 (%ebp) |
---|---|---|---|---|---|---|---|---|---|
0 | restart_syscall | man/ cs/ | 0x00 | - | - | - | - | - | - |
1 | exit | man/ cs/ | 0x01 | int error_code | - | - | - | - | - |
2 | fork | man/ cs/ | 0x02 | - | - | - | - | - | - |
3 | read | man/ cs/ | 0x03 | unsigned int fd | char *buf | size_t count | - | - | - |
Here is a simple Assembly
section .data
hello db 'Hello, World!', 0
section .text
global _start
_start:
; write system call
mov eax, 4 ; system call number for write
mov ebx, 1 ; file descriptor (stdout)
mov ecx, hello ; message to write
mov edx, 13 ; message length
int 0x80 ; invoke the kernel
; exit system call
mov eax, 1 ; system call number for exit
xor ebx, ebx ; exit status (0)
int 0x80 ; invoke the kernel
Data Section The data section, also known as the “.data” section, is used to declare and allocate memory for initialized data values. This section is typically used for storing static variables, strings, arrays, and other data that have predefined values.
- The
db
directive stands for “define byte” and is used to allocate memory for individual bytes. It allows you to declare and initialize byte-sized data values.