Let's begin with printing 'Hello World!' on screen.
Let us create a hello.o assembly file.
In order to begin the assembly code we need to define the entry point for program using global keyword which makes the identifier accessible to linker.

                                    

global _start ; must be declared for linker

_start: ; start label

Now let's make system exiit call by moving 1 in eax register and using 0 as exit status in the text section.

                                    

global _start ; must be declared for linker

section .text

_start: ; start label

mov eax , 1 ; sys_exit system call

mov ebx , 0 ; setting exit status

int 0x80 ; Calling interrupt handler to exit program

Now let's execute the program to see the output.
We first convert the assembly code to 32-bit executable and linking format object file and then linker generates an executable file from object file.

                                    

>> nasm -f elf32 hello.asm -o hello.o

>> ld -m elf_i386 hello.o -o hello

>> ./hello

>> echo $?


                                    

>> 0

Now let us define some constants in data section.

                                    

global _start ; must be declared for global

section .data

msg db "Hello World!", 0x0a ; msg="Hello World!\n"

len equ $ - msg ; len equals size of msg

section .text

_start: ; start label

mov eax , 1 ; sys_exit system call

mov ebx , 0 ; setting exit status

int 0x80 ; Calling interrupt handler to exit program

Here db stands for describe byte to declare a 1 byte directive and db for defining a constant value.
Let us expand our text section and move 4 to eax for system write and run the program to get our required output.

                                    

global _start ; must be declared for global

section .data

msg db "Hello World!", 0x0a ; msg="Hello World!\n"

len equ $ - msg ; len equals size of msg

section .text

_start: ; start label

mov eax, 4 ; sys_write system call

mov ebx, 1 ; stdout file descriptor

mov ecx, msg ; ecx=msg

mov edx, len ; edx=len

int 0x80 ; Perform the system call

mov eax , 1 ; sys_exit system call

mov ebx , 0 ; setting exit status

int 0x80 ; Calling interrupt handler to exit program


                                    

>> nasm -f elf32 hello.asm -o hello.o

>> ld -m elf_i386 hello.o -o hello

>> ./hello

>> echo $?


                                   

>> Hello World!

>> 0

This completes our first assembly program. In next example we will learn to perform Input and Output Operations.