I am playing around trying to call assembly functions I have written in Nasm within C. For some reason things are not behaving as I am expecting.
NASM:
SECTION .DATA
hello: db 'Hello', 0x0a ; Hello/n
SECTION .TEXT
global sayHello
sayHello:
mov rax, 4 ; write()
mov rbx, 1 ; stdout
mov rcx, hello ; add hello to register
mov rdx, 6 ; length of string
int 0x80 ; interrupt
ret ; return
C:
#include <stdio.h>
extern int sayHello();
int main(int argc, char **argv) {
printf("ASM Function is saying Hello:\n");
sayHello();
return 0;
}
compiled with: nasm -f elf64 and gcc
result:
ASM Function is saying Hello:
expected result:
ASM Function is saying Hello:
Hello
What am I missing?