Basic Hello World Program
Provides a simple hello world program with comments that explain what is happening
Refer to the syscall tables here: https://filippo.io/linux-syscall-table/
Also at: /usr/include/x86-64-linux-gnu/unistd_64.h file in linux
Basically there are 3 program sections in assembly:
.data section: Which holds the variables and strings
.text section: Holds the CPU instructions in Assembly
_start variable: This is where CPU execution begins and RIP is assigneed to the start of this offset when program executes.
We use general purpose registers for syscalls. Like rax and assign a value to it and use rdi,rsi,rdx,r10,r8,r9 as the 1st,2nd,3rd...6th argument of the syscall.
Upon a syscall execution, the return value of that syscall is also stored in rax again.
Considering this basic, here is a very simply hello world program which would write to screen and then exit.
To assemble and link and finally execute this:
nasm -f elf64 hello.asm -o hello.asm
ld hello.o -o hello
./hello
Here, in .data section "db" is short for define bytes which initializes a string. We can input enters in assembly by adding 0a at the end.
P.S. Semicolons in assembly are comments
Last updated