[請益] 將C code某段函數轉換為彙編,使用gcc & gas
原始檔有兩個main1.c square.s
//main1.c
#include<stdio.h>
extern int square(int i);
int main(void)
{
int i;
for (i=0;i<10;i++)
{
printf("Square of %d is %d\n",i,square(i));
}
}
@square.s
.text
.global square
square:
MUL r1,r0,r0 @ r1 = r0 x r0
MOV r0,r1 @ r0 = r1
MOV pc,lr @ return r0
.end
編譯步驟與錯誤訊息如下
[leo@localhost main]$ ls
main1.c square.s
[leo@localhost main]$ gcc -c main1.c
[leo@localhost main]$ as -o square.o square.s
[leo@localhost main]$ ls
main1.c main1.o square.o square.s
[leo@localhost main]$ ld -o main1 main1.o square.o
ld: warning: cannot find entry symbol _start; defaulting to 00008074
main1.o: In function `main':
main1.c:(.text+0x34): undefined reference to `printf'
請問是哪裡的寫法不對?先謝謝各位
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.155.213
→
03/04 13:59, , 1F
03/04 13:59, 1F
→
03/04 13:59, , 2F
03/04 13:59, 2F
→
03/04 13:59, , 3F
03/04 13:59, 3F
→
03/05 09:14, , 4F
03/05 09:14, 4F
→
03/06 20:58, , 5F
03/06 20:58, 5F
推
03/07 01:42, , 6F
03/07 01:42, 6F
ASM 近期熱門文章
PTT數位生活區 即時熱門文章