xref: /original-bsd/usr.bin/f77/libF77/CCI/rindex_s.s (revision 3b6250d9)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.proprietary.c%
9 */
10
11#ifndef lint
12	.asciz "@(#)rindex_s.s	5.2 (Berkeley) 04/12/91"
13#endif /* not lint */
14
15.data
16.text
17LL0:.align	1
18.globl	_rindex_
19.set MASK__,0x1c0c
20.data
21.text
22_rindex_: .word	MASK__
23
24	movl	16(fp),r12	/* sublen */
25	tstl	r12		/* if sublen == 0 */
26	jeql	out0		/*   return(0L) */
27
28	movl 	4(fp), r11	/* str */
29	movl	8(fp), r10	/* substr */
30	addl3	r11, 12(fp), r3	/* p = str + strlen */
31	subl2	r12, r3		/* p -= sublen */
32loop:
33	cmpl	r3, r11		/* while (p >= str) */
34	jlss	out0		/* not found - return(0L) */
35	movl	r3, r0		/* current p (in str) */
36	movl	r10, r1		/* substr */
37	movl 	r12, r2		/* sublen */
38	cmps3			/* if strigs equal */
39	jeql	out		/* return index */
40
41	decl	r3		/* p-- */
42	jbr	loop
43
44out:
45	incl	r3		/* index = ++p - str */
46	subl3	r11, r3, r0
47	ret
48
49out0:
50	clrl	r0
51	ret
52
53