2010-03-03 15:27:30 +01:00
|
|
|
/* memchr() Author: Kees J. Bot */
|
|
|
|
/* 2 Jan 1994 */
|
|
|
|
|
|
|
|
/* void *memchr(const void *s, int c, size_t n) */
|
|
|
|
/* Look for a character in a chunk of memory. */
|
|
|
|
/* */
|
2010-08-17 18:44:07 +02:00
|
|
|
#include <machine/asm.h>
|
|
|
|
|
|
|
|
ENTRY(memchr)
|
2010-03-03 15:27:30 +01:00
|
|
|
push %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
push %edi
|
|
|
|
movl 8(%ebp), %edi /* edi = string */
|
|
|
|
movb 12(%ebp), %al /* The character to look for */
|
|
|
|
movl 16(%ebp), %ecx /* Length */
|
|
|
|
cmpb $1, %cl /* 'Z' bit must be clear if ecx = 0 */
|
|
|
|
cld
|
|
|
|
|
|
|
|
repne scasb
|
|
|
|
jne failure
|
|
|
|
leal -1(%edi), %eax /* Found */
|
|
|
|
pop %edi
|
|
|
|
pop %ebp
|
|
|
|
ret
|
|
|
|
failure:
|
|
|
|
xorl %eax, %eax
|
|
|
|
pop %edi
|
|
|
|
pop %ebp
|
|
|
|
ret
|