/	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	"memccpy.s"

	.ident	"@(#)libc-i386:libc-i386/gen/memccpy.s	1.2"

	.globl	memccpy
	.align	4

memccpy:
	MCOUNT			/ profiling
	pushl	%edi		/ register variables
	pushl	%esi
	movl	12(%esp),%edi	/ %edi = address of dest string
	movl	16(%esp),%esi	/ %esi = address of source string
	movb	20(%esp),%dl	/ %dl = character to search for
	movl	24(%esp),%ecx	/ %ecx = length to go still
.loop:
	decl	%ecx		/ decrement bytes to go
	jl	.notfound
	slodb ; sstob		/ move byte
	cmpb	%dl,%al		/ is it the byte sought?
	je	.found		/ no

	decl	%ecx		/ decrement bytes to go
	jl	.notfound
	slodb ; sstob		/ move byte
	cmpb	%dl,%al		/ is it the byte sought?
	je	.found		/ no

	decl	%ecx		/ decrement bytes to go
	jl	.notfound
	slodb ; sstob		/ move byte
	cmpb	%dl,%al		/ is it the byte sought?
	je	.found		/ no

	decl	%ecx		/ decrement bytes to go
	jl	.notfound
	slodb ; sstob		/ move byte
	cmpb	%dl,%al		/ is it the byte sought?
	jne	.loop		/ no

.found:
	movl	%edi,%eax	/ yes, return byte after in dest
	popl	%esi		/ restore register variables
	popl	%edi
	ret

.notfound:
	xorl	%eax,%eax	/ search fails
	popl	%esi		/ restore register variables
	popl	%edi
	ret
