The problem is each of your compilation lines are trying to create your executable without the full program. You somewhat complicate things if your source files are the same name with a different extension.
One simple option is instead, this command: gcc -o program factarial.c factarial.s
.
Alternatively you might consider compiling but not linking your individual source files, and then linking their objects together to build your executable. Assuming your source files were named a.c
and b.s
, you would:
gcc -c a.c
gcc -c b.s
gcc -o program a.o b.o
Finally (and not related to your problem, of course), I believe the word you are looking for is factorial
:)
There still exists a problem in your assembly. First, I've recreated your results, as seen here:
$ gcc -c factarial.c
$ gcc -c factarial_asm.s
$ gcc -o program factarial.o factarial_asm.o
factarial.o: In function `main':
factarial.c:(.text+0xf): undefined reference to `factarial_asm'
collect2: error: ld returned 1 exit status
Next, I used the nm
command to inspect the object files:
$ nm factarial.o
U factarial_asm
0000000000000000 T main
$ nm factarial_asm.o
U _main
0000000000000000 t factarial_asm
000000000000001a t koniec
There are some interesting things in the nm
output for the assembly object. First, U _main
tells us that main()
is undefined in that object, meaning it's expected to be found when we link the program. This file doesn't call main()
so we really shouldn't even care about that. This is caused by .global _main
, which can safely be removed.
Next, the symbol for factarial_asm
is a lower case t
, not the T
found in main()
from the primary C source... being shown as t
means the symbol is local to that source file only, it's not exported to others. (In C, this is the difference between void function() {}
and static void function() {}
). We need to fix that, by adding the proper .global
directive.
Summarized: in your assembly, change .global _main
to .global factarial_asm
.