0% found this document useful (0 votes)
68 views2 pages

Installation of Nsam in Ubuntu and Linux

This document provides instructions for installing NASM and using it to compile and run a simple "Hello World" assembly program in Ubuntu Linux. It explains how to install NASM using the apt-get command, defines the data and text sections containing the string and length variables, and shows the system calls used to write and exit. It concludes by explaining how to assemble the program with nasm, link it with ld, and run the executable to output "Hello World!".

Uploaded by

George M Jacob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

Installation of Nsam in Ubuntu and Linux

This document provides instructions for installing NASM and using it to compile and run a simple "Hello World" assembly program in Ubuntu Linux. It explains how to install NASM using the apt-get command, defines the data and text sections containing the string and length variables, and shows the system calls used to write and exit. It concludes by explaining how to assemble the program with nasm, link it with ld, and run the executable to output "Hello World!".

Uploaded by

George M Jacob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

helloLen: equ $-hello

; 'Hello world!' plus a linefeed character


; Length of the 'Hello world!' string

; (I'll explain soon)

section .text
global _start

_start:
mov eax,4

; The system call for write (sys_write)

mov ebx,1

; File descriptor 1 - standard output

mov ecx,hello

; Put the offset of hello in ecx

mov edx,helloLen

; helloLen is a constant, so we don't need to say

; mov edx,[helloLen] to get it's actual value


int 80h

; Call the kernel

mov eax,1

; The system call for exit (sys_exit)

mov ebx,0

; Exit with return code of 0 (no error)

int 80h
4.5 Compiling and Linking

If you don't have a terminal or console open, open one now.

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!

You might also like