|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 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: .asciz "@(#)index.s 5.3 (Berkeley) 3/9/86" ! 9: #endif LIBC_SCCS ! 10: ! 11: /* ! 12: * Find the first occurence of c in the string cp. ! 13: * Return pointer to match or null pointer. ! 14: * ! 15: * char * ! 16: * index(cp, c) ! 17: * char *cp, c; ! 18: */ ! 19: #include "DEFS.h" ! 20: ! 21: ENTRY(index, 0) ! 22: movq 4(ap),r1 # r1 = cp; r2 = c ! 23: tstl r2 # check for special case c == '\0' ! 24: bneq 2f ! 25: 1: ! 26: locc $0,$65535,(r1) # just find end of string ! 27: beql 1b # still looking ! 28: movl r1,r0 # found it ! 29: ret ! 30: 2: ! 31: moval tbl,r3 # r3 = address of table ! 32: bbss $0,(r3),5f # insure not reentering ! 33: movab (r3)[r2],r5 # table entry for c ! 34: incb (r5) ! 35: movzwl $65535,r4 # fast access ! 36: 3: ! 37: scanc r4,(r1),(r3),$1 # look for c or '\0' ! 38: beql 3b # still looking ! 39: movl r1,r0 # return pointer to char ! 40: tstb (r0) # if have found '\0' ! 41: bneq 4f ! 42: clrl r0 # else return 0 ! 43: 4: ! 44: clrb (r5) # clean up table ! 45: clrb (r3) ! 46: ret ! 47: ! 48: .data ! 49: tbl: .space 256 ! 50: .text ! 51: ! 52: /* ! 53: * Reentrant, but slower version of index ! 54: */ ! 55: 5: ! 56: movl r1,r3 ! 57: 6: ! 58: locc $0,$65535,(r3) # look for '\0' ! 59: bneq 7f ! 60: locc r2,$65535,(r3) # look for c ! 61: bneq 8f ! 62: movl r1,r3 # reset pointer and ... ! 63: jbr 6b # ... try again ! 64: 7: ! 65: subl3 r3,r1,r4 # length of short block ! 66: incl r4 # +1 for '\0' ! 67: locc r2,r4,(r3) # look for c ! 68: bneq 8f ! 69: ret ! 70: 8: ! 71: movl r1,r0 # return pointer to char ! 72: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.