1: /*
   2:  * Copyright (c) 1987 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifdef LIBC_SCCS
   8:         <@(#)rindex.s	1.2 (2.11BSD) 1996/1/12\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: /*
  13:  * Find the last occurence of c in the string cp.
  14:  * Return pointer to match or null pointer.
  15:  *
  16:  * char *
  17:  * rindex(cp, c)
  18:  *	char *cp, c;
  19:  */
  20: #include "DEFS.h"
  21: 
  22:         .globl  _strrchr
  23: _strrchr = _rindex ^ .
  24: 
  25: ENTRY(rindex)
  26:         mov     2(sp),r0        / r0 = cp
  27:         mov     4(sp),r1        / r1 = c
  28:         beq     3f              / check for special case of c == '\0'
  29:         mov     r2,-(sp)        / need an extra register to keep track of
  30:         clr     r2              /   last occurance of c (not found == 0)
  31: 1:
  32:         cmpb    (r0),r1         / look for c ...
  33:         beq     2f
  34:         tstb    (r0)+           / but don't pass end of string ...
  35:         bne     1b
  36:         mov     r2,r0           / fell off the end of the string - return
  37:         mov     (sp)+,r2        /   last occurance of c
  38:         rts     pc
  39: 2:
  40:         mov     r0,r2           / remember position of c and bounce back into
  41:         inc     r0              /   loop one position further
  42:         br      1b
  43: 3:
  44:         tstb    (r0)+           / just find end of string
  45:         bne     3b
  46:         dec     r0              / back up to '\0'
  47:         rts     pc              /   and return pointer

Defined functions

_rindex defined in line 25; used 180 times
Last modified: 1996-01-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 4025
Valid CSS Valid XHTML 1.0 Strict