Installation of Nsam in Ubuntu and Linux
Installation of Nsam in Ubuntu and Linux
Ubuntu Linux
NASM was installed using the command
sudo apt-get install nasm
section .data
hello:
db 'Hello world!',10
section .text
global _start
_start:
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,helloLen
mov eax,1
mov ebx,0
int 80h
4.5 Compiling and Linking
Make sure you are in the same directory as where you saved hello.asm.
To assemble the program, type
nasm -f elf hello.asm
If there are any errors, NASM will tell you on what line you did what wrong.
Now type ld -s -o hello hello.o
This will link the object file NASM produced into an executable file.
Run your program by typing ./hello
(To run programs/scripts in the current directory, you must always type ./ before the
name, unless the current directory is in the path.)
You should see Hello world! printed to the screen. Congratulations! You have just
written your first assembly program in Linux!