Assembly may seem daunting, but it’s alright if you know the instructions.
To start off, write the following:
global _start
_start:
mov rax, 60
mov rdi, 0
syscall
To go over what this does,
_start
is something called a Label. It is the function/method of assembly.
global _start
makes it visible to the outside world
Now the following 3 lines are a bit more complex.
rax
and rdi
are what’s called registers. They’re places on the cpu where you put certain instructions, called syscalls
.
60 means that we are calling syscall number 60.
If we look at the linux 64 bit call table, we can see that rax number 60 is:
The exit command.
The first argument is added at the register location
rdi
In our case we want to return the code 0, so we write 0.
Even though the rax register is 64 bits, the rdi register is only 8 bits(one byte). This means that we can only return numbers 0 to 255. (256 would be 0 again).
Now where conventional methods are written as: method(arg0, arg1…) assembly uses the mov
command. You are moving the values into the register locations.
syscall
runs the syscall and executes the registers we just set up.
Now we are ready to assemble and compile for the first time.
next article