我想從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任何調用函數幫助我一下解決這個問題?
小丑的答案應該讓你的程序不是至少崩潰。你應該標記他的答案。我正在考慮發佈完整的彙編代碼,但不知道程序集應該做什麼,我真的不能做比他的回答更多的東西。 –