/	Copyright (c) 1984, 1986, 1987, 1988 AT&T
/	  All Rights Reserved

/	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
/	The copyright notice above does not evidence any
/	actual or intended publication of such source code.
	.file	"strncmp.s"

	.ident	"@(#)libc-i386:libc-i386/gen/strncmp.s	1.2.1.1"

	.globl	strncmp
	.align	4

strncmp:
	MCOUNT
	pushl	%edi		/ save register variables
	pushl	%esi

	movl	12(%esp),%esi	/ %esi = first string
	movl	16(%esp),%edi	/ %edi = second string
	cmpl	%esi,%edi	/ same string?
	je	.equal
	movl	20(%esp),%ecx	/ %ecx = length
	incl	%ecx		/ will later predecrement this uint

.loop:
	decl	%ecx
	je	.equal		/ Used all n chars?
	slodb ; scab
	jne	.notequal	/ Are the bytes equal?
	testb	%al,%al
	je	.equal		/ End of string?

	decl	%ecx
	je	.equal		/ Used all n chars?
	slodb ; scab
	jne	.notequal	/ Are the bytes equal?
	testb	%al,%al
	je	.equal		/ End of string?

	decl	%ecx
	je	.equal		/ Used all n chars?
	slodb ; scab
	jne	.notequal	/ Are the bytes equal?
	testb	%al,%al
	je	.equal		/ End of string?

	decl	%ecx
	je	.equal		/ Used all n chars?
	slodb ; scab
	jne	.notequal	/ Are the bytes equal?
	testb	%al,%al
	jne	.loop		/ End of string?

.equal:
	xorl	%eax,%eax	/ return 0
	popl	%esi		/ restore registers
	popl	%edi
	ret	

.notequal:
	movzbl	%al,%eax
	movzbl	-1(%edi),%edx
	subl	%edx,%eax
	popl	%esi		/ restore registers
	popl	%edi
	ret	
