Assembly Language Crash Course 2
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!
Nice, but I found two inconsistencies:
performing a system interruption.
I believe it should be 'requesting a kernel interrupt'.
As you can see via mov ebx, 1 that 1 is going into ebx.
1 is the code for stdout. STDOUT is the output stream meaning that the computer will write something to the terminal window
I think it should be:
ebxis the file descriptor for the write. (A descriptor of 0, 1, or 2 is a special one, indicating stdin, stdout, or stderr, respectively.
no yes everything makes no total sense about the code at the beggining I don't even have to read down all I needed was that first image before realizing that I aredy didn't knew this haha definitlty not
@Wuru I am not questioning the runtime processes, but high-level does not mean 'far from assembly'.
It can mean
far from machine code, but it can also mean other things.
A high level library could implement the
Instead of calling every method and nitpicking over cross platform details, you could call
@Wuru @CodeLongAndPros @DynamicSquid ya know there was a really nice explanation I got from a book about a month ago on the evolution from a low to high level language, and they were directly relating it to abstraction. Let me explain.
As we go up the ladder of abstraction, we are slowly stripping away constantly repeated concepts/paradigms and replacing them with a more simplistic version or with nothing at all and handle the construction of those paradigms on instead of the programmer. So a high level language is really just a language that has a ton of abstraction. In the same exact sense a high level library just has a bunch of abstraction. The amount of abstraction is key to figuring out how high level a language is. Maybe I’ll send you guys the book, it’s so good! :)