Assembly Language x86_64 basics | 0x04 | Bin Exp#4

0xCyberzombie xdev
4 min readMay 16, 2021

Hi friends, in the last blog I wrote about the compilation process of C. In this blog, we going to see the basics of x86_64 Assembly programming.

What is Assembly?

Assembly is a low-level programming language through which we can directly communicate with the microprocessor. By using this kind of low-level language, many utilities like Drivers and some Kernel programming are done.

As I already mention that assembly can directly communicate with the microprocessor so that by using this kind of low-level language we can use the CPU in an efficient way.

How this Kind of Language used in I.T.Security?

Imagine we are going to write Malware, and we know that we can write Malware in any programming Language, but Writing it in an Assembly language will lead the Malware to work efficiently when compare to Malwares written in any other programming language.

And when it comes to Binary Exploitation and Reverse Engineering we always let to deal with Assembly language, so we must know some basics about it to survive in this certain domain of I.T.Security.

About Assembly Language

Assembly is a Processor oriented Langauge means, We can only use Certain type of Assembly Language to Certain type of Procesor family. We can execute x86_64 Assembly only if the Processor supports this type of Language. We can’t execute x86_64 assembly in ARM(ADVANCED RISC MACHINE) processor, ARM is a processor which is used in Devices like Mobile phones and Raspberry pi and even also in some Pc.

At first, when programming languages like C or Python don't exist Assembly is a common language that is used by developers. They Develop assembly because the machine can only understand the 01 machine code only, But we humans can’t understand it, so to communicate with the processor, assembly language was Invented.

Now you may have doubt that we wrote Assembly in Alphabets then how does it communicate with the processor, which only understands 01?

So the answer is We have two programs called Assembler and Linker or Linkage Editor which compile the Assembly Language, which we write and convert into 0and1, which is understandable by the processor. These two programs act’s as Translators between us and Machines.

Now it’s Practical Time

As I mentioned before Assembly is a processor-oriented Language, We have to know what type of CPU was us and Which type of Assembly Instruction it can understand. So to know that we have a Command-Line utility called “lscpu”, which shows us info about our Machine.

lscpu

Assembly Breakdown

As a programming language assembly also has its own syntax and structure. Let’s see about it…

All assembly code end with the “.nasm” extension

Generally, it has three sections:

“.text” → In which our actual code was placed

“.data” → Our programs constants and variables

“.bss” → If we need any memory in for our program we declined it here

Now we write Hello world program in Assembly and see about the structure of Assembly Language

Assembly Code

Here is our Hello world code, for now just we are going to understand the structure only so don’t worry about the content of the program. In the next blog, I’ll explain it briefly.

As like C, we include our header called “_start” below the “.text” section because as I already mention in the “.text” section only we write our code. below “_start” I wrote our assembly instruction and this the basics How an Assembly code looks

And in the “.data” section I write my Variables which are I’m going to use in my program. And in this program, I don’t want any memory so I don’t use the “.bss” section.

Compilation

Now we are going to compile our hello world program

Typically, compiling an assembly code is of two steps one is “Creating object file with NASM”, “Using those object files to compile a Binary by using ld”

For compiling we going to use NASM(Netwide Assembler) for creating a binary we going to use ld(Linkage Editor)

cmds :

  1. nasm -felf64 HelloWorld.nasm -o HelloWorld.o
  2. ld HelloWorld.o -o HelloWorld

This because we going to create a Linux executable so that we pass the argument “-felf64”

→ “-o” This is for the Output file name.

Compilation Process

This is the Basics about the x86_64 Assembly

Hope you guys enjoy this blog.

And if you have any doubt’s DM me on Twitter: https://twitter.com/0xCyber_Zombie

Join our Discord Server: https://discord.com/invite/UA8mSkSNhV

And don’t forget to Subscribe to my YouTube Channel.

And Happy Hacking…!!!

--

--