First change _printf
to printf
and the _start
symbol to main
, then use gcc
to link the object file, which will automatically link it to libc
, you need to do that because AFAIK you can't link to libc without a main
. Also you should use elf32 not elf64 when assembling because the code has 32 bits instructions :
bits 32
extern printf
global main
section .data
message db "Hello world!!", 10, 0
section .text
main:
pushad
push dword message
call printf
add esp, 4
popad
ret
And build with:
nasm -f elf32 vaja4.asm
gcc -m32 vaja4.o -o vaja4
$./test
$Hello world!!
Edit:
Since you're now compiling 32-bit code on a 64-bit system, you will need to install the 32-bit version of the libraries
apt-get install ia32-libs