Systemnahe Programmierung in C: strcpy |
|
1#include <stdlib.h>
2
3char *
4strcpy1 (char *d, char *s)
5{
6 size_t i;
7
8 for (i = 0; s[i] != 0; ++i)
9 {
10 d[i] = s[i];
11 }
12 d[i] = 0;
13
14 return d;
15}
|
1 strcpy1:
2 movq %rdi, %rax
3 movzbl (%rsi), %ecx
4 movl $0, %edx
5 testb %cl, %cl
6 je .L2
7 .L3:
8 movb %cl, (%rax,%rdx)
9 addq $1, %rdx
10 movzbl (%rsi,%rdx), %ecx
11 testb %cl, %cl
12 jne .L3
13 .L2:
14 movb $0, (%rax,%rdx)
15 ret
|
1#include <stdlib.h>
2
3char *
4strcpy2 (char *d, char *s)
5{
6 char *d1 = d;
7
8 while ((*d1++ = *s++));
9
10 return d;
11}
|
1 strcpy2:
2 movq %rdi, %rax
3 movl $0, %edx
4 .L2:
5 movzbl (%rsi,%rdx), %ecx
6 movb %cl, (%rax,%rdx)
7 addq $1, %rdx
8 testb %cl, %cl
9 jne .L2
10 rep
11 ret
|
Letzte Änderung: 12.11.2009 | © Prof. Dr. Uwe Schmidt |