Line | |
---|
1 | ! strchr() Author: Kees J. Bot
|
---|
2 | ! 1 Jan 1994
|
---|
3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
4 |
|
---|
5 | ! char *strchr(const char *s, int c)
|
---|
6 | ! Look for a character in a string.
|
---|
7 | !
|
---|
8 | .sect .text
|
---|
9 | .define _strchr
|
---|
10 | .align 16
|
---|
11 | _strchr:
|
---|
12 | push ebp
|
---|
13 | mov ebp, esp
|
---|
14 | push edi
|
---|
15 | cld
|
---|
16 | mov edi, 8(ebp) ! edi = string
|
---|
17 | mov edx, 16 ! Look at small chunks of the string
|
---|
18 | next: shl edx, 1 ! Chunks become bigger each time
|
---|
19 | mov ecx, edx
|
---|
20 | xorb al, al ! Look for the zero at the end
|
---|
21 | repne
|
---|
22 | scasb
|
---|
23 | pushf ! Remember the flags
|
---|
24 | sub ecx, edx
|
---|
25 | neg ecx ! Some or all of the chunk
|
---|
26 | sub edi, ecx ! Step back
|
---|
27 | movb al, 12(ebp) ! The character to look for
|
---|
28 | repne
|
---|
29 | scasb
|
---|
30 | je found
|
---|
31 | popf ! Did we find the end of string earlier?
|
---|
32 | jne next ! No, try again
|
---|
33 | xor eax, eax ! Return NULL
|
---|
34 | pop edi
|
---|
35 | pop ebp
|
---|
36 | ret
|
---|
37 | found: pop eax ! Get rid of those flags
|
---|
38 | lea eax, -1(edi) ! Address of byte found
|
---|
39 | pop edi
|
---|
40 | pop ebp
|
---|
41 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.