xref: /original-bsd/lib/libc/vax/string/strncmp.s (revision a95f03a8)
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)strncmp.s	5.6 (Berkeley) 06/01/90"
10#endif /* LIBC_SCCS and not lint */
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 */
24#include "DEFS.h"
25
26ENTRY(strncmp, 0)
27	movl	4(ap),r1	# r1 = s1
28	movq	8(ap),r3	# r3 = s2; r4 = n
291:
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
362:
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:
42	cmpc3	r5,(r1),(r3)	# compare strings
43	bneq	4f
44	subl2	r5,r4		# check for end of comparison
45	beql	5f
46	subl2	r5,r1		# check if found null yet
47	locc	$0,r5,(r1)
48	beql	1b		# not yet done, continue checking
49	subl2	r0,r3
50	mnegb	(r3),r0		# r0 = '\0' - *s2
51	cvtbl	r0,r0
52	ret
534:
54	subl2	r0,r5		# check for null in matching string
55	subl2	r5,r1
56	locc	$0,r5,(r1)
57	bneq	5f
58	subb3	(r3),(r1),r0	# r0 = *s1 - *s2
59	cvtbl	r0,r0
60	ret
615:
62	clrl	r0		# both the same to null
63	ret
64