请嵌入式高手帮忙翻译一段程序(翻译成C语言)
来源:百度知道 编辑:UC知道 时间:2024/05/30 10:57:22
AREA SCopy, CODE, READONLY
EXPORT strcopy
strcopy
; r0 points to destination string
; r1 points to source string
LDRB r2, [r1],#1 ; load byte and update address
STRB r2, [r0],#1 ; store byte and update address;
CMP r2, #0 ; check for zero terminator
BNE strcopy ; keep going if not
MOV pc,lr ; Return
END
EXPORT strcopy
strcopy
; r0 points to destination string
; r1 points to source string
LDRB r2, [r1],#1 ; load byte and update address
STRB r2, [r0],#1 ; store byte and update address;
CMP r2, #0 ; check for zero terminator
BNE strcopy ; keep going if not
MOV pc,lr ; Return
END
其实就是一个字符串拷贝函数,C 语言表示如下:
strcopy( char *sp1, char *sp2 )
{
while( *sp2 != '\0' )
{
*sp1 = *sp2;
sp1++;
sp2++;
}
}
strcpy(char * dest,const char * src)
{
assert(dest!=NULL && src!=NULL);
while((*dest++=*src++)!='\0');
}
一楼说的不错。