1/* index.s 4.3 84/11/04 */ 2 3/* 4 * Find the first occurence of c in the string cp. 5 * Return pointer to match or null pointer. 6 * 7 * char * 8 * index(cp, c) 9 * char *cp, c; 10 */ 11#include "DEFS.h" 12 13ENTRY(index, 0) 14 movq 4(ap),r1 # r1 = cp; r2 = c 15 tstl r2 # check for special case c == '\0' 16 bneq 2f 171: 18 locc $0,$65535,(r1) # just find end of string 19 beql 1b # still looking 20 movl r1,r0 # found it 21 ret 222: 23 moval tbl,r3 # r3 = address of table 24 bbss $0,(r3),5f # insure not reentering 25 movab (r3)[r2],r5 # table entry for c 26 incb (r5) 27 movzwl $65535,r4 # fast access 283: 29 scanc r4,(r1),(r3),$1 # look for c or '\0' 30 beql 3b # still looking 31 movl r1,r0 # return pointer to char 32 tstb (r0) # if have found '\0' 33 bneq 4f 34 clrl r0 # else return 0 354: 36 clrb (r5) # clean up table 37 clrb (r3) 38 ret 39 40 .data 41tbl: .space 256 42 .text 43 44/* 45 * Reentrant, but slower version of index 46 */ 475: 48 movl r1,r3 496: 50 locc $0,$65535,(r3) # look for '\0' 51 bneq 7f 52 locc r2,$65535,(r3) # look for c 53 bneq 8f 54 movl r1,r3 # reset pointer and ... 55 jbr 6b # ... try again 567: 57 subl3 r3,r1,r4 # length of short block 58 incl r4 # +1 for '\0' 59 locc r2,r4,(r3) # look for c 60 bneq 8f 61 ret 628: 63 movl r1,r0 # return pointer to char 64 ret 65