Archive for February 13th, 2008

At about 22 years ago, Assembly Language is my second language after BASICA. I used Borland Turbo Assembler and Microsoft Debug on that time. I think Debug one of the very powerful tools for hacking. I like hacking. With Assembly, you can order the machine to do anything you want and go directly to every ports in the machine.

I just figure out, is there any Assembly Language in Linux?

Because, usually Assembly Language use DOS Services. Meanwhile, there is no DOS in Linux.

I finally found a good application, named NASM (Net wide Assembler). It’s a Assembly Language compiler in Linux. I’m still new with NASM, so I just take the sample codes from http://leto.net/writing/nasm.php.

NASM doesn’t have a text editor, so you have to type your code using other text editor then save the file with .asm file extension.

There are few main differences to be considered when you use assembly language in Linux:

  • In DOS mostly you use interrupt int 21h, int 10h and int 16h. In Linux, everything is handled by kernel with int 80h.

  • Linux is a 32-bit protected mode operating system, so you have to use extended 32-bit registers, such as EAX, EBX, ECX and so on. In 16-bit register, you still use AX, BX,CX etc …. registers.

  • In 32-bit programming, you don’t have to think about segments at all because it runs in the flat memory model.

  • I think no body write DOS assembly anymore. Hey… it’s 16 bit.

How I can get Nasm?

NASM is listed in Ubuntu Repository, so just download it using apt.

taufanlubis@toshiba:~$ sudo apt-get install nasm

[sudo] password for taufanlubis:

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following packages were automatically installed and are no longer required:

mplayer-skins mplayer libggi2 libgii1 libgii1-target-x youtube-dl

Use ‘apt-get autoremove’ to remove them.

The following NEW packages will be installed:


0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

Need to get 1557kB of archives.

After unpacking 2855kB of additional disk space will be used.

Get:1 http://archive.ubuntu.com gutsy/main nasm 0.98.38-1.2build1 [1557kB]

Fetched 1557kB in 36s (42.8kB/s)

Selecting previously deselected package nasm.

(Reading database … 126048 files and directories currently installed.)

Unpacking nasm (from …/nasm_0.98.38-1.2build1_i386.deb) …

Setting up nasm (0.98.38-1.2build1) …


Write your first Linux Assembly Language Application

When I learn a new computer language, the first thing I want to know is, how to display a ‘Hello World!!!’. I don’t want to know about the structure, variables, codes etc. Just do a simple thing, type, compile and see it run. That’s it. Then you can go further. It’s the same when you teach a baby to speak. We don’t teach any grammar. We give samples.

So, here it is.

Step 1. Type the code

You can use, vim, vi, gedit etc. The extension must be .asm.

taufanlubis@toshiba:~$ sudo vim hello.asm

[sudo] password for taufanlubis:

section .data

hello: db ‘Hello world!’,10

helloLen: equ $-hello

section .text

global _start


mov eax,4

mov ebx,1

mov ecx,hello

mov edx,helloLen

int 80h

mov eax,1

mov ebx,0

int 80h

Press ‘Esc‘ button and type ‘:wq‘ to save the file.

Actually, I’m new myself in Assembly Programming in Linux. I took the codes above from the NASM website. I just wanna show you that we can do Assembly Programming in Linux. If you want to know deeper you can go

to this link: ……………………..

Step 2. Compile .asm (source code) to .o (object)

taufanlubis@toshiba:~$ nasm -f elf hello.asm

Step 3. Link the object file to produce an executable file.

taufanlubis@toshiba:~$ ld -s -o hello hello.o

Now, you have 3 files, hello.asm (your source code), hello.o (your object file) and hello (your program).

taufanlubis@toshiba:~$ ls -l hello*

-rwxr-xr-x 1 taufanlubis taufanlubis 440 2008-01-17 20:38 hello

-rw-r–r– 1 root root 203 2008-01-17 20:33 hello.asm

-rw-r–r– 1 taufanlubis taufanlubis 736 2008-01-17 20:37 hello.o

Step 3. Ready to run

You can run your program by typing:

taufanlubis@toshiba:~$ ./hello

Hello world!


Congratulations! You have just written your first assembly program in Linux.

If you want to know more details about nasm and ld, you can see the manual.

taufanlubis@toshiba:~$ man ld

taufanlubis@toshiba:~$ man nasm



Read Full Post »