i am new to assembly and i wanna call a c function from an assembly file and i was using the following ...
test.c
#include <stdio.h>
extern void asmfunction(void);
extern int test_variable;
int main(){
printf("before asm: %d\n", test_variable);
asmfunction();
printf("after asm: %d\n",test_variable);
return 0;
}
test.S
.globl _asmfunction
;.global test_variable
_asmfunction:
movl $12345, test_variable
ret
and i compiled it using the following method
$ gcc test.c test.S
$ ./a.out
but i keep getting the error
/tmp/ccmzpUux.o: In function `main':
astest.c
.text+0xa): undefined reference to `test_variable'
astest.c
.text+0x1f): undefined reference to `asmfunction'
astest.c
.text+0x24): undefined reference to `test_variable'
/tmp/ccsUsANm.o: In function `_asmfunction':
(.text+0x2): undefined reference to `test_variable'
collect2: error: ld returned 1 exit status
please what am i doing wrong??