I'm absolutely green in this but during classes, teacher gave us file he wrote just for us to run it and it worked fine then, but when I try to do it at home (I use Linux on VirtualBox) and use:
nasm -f elf64 hello.asm -o hello.o
gcc hello.o -o hello
I get an error "relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC”. Can someone please explain what to do to make it work?
global main
extern printf
section .data
napis: db ' Hello world! - po raz %ld',10,0
liczba_iteracji: equ 5
section .bss
licznik: resb 1
section .text
main:
push rbp
mov rbp,rsp
mov byte [licznik],0
petla: ;naiwna!
inc byte [licznik]
mov rdi, qword napis
mov rsi, qword [licznik]
mov rax, 0
call printf
cmp byte [licznik],liczba_iteracji
jnz petla
mov rsp,rbp
pop rbp
mov rax,1 ;SYS_EXIT
mov rbx,0
int 80h