Assembly Language - Hello World
Hello guys so as i said in the previous post that we are going to code our first program in the assembly. So here it is now in this post I am going to show how to write a program for hello world in the assembly language.
I hope that you guys have installed the NASM on to your machine.....
Here's how the code looks like...
If you are wondering about the syntax highlight then i have done some editing....
I will first execute the program and then explain how it works..... ok
- I know it looks intimidating to look at this code but trust me it is very simple.
Here's the explanation...
- As I said earlier there are section in which your program is divided into sections right.... So you can see there is .text and .data section in the program.
- In the data section your data is stored which is the string you are going to print.....
- Then there is text section where your instructions are stored.
Now lets breakdown the code...
Why _start is the entrypoint :-
- Well you can give any name for the entrypoint but the assmebly by default have _start as the entrypoint name.
breakdown of the write syscall :-
- As you can see write syscall has 3 parameter
- As you can see in the table. In order to generate a write syscall your eax must contain the value 0x4, ebx contains the file descriptor value, ecx must have the message you are going to print and edx must have the length of string you are going to print.
- As you can see the table. In order to perform the exit syscall your eax must have the value 0x0 and ebx must have the status code.
what is int 0x80 :-
- Just think it as that interrupt 0x80 does the system call for you. Means when you load the values for any syscalls into registers and then give int 0x80 then cpu will perform the syscall.
- I will tell you the interrupt 0x80 into detail when time comes.... OK
breakdown of the data section :-
Why there is 0xA at the end of string :-
This is what happens when you run the program without adding 0xA at the end....
And at last this is how the code will look in the C language and excutes...
[ The echo $? gives the status code of the program]
Assembly Language - Hello World
Reviewed by h4kk4
on
April 04, 2020
Rating:
No comments:
Enter your comments here if you need any help: