xref: /csrg-svn/lib/libc/vax/string/strncmp.s (revision 61222)
121437Sdist/*
2*61222Sbostic * Copyright (c) 1983, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
434481Sbostic *
542639Sbostic * %sccs.include.redist.c%
621437Sdist */
717324Ssam
834819Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)strncmp.s	8.1 (Berkeley) 06/04/93"
1034819Sbostic#endif /* LIBC_SCCS and not lint */
1121437Sdist
1217324Ssam/*
1317324Ssam * Compare at most n characters of string
1417324Ssam * s1 lexicographically to string s2.
1517324Ssam * Return:
1617324Ssam *	0	s1 == s2
1717324Ssam *	> 0	s1 > s2
1817324Ssam *	< 0	s2 < s2
1917324Ssam *
2017324Ssam * strncmp(s1, s2, n)
2117324Ssam *	char *s1, *s2;
2217324Ssam *	int n;
2317324Ssam */
2417329Ssam#include "DEFS.h"
2517324Ssam
2617329SsamENTRY(strncmp, 0)
2717364Smckusick	movl	4(ap),r1	# r1 = s1
2817364Smckusick	movq	8(ap),r3	# r3 = s2; r4 = n
2917324Ssam1:
3017483Smckusick	clrl	r5		# calculate min bytes to next page boundry
3117483Smckusick	subb3	r1,$255,r5	# r5 = (bytes - 1) to end of page for s1
3217483Smckusick	subb3	r3,$255,r0	# r0 = (bytes - 1) to end of page for s2
3317483Smckusick	cmpb	r0,r5		# r5 = min(r0, r5);
3417483Smckusick	bgtru	2f
3517483Smckusick	movb	r0,r5
3617483Smckusick2:
3717483Smckusick	incl	r5		# r5 = min bytes to next page boundry
3817483Smckusick	cmpl	r4,r5		# r5 = min(n, r5);
3917483Smckusick	bgeq	3f
4017364Smckusick	movl	r4,r5
4117483Smckusick3:
4217364Smckusick	cmpc3	r5,(r1),(r3)	# compare strings
4317483Smckusick	bneq	4f
4417364Smckusick	subl2	r5,r4		# check for end of comparison
4517483Smckusick	beql	5f
4617364Smckusick	subl2	r5,r1		# check if found null yet
4717364Smckusick	locc	$0,r5,(r1)
4817364Smckusick	beql	1b		# not yet done, continue checking
4917447Smckusick	subl2	r0,r3
5017447Smckusick	mnegb	(r3),r0		# r0 = '\0' - *s2
5117364Smckusick	cvtbl	r0,r0
5217364Smckusick	ret
5317483Smckusick4:
5417364Smckusick	subl2	r0,r5		# check for null in matching string
5517364Smckusick	subl2	r5,r1
5617364Smckusick	locc	$0,r5,(r1)
5717483Smckusick	bneq	5f
5817447Smckusick	subb3	(r3),(r1),r0	# r0 = *s1 - *s2
5917324Ssam	cvtbl	r0,r0
6017324Ssam	ret
6117483Smckusick5:
6217364Smckusick	clrl	r0		# both the same to null
6317364Smckusick	ret
64