|
|
1#include <stdlib.h>
2
3size_t
4strlen1 (char *str)
5{
6 size_t i = 0;
7
8 while (str[i] != 0)
9 ++i;
10
11 return i;
12}
|
1 strlen1:
2 xorl %eax, %eax
3 cmpb $0, (%rdi)
4 je .L3
5 .L6:
6 addq $1, %rax
7 cmpb $0, (%rdi,%rax)
8 jne .L6
9 .L3:
10 rep
11 ret
|
|
1#include <stdlib.h>
2
3size_t
4strlen2 (char *str)
5{
6 char *ptr = str;
7
8 while (*ptr++);
9
10 return (ptr - str) - 1;
11}
|
1 strlen2:
2 movq %rdi, %rdx
3 .L2:
4 movzbl (%rdx), %eax
5 addq $1, %rdx
6 testb %al, %al
7 jne .L2
8 notq %rdi
9 leaq (%rdx,%rdi), %rax
10 ret
|
| Letzte Änderung: 12.11.2009 | © Prof. Dr. Uwe Schmidt |