xref: /original-bsd/lib/libc/vax/string/strncmp.s (revision 8b87d5f9)
1/*	strncmp.s	4.5	84/12/06	*/
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 */
15#include "DEFS.h"
16
17ENTRY(strncmp, 0)
18	movl	4(ap),r1	# r1 = s1
19	movq	8(ap),r3	# r3 = s2; r4 = n
201:
21	clrl	r5		# calculate min bytes to next page boundry
22	subb3	r1,$255,r5	# r5 = (bytes - 1) to end of page for s1
23	subb3	r3,$255,r0	# r0 = (bytes - 1) to end of page for s2
24	cmpb	r0,r5		# r5 = min(r0, r5);
25	bgtru	2f
26	movb	r0,r5
272:
28	incl	r5		# r5 = min bytes to next page boundry
29	cmpl	r4,r5		# r5 = min(n, r5);
30	bgeq	3f
31	movl	r4,r5
323:
33	cmpc3	r5,(r1),(r3)	# compare strings
34	bneq	4f
35	subl2	r5,r4		# check for end of comparison
36	beql	5f
37	subl2	r5,r1		# check if found null yet
38	locc	$0,r5,(r1)
39	beql	1b		# not yet done, continue checking
40	subl2	r0,r3
41	mnegb	(r3),r0		# r0 = '\0' - *s2
42	cvtbl	r0,r0
43	ret
444:
45	subl2	r0,r5		# check for null in matching string
46	subl2	r5,r1
47	locc	$0,r5,(r1)
48	bneq	5f
49	subb3	(r3),(r1),r0	# r0 = *s1 - *s2
50	cvtbl	r0,r0
51	ret
525:
53	clrl	r0		# both the same to null
54	ret
55