首先是arm汇编代码:p1.s文件:
.global strcopy
strcopy:
ldrb r2,[r1],#1
strb r2,[r0],#1
cmp r2,#0
bne strcopy
mov pc,lr
下面是c文件:p2.c
#include <stdio.h>
extern void strcopy(char *d,const char *s);
int main(void)
{
const char *srcstr="first string_source";
char dststr[]="sencond string_destination";
printf("before copying:/n");
printf("%s/n %s/n",srcstr,dststr);
strcopy(dststr,srcstr);
printf("after copying:/n");
printf("%s/n%s/n",srcstr,dststr);
return 0;
}
利用交叉编译进行编译:
arm-linux-gcc p2.c p1.s
生成a.out文件
然后到开发板上运行./a.out可以看到运行结果:
before copying:
first string_source
sencond string_destination
after copying:
first string_source
first string_source
运行正确把第一个字符串拷过来了,不过还有一个问题,就是目的字符串明明长度比源字符串长,怎么把目的字符串全覆盖了