Commit | Line | Data |
---|---|---|
3d8a65a3 | 1 | /* strncmp.s 4.3 84/11/14 */ |
6a124eb1 SL |
2 | |
3 | /* | |
4 | * Compare at most n characters of string | |
5 | * s1 lexicographically to string s2. | |
6 | * Return: | |
7 | * 0 s1 == s2 | |
8 | * > 0 s1 > s2 | |
9 | * < 0 s2 < s2 | |
10 | * | |
11 | * strncmp(s1, s2, n) | |
12 | * char *s1, *s2; | |
13 | * int n; | |
14 | */ | |
dadab5a2 | 15 | #include "DEFS.h" |
6a124eb1 | 16 | |
dadab5a2 | 17 | ENTRY(strncmp, 0) |
3d8a65a3 KM |
18 | movl 4(ap),r1 # r1 = s1 |
19 | movq 8(ap),r3 # r3 = s2; r4 = n | |
6a124eb1 | 20 | 1: |
3d8a65a3 KM |
21 | movl $32,r5 # r5 = current blocksize |
22 | cmpl r4,r5 # r5 = min(n, 32); | |
23 | bgeq 2f | |
24 | movl r4,r5 | |
6a124eb1 | 25 | 2: |
3d8a65a3 | 26 | cmpc3 r5,(r1),(r3) # compare strings |
6a124eb1 | 27 | bneq 3f |
3d8a65a3 KM |
28 | subl2 r5,r4 # check for end of comparison |
29 | beql 4f | |
30 | subl2 r5,r1 # check if found null yet | |
31 | locc $0,r5,(r1) | |
32 | beql 1b # not yet done, continue checking | |
33 | subl2 r5,r0 | |
34 | mnegb (r0)[r3],r0 # r0 = $0 - *s2 | |
35 | cvtbl r0,r0 | |
36 | ret | |
6a124eb1 | 37 | 3: |
3d8a65a3 KM |
38 | subl2 r0,r5 # check for null in matching string |
39 | subl2 r5,r1 | |
40 | locc $0,r5,(r1) | |
41 | bneq 4f | |
42 | subb3 (r3),-(r1),r0 # r0 = *s1 - *s2 | |
6a124eb1 SL |
43 | cvtbl r0,r0 |
44 | ret | |
3d8a65a3 KM |
45 | 4: |
46 | clrl r0 # both the same to null | |
47 | ret |