When trying to use external C function in assembly, I have segfaults without knowing why. Does it have something to do with stack alignement ? I can't find the right documentation (a link will be highy appreciated).
My code :
extern printf
section .data
int_string: db "hey, your result is %d", 10, 0
global main
main:
push rbp
mov rbp, rsp
mov rax, 78
push rbp
mov rdi, int_string
mov rsi, rax ; 78 in rsi
call printf
pop rbp
mov rax, 1
leave
ret
I compile using :
nasm -f elf64 test.asm
gcc -no-pie -fno-pie test.o -o test
./test
Note that this sometimes works.
My working environment : Linux (ubuntu) Intel i7