Assembly Language - Hello World

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

Assembly Language, Reverse Engineering, Binary Exploitation


I will first execute the program and then explain how it works..... ok


Assembly Language, Reverse Engineering, Binary Exploitation

  • 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
Assembly Language, Reverse Engineering, Binary Exploitation
  • 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.

Assembly Language, Reverse Engineering, Binary Exploitation

breakdown of the exit syscall :-

  • As you can see exit syscall has only 1 parameter which is the status code.
Assembly Language, Reverse Engineering, Binary Exploitation
  • 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 :-

Assembly Language, Reverse Engineering, Binary Exploitation
  • 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 :-

  • 0xA is the ascii value for the new line character which is '\n'
Assembly Language, Reverse Engineering, Binary Exploitation

This is what happens when you run the program without adding 0xA at the end....

Assembly Language, Reverse Engineering, Binary Exploitation

And at last this is how the code will look in the C language and excutes...


Assembly Language, Reverse Engineering, Binary Exploitation


[ The echo $? gives the status code of the program]

 

Assembly Language - Hello World Assembly Language - Hello World Reviewed by h4kk4 on April 04, 2020 Rating: 5

No comments:

Enter your comments here if you need any help:

Powered by Blogger.