Rev | Line | |
---|
[9] | 1 | ! _strnlen() Author: Kees J. Bot
|
---|
| 2 | ! 27 Jan 1994
|
---|
| 3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
| 4 |
|
---|
| 5 | ! size_t _strnlen(const char *s, size_t cx)
|
---|
| 6 | ! Return the length of a string.
|
---|
| 7 | !
|
---|
| 8 | .sect .text
|
---|
| 9 | .define __strnlen
|
---|
| 10 | __strnlen:
|
---|
| 11 | push bp
|
---|
| 12 | mov bp, sp
|
---|
| 13 | push di
|
---|
| 14 | mov di, 4(bp) ! di = string
|
---|
| 15 | xorb al, al ! Look for a zero byte
|
---|
| 16 | mov dx, cx ! Save maximum count
|
---|
| 17 | cmpb cl, #1 ! 'Z' bit must be clear if cx = 0
|
---|
| 18 | cld
|
---|
| 19 | repne scasb ! Look for zero
|
---|
| 20 | jne no0
|
---|
| 21 | inc cx ! Don't count zero byte
|
---|
| 22 | no0: mov ax, dx
|
---|
| 23 | sub ax, cx ! Compute bytes scanned
|
---|
| 24 | pop di
|
---|
| 25 | pop bp
|
---|
| 26 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.