xref: /netbsd-src/common/lib/libc/arch/m68k/string/strrchr.S (revision 65726deb6103627765b24597784be0763a02c2ca)
1*65726debSmatt/*	$NetBSD: strrchr.S,v 1.4 2013/07/16 23:24:19 matt Exp $	*/
237c9f0a6Schristos
353a0f227Sdsl/*-
453a0f227Sdsl * Copyright (c) 1990 The Regents of the University of California.
553a0f227Sdsl * All rights reserved.
653a0f227Sdsl *
753a0f227Sdsl * This code is derived from software contributed to Berkeley by
853a0f227Sdsl * the Systems Programming Group of the University of Utah Computer
953a0f227Sdsl * Science Department.
1053a0f227Sdsl *
1153a0f227Sdsl * Redistribution and use in source and binary forms, with or without
1253a0f227Sdsl * modification, are permitted provided that the following conditions
1353a0f227Sdsl * are met:
1453a0f227Sdsl * 1. Redistributions of source code must retain the above copyright
1553a0f227Sdsl *    notice, this list of conditions and the following disclaimer.
1653a0f227Sdsl * 2. Redistributions in binary form must reproduce the above copyright
1753a0f227Sdsl *    notice, this list of conditions and the following disclaimer in the
1853a0f227Sdsl *    documentation and/or other materials provided with the distribution.
1953a0f227Sdsl * 3. Neither the name of the University nor the names of its contributors
2053a0f227Sdsl *    may be used to endorse or promote products derived from this software
2153a0f227Sdsl *    without specific prior written permission.
2253a0f227Sdsl *
2353a0f227Sdsl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2453a0f227Sdsl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2553a0f227Sdsl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2653a0f227Sdsl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2753a0f227Sdsl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2853a0f227Sdsl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2953a0f227Sdsl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3053a0f227Sdsl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3153a0f227Sdsl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3253a0f227Sdsl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3353a0f227Sdsl * SUCH DAMAGE.
3453a0f227Sdsl */
3553a0f227Sdsl
3653a0f227Sdsl#include <machine/asm.h>
3753a0f227Sdsl
3853a0f227Sdsl#if defined(LIBC_SCCS) && !defined(lint)
3953a0f227Sdsl#if 0
4053a0f227Sdsl	RCSID("from: @(#)rindex.s	5.1 (Berkeley) 5/12/90")
4153a0f227Sdsl#else
42*65726debSmatt	RCSID("$NetBSD: strrchr.S,v 1.4 2013/07/16 23:24:19 matt Exp $")
4353a0f227Sdsl#endif
4453a0f227Sdsl#endif /* LIBC_SCCS and not lint */
4553a0f227Sdsl
4653a0f227SdslENTRY(strrchr)
4707a0a325Smatt	movl	4(%sp),%a1		| string
4807a0a325Smatt	movb	11(%sp),%d0		| char to look for
4953a0f227Sdsl	subl	%a0,%a0			| clear rindex pointer
5053a0f227Sdslrixloop:
5107a0a325Smatt	cmpb	(%a1),%d0		| found our char?
5253a0f227Sdsl	jne	rixnope			| no, check for null
5353a0f227Sdsl	movl	%a1,%a0			| yes, remember location
5453a0f227Sdslrixnope:
5507a0a325Smatt	tstb	(%a1)+			| null?
5653a0f227Sdsl	jne	rixloop			| no, keep going
5753a0f227Sdsl	movl	%a0,%d0			| return value
5853a0f227Sdsl	rts
59*65726debSmattEND(strrchr)
6053a0f227Sdsl
6153a0f227SdslSTRONG_ALIAS(rindex,strrchr)
62