1/* rindex.s 4.1 84/11/01 */ 2 3/* 4 * Find the last occurence of c in the string cp. 5 * Return pointer to match or null pointer. 6 * 7 * char * 8 * rindex(cp, c) 9 * char *cp, c; 10 */ 11 .globl _rindex 12 13_rindex: 14 .word 0x0 15 movq 4(ap),r1 # r1 = cp; r2 = c 16 tstl r2 # check for special case c == '\0' 17 bneq 2f 181: 19 locc $0,$65535,(r1) # just find end of string 20 beql 1b # still looking 21 movl r1,r0 # found it 22 ret 232: 24 movab tbl[r2],r5 # table entry for c 25 incb (r5) 26 clrl r4 # last found 273: 28 scanc $65535,(r1),tbl,$1 # look for c or '\0' 29 beql 3b # keep looking 30 tstb (r1) # if have found '\0' 31 beql 4f # we are done 32 movl r1,r4 # save most recently found 33 incl r1 # skip over character 34 jbr 3b # keep looking 354: 36 movl r4,r0 # return last found (if any) 37 clrb (r5) # clean up table 38 ret 39 40 .data 41tbl: .byte 1 42 .space 255 43 .text 44