Rev 1408 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1627 | serge | 1 | /* strchr() Author: Kees J. Bot */ |
2 | /* 1 Jan 1994 */ |
||
1408 | serge | 3 | |
1627 | serge | 4 | /* char *strchr(const char *s, int c) */ |
5 | /* Look for a character in a string. */ |
||
6 | /* */ |
||
7 | #include "asm.h" |
||
1408 | serge | 8 | |
1627 | serge | 9 | ENTRY(strchr) |
10 | push %ebp |
||
11 | movl %esp, %ebp |
||
12 | push %edi |
||
13 | cld |
||
14 | movl 8(%ebp), %edi /* edi = string */ |
||
15 | movl $16, %edx /* Look at small chunks of the string */ |
||
1408 | serge | 16 | next: |
1627 | serge | 17 | shll $1, %edx /* Chunks become bigger each time */ |
18 | movl %edx, %ecx |
||
19 | xorb %al, %al /* Look for the zero at the end */ |
||
1408 | serge | 20 | |
1627 | serge | 21 | repne scasb |
22 | pushf /* Remember the flags */ |
||
23 | subl %edx, %ecx |
||
24 | negl %ecx /* Some or all of the chunk */ |
||
25 | subl %ecx, %edi /* Step back */ |
||
26 | movb 12(%ebp), %al /* The character to look for */ |
||
1408 | serge | 27 | |
1627 | serge | 28 | repne scasb |
29 | je found |
||
30 | popf /* Did we find the end of string earlier? */ |
||
31 | jne next /* No, try again */ |
||
32 | xorl %eax, %eax /* Return NULL */ |
||
33 | pop %edi |
||
34 | pop %ebp |
||
35 | ret |
||
1408 | serge | 36 | found: |
1627 | serge | 37 | pop %eax /* Get rid of those flags */ |
38 | leal -1(%edi), %eax /* Address of byte found */ |
||
39 | pop %edi |
||
40 | pop %ebp |
||
41 | ret |