macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libc / vax / string / strncmp.s
CommitLineData
586c39b1
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
493b70ca
KB
3 * All rights reserved.
4 *
019bea33 5 * %sccs.include.redist.c%
586c39b1
DF
6 */
7
f4f66d2c 8#if defined(LIBC_SCCS) && !defined(lint)
019bea33 9 .asciz "@(#)strncmp.s 5.6 (Berkeley) %G%"
f4f66d2c 10#endif /* LIBC_SCCS and not lint */
6a124eb1
SL
11
12/*
13 * Compare at most n characters of string
14 * s1 lexicographically to string s2.
15 * Return:
16 * 0 s1 == s2
17 * > 0 s1 > s2
18 * < 0 s2 < s2
19 *
20 * strncmp(s1, s2, n)
21 * char *s1, *s2;
22 * int n;
23 */
dadab5a2 24#include "DEFS.h"
6a124eb1 25
dadab5a2 26ENTRY(strncmp, 0)
3d8a65a3
KM
27 movl 4(ap),r1 # r1 = s1
28 movq 8(ap),r3 # r3 = s2; r4 = n
6a124eb1 291:
009a82a7
KM
30 clrl r5 # calculate min bytes to next page boundry
31 subb3 r1,$255,r5 # r5 = (bytes - 1) to end of page for s1
32 subb3 r3,$255,r0 # r0 = (bytes - 1) to end of page for s2
33 cmpb r0,r5 # r5 = min(r0, r5);
34 bgtru 2f
35 movb r0,r5
6a124eb1 362:
009a82a7
KM
37 incl r5 # r5 = min bytes to next page boundry
38 cmpl r4,r5 # r5 = min(n, r5);
39 bgeq 3f
40 movl r4,r5
413:
3d8a65a3 42 cmpc3 r5,(r1),(r3) # compare strings
009a82a7 43 bneq 4f
3d8a65a3 44 subl2 r5,r4 # check for end of comparison
009a82a7 45 beql 5f
3d8a65a3
KM
46 subl2 r5,r1 # check if found null yet
47 locc $0,r5,(r1)
48 beql 1b # not yet done, continue checking
5a6eac85
KM
49 subl2 r0,r3
50 mnegb (r3),r0 # r0 = '\0' - *s2
3d8a65a3
KM
51 cvtbl r0,r0
52 ret
009a82a7 534:
3d8a65a3
KM
54 subl2 r0,r5 # check for null in matching string
55 subl2 r5,r1
56 locc $0,r5,(r1)
009a82a7 57 bneq 5f
5a6eac85 58 subb3 (r3),(r1),r0 # r0 = *s1 - *s2
6a124eb1
SL
59 cvtbl r0,r0
60 ret
009a82a7 615:
3d8a65a3
KM
62 clrl r0 # both the same to null
63 ret