Line | |
---|
1 | ! strncmp() Author: Kees J. Bot
|
---|
2 | ! 27 Jan 1994
|
---|
3 | .sect .text; .sect .rom; .sect .data; .sect .bss
|
---|
4 |
|
---|
5 | ! int strncmp(const char *s1, const char *s2, size_t cx)
|
---|
6 | ! Compare two strings.
|
---|
7 | !
|
---|
8 | .sect .text
|
---|
9 | .define __strncmp
|
---|
10 | __strncmp:
|
---|
11 | push bp
|
---|
12 | mov bp, sp
|
---|
13 | push si
|
---|
14 | push di
|
---|
15 | xor ax, ax ! Prepare return value
|
---|
16 | test cx, cx ! Max length is zero?
|
---|
17 | je equal
|
---|
18 | mov si, 4(bp) ! si = string s1
|
---|
19 | mov di, 6(bp) ! di = string s2
|
---|
20 | cld
|
---|
21 | compare:
|
---|
22 | cmpsb ! Compare two bytes
|
---|
23 | jne unequal
|
---|
24 | cmpb -1(si), #0 ! End of string?
|
---|
25 | je equal
|
---|
26 | dec cx ! Length limit reached?
|
---|
27 | jne compare
|
---|
28 | jmp equal
|
---|
29 | unequal:
|
---|
30 | ja after
|
---|
31 | sub ax, #2 ! if (s1 < s2) ax -= 2;
|
---|
32 | after: inc ax ! ax++, now it's -1 or 1
|
---|
33 | equal: pop di
|
---|
34 | pop si
|
---|
35 | pop bp
|
---|
36 | ret
|
---|
Note:
See
TracBrowser
for help on using the repository browser.