minix/lib/libc/arch/i386/string/strrchr.S
Arun Thomas 9a21d1a2fd Macros for symbols used in both ASM and C
-The macros take care of prepending the leading underscore when
 necessary.
2010-08-17 16:44:07 +00:00

35 lines
757 B
ArmAsm

/* strrchr() Author: Kees J. Bot */
/* 2 Jan 1994 */
/* char *strrchr(const char *s, int c) */
/* Look for the last occurrence a character in a string. */
/* */
#include <machine/asm.h>
ENTRY(strrchr)
push %ebp
movl %esp, %ebp
push %edi
movl 8(%ebp), %edi /* edi = string */
movl $-1, %ecx
xorb %al, %al
cld
repne scasb /* Look for the end of the string */
notl %ecx /* -1 - ecx = Length of the string + null */
decl %edi /* Put edi back on the zero byte */
movb 12(%ebp), %al /* The character to look for */
std /* Downwards search */
repne scasb
cld /* Direction bit back to default */
jne failure
leal 1(%edi), %eax /* Found it */
pop %edi
pop %ebp
ret
failure:
xorl %eax, %eax /* Not there */
pop %edi
pop %ebp
ret