I have problems with linking c and assembly code. Tried to search some solutions, but none of which I found worked for me.
c file "l3.c" looks like this:
#include <stdio.h>
#include <stdlib.h>
const int INP_SIZE = 100;
extern int mult(int c1, int c2);
int main()
{
char number[INP_SIZE];
scanf("%s",number);
printf("You typed: %s \n",number);
int j=2;
int k=5;
j = mult(j,k); #here is the problem
printf("%d",j);
scanf("%s",number);
return 0;
}
and asembly "mult.s" like this:
.type mult, @function
mult:
push %rbp
mov %rsp, %rbp
mov 8(%rbp), %rbx
mov 12(%rbp), %rcx
mov $0, %rax
add %rbx, %rax;
add %rcx, %rax;
mov %rbp, %rsp
pop %rbp
ret
In my makefile i got following lines(most recent solution i googled):
l3:
as -g -o mult.o mult.s
gcc -o l3.o -c l3.c
gcc l3.o mult.o
When I type make in console it is throwing: undefined reference to 'mult'
when I comment //j = mult(j,k);
program works fine. How should I link this?