Assembly Language Crash Course 2
Wuru (585)

Third take.

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.

How?

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.

The interruption 0x80 uses 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.

The 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 ebx.

1 is the code for stdout. STDOUT is the output stream meaning that the computer will write something to the terminal window.

You might recognize this from C or C++.

sys_write also depends on ecx and edx.

But why?

ecx needs to contain the data.

And 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 ecx via 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.

len is a pointer to another address in memory.

The equ keyword (after len) is a keyword to say that it is going to equal something.

$ is the end of msg.

And 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.

How?

Well let’s break it down.

The _start label is a label we have been using since the start. pun intended

And 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.

And jmp jumps to another label.

As you can see we jump to other.

That’s pretty much it.

Farewell until part 3!

Please upvote and give feedback :D!

You are viewing a single comment. View All