Rev | Line | |
---|
[9] | 1 | ! strncmp() Author: Kees J. Bot
|
---|
| 2 | ! 1 Jan 1994
|
---|
| 3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
| 4 |
|
---|
| 5 | ! int strncmp(const char *s1, const char *s2, size_t ecx)
|
---|
| 6 | ! Compare two strings.
|
---|
| 7 | !
|
---|
| 8 | .sect .text
|
---|
| 9 | .define __strncmp
|
---|
| 10 | .align 16
|
---|
| 11 | __strncmp:
|
---|
| 12 | push ebp
|
---|
| 13 | mov ebp, esp
|
---|
| 14 | push esi
|
---|
| 15 | push edi
|
---|
| 16 | test ecx, ecx ! Max length is zero?
|
---|
| 17 | je done
|
---|
| 18 | mov esi, 8(ebp) ! esi = string s1
|
---|
| 19 | mov edi, 12(ebp) ! edi = string s2
|
---|
| 20 | cld
|
---|
| 21 | compare:
|
---|
| 22 | cmpsb ! Compare two bytes
|
---|
| 23 | jne done
|
---|
| 24 | cmpb -1(esi), 0 ! End of string?
|
---|
| 25 | je done
|
---|
| 26 | dec ecx ! Length limit reached?
|
---|
| 27 | jne compare
|
---|
| 28 | done: seta al ! al = (s1 > s2)
|
---|
| 29 | setb ah ! ah = (s1 < s2)
|
---|
| 30 | subb al, ah
|
---|
| 31 | movsxb eax, al ! eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
|
---|
| 32 | pop edi
|
---|
| 33 | pop esi
|
---|
| 34 | pop ebp
|
---|
| 35 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.