我的C代码:
#include <stdio.h>
#include <stdlib.h>
extern char * ins( char * string1, char * string2, int place ) ;
int main( int argc, char * argv[] )
{
char s1[] = "String to insert into" ;
char s2[] = " this is the string to insert" ;
int place = 9 ;
char * result ;
result = ins( s1, s2, place ) ;
printf( "s1:\t%s\n", s1 ) ;
printf( "s2:\t%s\n", s2 ) ;
printf( "resulting string: %s\n", result ) ;
exit( 0 ) ;
}
此C代码将使用以下汇编代码作为函数&#34; ins&#34;如下定义,ARM编译器同时接收C和汇编文件并将它们编译在一起......它应该用汇编语言处理ins函数,并从C中打印出结果。
我的汇编代码:
.global ins
ins:
stmfd sp!, {v1-v6, lr}
mov v1, a1
bl strlen
add a1, a1, #1
mov v2, a1
bl malloc
mov v3, #0
loop:
ldrb v4, [v1], #1
subs v2, v2, #1
add v4, v4, a2
strb v4, [a1], #1
bne loop
ldmfd sp!, {v1-v6, pc} @std
.end