我想从c调用汇编函数,但我不断收到错误。调用汇编函数从c
.text
.globl integrate
.type integrate, @function
integrate:
push %ebp
mov %esp, %ebp
mov $0,%edi
start_loop:
cmp %edi,1024
je loop_exit
mov 8(%ebp),%eax
mov 12(%ebp),%ecx
sub %eax,%ecx
add %edi,%ecx
incl %edi
jmp start_loop
loop_exit:
movl %ebp, %esp
popl %ebp
ret
这是我的汇编函数,文件名为integrate.s。
#include <stdio.h>
extern int integrate(int from,int to);
void main()
{
printf("%d",integrate(1,10));
}
继承人我的c代码。
function.c:5:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
/tmp/cciR63og.o: In function `main':
function.c:(.text+0x19): undefined reference to `integrate'
collect2: ld returned 1 exit status
每当我试图编译我的代码用gcc -Wall function.c -o功能,它给“未定义参考整合” error.I也试图从C添加链接到integrate.s文件,像
#include<(file path)/integrate.s>
,但它没有工作作为well.Btw什么汇编代码是干什么并不重要,现在我只是想从C successfully.Can任何调用函数帮助我一下解决这个问题?
小丑的答案应该让你的程序不是至少崩溃。你应该标记他的答案。我正在考虑发布完整的汇编代码,但不知道程序集应该做什么,我真的不能做比他的回答更多的东西。 –