When you do #include "assem.s"
it takes the contents of the file assem.s
and places it into the C at that point. The result would have the compiler trying to compile this:
#include <stdio.h>
.globl testing
testing:
ret
void extern testing(int * a);
int main(){
int b = 8;
int * a = &b;
testing(a);
printf("%d",*a);
}
Of course that's not what you want. The compiler attempted to compile the line .globl testing
and it failed because it isn't proper C syntax and results in the error you got. All you have to do is remove #include "assem.s"
.
assem.s
will be assembled and then linked into the executable with the command gcc main.c assem.s -o test.exe
. This one GCC command is the equivalent of the following except that intermediate object files won't be generated:
gcc -c main.c -o main.o
gcc -c assem.s -o assem.o
gcc main.o assem.o -o test.exe
You assemble/compile .s
and .S
files in the same fashion as .c
files. .s
and .S
files should not be used with the C #include
directive. There is a misconception among some new GCC users that they should be included and not assembled/linked separately.