I've been trying to learn 64-bit assembly on both Mac-OS and Windows using NASM.
My code is
extern _printf
section .data
msg db "Hello World!", 10, 0
section .text
global _main
_main:
mov rax, 0
mov rdi, msg
call _printf
mov rax, 0x2000001
mov rdi, 0
syscall
and I compile it with
nasm -f macho64 -o main.o main.asm
gcc -o main main.o
While trying to call _printf
, I got the error
Segmentation fault: 11
When I remove the call to _printf
, my code runs fine.
Why does the call to _printf
cause a segmentation fault?
I have found the ABI Calling Convention here, but had no luck successfully calling a C-function.
I would expect Hello World!
to be printedd, however I get 'Segmentation Fault: 11' instead.