Assembly: Hello World example in NASM

Save the following code as helloWorld.asm:

; we will use function printf
extern printf
; mark label "main" as entry point of our executable
global main

; this section contains all data
section .data
	message db "Hello world!!", 10, 0

; this section contains all code
section .text
main:
	; save registers on stack
	pushad 

	; print message
	push dword message
	call printf 
	add esp, 4 

	; restore registers
	popad 

	; exit with code 0
	mov eax,1
	mov ebx,0
	int 80h

Create a Makefile with the following content:

# "compile" helloWorld.asm to ./a.out
all:
	nasm -felf32 helloWorld.asm && ld -melf_i386 -I/lib/ld-linux.so.2 -lc --entry main helloWorld.o

Now assemble and run:

make && ./a.out

If ld complains cannot find -lc, you might need to install some libraries, e.g., on Debian based systems:

apt install gcc-multilib