首页 > 代码库 > 汇编写下strcpy

汇编写下strcpy

  1 #include <stdio.h>  2   3 int main()  4 {  5         char *source = "hello world\n";  6         char dest[1024] = {0};  7         char *p = dest;  8         char c = \0;  9 #if 0 10 loop:  11         if(*(source + i) == \0){ 12                 *(dest + i) = \0; 13                 goto exit; 14         } 15         *(dest + i) = *(source + i); 16         i++; 17         goto loop; 18 exit: 19 #else 20         __asm__ __volatile__( 21                 "ldr r2, [%2]\n" 22                 "mov r0, #0\n" 23                 "loop:\n" 24                 "ldr r1, [%0, r0]\n" 25                 "cmp r1, r2\n" 26                 "beq exit\n" 27                 "str r1, [%1, r0]\n" 28                 "add r0, r0, #1\n" 29                 "b loop\n" 30                 "exit:\n" 31                 : 32                 :"r" (source), "r" (dest), "r" (&c) 33                 :"r0", "r1", "r2", "memory" 34         ); 35 #endif 36  37         printf("%s\n", p); 38 }

注意:最后一行要写上保护(r1,r2,r3)否则会段错误。

汇编写下strcpy