Hello. I am @Wuru and this is Assembly Language Crash Course 2.
So. Let’s just start right now.
Section 4: Hello, World!
Consider the code below.
section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, msg mov edx, len int 0x80 section .data msg db “Hello, World!”, 0x0a len equ $ - msg
The code above prints ‘Hello, World!’ to the terminal.
Well, let’s break down the parts you may not understand.
You can see via
int 0x80 we are requesting a kernel interrupt. We discussed this in section 2.
eax as a code to determine what to do. We discussed this in section 2.
eax contains 4. You can see this via
mov eax, 4
4 is the code for a
sys_write. This means the computer is going to write data somewhere.
sys_write interrupt is also dependent on
ebx for the destination to write.
A better explanation would be that ebx is the file descriptor. (0 is stdin, 1 is stdout, and 2 is stderr, respectively.)
These codes are the same in C.
Do I expect you to understand these codes? No. But reference them in the future.
As you can see via
mov ebx, 1 that 1 is going into
1 is the code for
stdout. STDOUT is the output stream meaning that the computer will write something to the terminal window.
sys_write also depends on
ecx needs to contain the data.
edx needs to contain the amount of data that will be written.
And this is where the data section comes into play.
As you can see in the data section I defined
msg. For reference, see section 3.
This is moved into
mov ecx, msg. This is possible because (as seen in section 3) pointers just point to an address in memory.
So this is just like moving that address into
ecx. Just a bit abstracted.
Also in the
data section there is
len is a pointer to another address in memory.
equ keyword (after len) is a keyword to say that it is going to equal something.
$ is the end of msg.
msg is the start.
So to find the length of msg we can just subtract.
And that’s it!
Section 5: labels and jmp
Consider the code below
global _start other: mov eax, 1 mov ebx, 0 int 0x80 _start: jmp other
The code will just end itself.
Well let’s break it down.
_start label is a label we have been using since the start. pun intended
other is just another label we defined.
As you can see in
other we perform a system interruption to end the program. As seen in section 2.
jmp jumps to another label.
As you can see we jump to
That’s pretty much it.
Farewell until part 3!
Please upvote and give feedback :D!