Rev | Line | |
---|
[9] | 1 | ! strchr() Author: Kees J. Bot
|
---|
| 2 | ! 27 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 | _strchr:
|
---|
| 11 | push bp
|
---|
| 12 | mov bp, sp
|
---|
| 13 | push di
|
---|
| 14 | cld
|
---|
| 15 | mov di, 4(bp) ! di = string
|
---|
| 16 | mov dx, #16 ! Look at small chunks of the string
|
---|
| 17 | next: shl dx, #1 ! Chunks become bigger each time
|
---|
| 18 | mov cx, dx
|
---|
| 19 | xorb al, al ! Look for the zero at the end
|
---|
| 20 | repne scasb
|
---|
| 21 | pushf ! Remember the flags
|
---|
| 22 | sub cx, dx
|
---|
| 23 | neg cx ! Some or all of the chunk
|
---|
| 24 | sub di, cx ! Step back
|
---|
| 25 | movb al, 6(bp) ! The character to look for
|
---|
| 26 | repne scasb
|
---|
| 27 | je found
|
---|
| 28 | popf ! Did we find the end of string earlier?
|
---|
| 29 | jne next ! No, try again
|
---|
| 30 | xor ax, ax ! Return NULL
|
---|
| 31 | pop di
|
---|
| 32 | pop bp
|
---|
| 33 | ret
|
---|
| 34 | found: pop ax ! Get rid of those flags
|
---|
| 35 | lea ax, -1(di) ! Address of byte found
|
---|
| 36 | pop di
|
---|
| 37 | pop bp
|
---|
| 38 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.