I would like to call ASM (MASM) from C (GCC). Easy! Now i would like my asm function to be able to use data and to call functions like printf().
I got two problems: the data section and the call to printf()
I have read examples on internet which are exactly like mine but don't seem to fail. Any help is welcomed.
test.c:
#include <stdio.h>
int64_t asmfunc();
int main() {
asmfunc());
return 0;
}
test.asm
global asmfunc
section .data
msg: db "a very inspired message!",10,0
section .text
extern printf
asmfunc:
mov edi,msg
xor eax,eax
call printf
ret
compilation:
nasm -felf64 maxofthree.asm
gcc callmaxofthree.c maxofthree.o
result:
/usr/bin/ld: maxofthree.o: relocation R_X86_64_32 against `.data' can not
be used when making a shared object; recompile with -fPIC
if i just leave the printf call, removing the .data section and the "mov edi,msg", i get
/usr/bin/ld: maxofthree.o: relocation R_X86_64_PC32 against symbol
`printf@@GLIBC_2.2.5' can not be used when making a shared object;
recompile with -fPIC
Thanks fellow coders