Create first program “Hello World” on Assembler in Linux

To create program on Assembler in Linux operating system we need compiler for x86 architecture named nasm

sudo apt install nasm

To compile program in file hello.asm use commands:

nasm -felf64 hello.asm
ld hello.o

To start compiled program use command:

./a.out

Nov let’s create our program in file hello.asm using text editor vim

vim hello.asm

Here is the full code of program:

message:
	db	"Hello World!", 10

_start:
	mov	rax, 1
	mov	rdi, 1
	mov	rsi, message
	mov	rdx, 14
	syscall

	mov	rax, 60
	syscall

	section .data

global _start

section .text

In first two lines we create some label which contains some directive db width string “Hello World!“, and last symbol 10line feed. Directive is like variables in high level programming languages.

Directive db can use 1 byte for writing information and can write constants from -128 to 255 and can write symbols and strings.

Next create label _start: and width command mov we write some data in processor address (register):

mov rax, 1 – move 1 in register rax – in this string we call data recording.
mov rdi, 1 – This register response for input and output stream. When we send 1 in register rdi we say processor to work width standard output stream.
mov rsi, message – we write address of our string in register rsi.
mov rdx, 14 – we write count bytes of our string in register rdx.

Next we make system call width command syscall.

mov rax, 60 – we put number 60 in register rax – this is system call for exit.

And again make system call width command syscall.

At the end of program we run command section .data

Width command global _start we run our program from label _start.

Width command section .text we declare text part of our code