Systemnahe Programmierung in C: strlen |
|
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 movl $0, %eax
3 cmpb $0, (%rdi)
4 je .L2
5 .L3:
6 addq $1, %rax
7 cmpb $0, (%rdi,%rax)
8 jne .L3
9 .L2:
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, %rax
3 .L2:
4 movzbl (%rax), %edx
5 addq $1, %rax
6 testb %dl, %dl
7 jne .L2
8 subq %rdi, %rax
9 subq $1, %rax
10 ret
|
Letzte Änderung: 12.11.2009 | © Prof. Dr. Uwe Schmidt |