Rev | Line | |
---|
[9] | 1 | ! strrchr() Author: Kees J. Bot
|
---|
| 2 | ! 27 Jan 1994
|
---|
| 3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
| 4 |
|
---|
| 5 | ! char *strrchr(const char *s, int c)
|
---|
| 6 | ! Look for the last occurrence a character in a string.
|
---|
| 7 | !
|
---|
| 8 | .sect .text
|
---|
| 9 | .define _strrchr
|
---|
| 10 | _strrchr:
|
---|
| 11 | push bp
|
---|
| 12 | mov bp, sp
|
---|
| 13 | push di
|
---|
| 14 | mov di, 4(bp) ! di = string
|
---|
| 15 | mov cx, #-1
|
---|
| 16 | xorb al, al
|
---|
| 17 | cld
|
---|
| 18 | repne scasb ! Look for the end of the string
|
---|
| 19 | not cx ! -1 - cx = Length of the string + null
|
---|
| 20 | dec di ! Put di back on the zero byte
|
---|
| 21 | movb al, 6(bp) ! The character to look for
|
---|
| 22 | std ! Downwards search
|
---|
| 23 | repne scasb
|
---|
| 24 | cld ! Direction bit back to default
|
---|
| 25 | jne failure
|
---|
| 26 | lea ax, 1(di) ! Found it
|
---|
| 27 | pop di
|
---|
| 28 | pop bp
|
---|
| 29 | ret
|
---|
| 30 | failure:xor ax, ax ! Not there
|
---|
| 31 | pop di
|
---|
| 32 | pop bp
|
---|
| 33 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.