|
|
1.1 ! root 1: .file "strcspn.s" ! 2: # @(#)strcspn.s 1.5 ! 3: # Fast assembler language version of the following C-program ! 4: # strcspn ! 5: # which represents the `standard' for the C-library. ! 6: ! 7: # Return the number of characters in the maximal leading segment ! 8: # of `string' which consists only of characters NOT in `charset'. ! 9: ! 10: # int ! 11: # strcspn(string, charset) ! 12: # char *string; ! 13: # register char *charset; ! 14: # { ! 15: # register char *p, *q; ! 16: ! 17: # for(q=string; *q != '\0'; ++q) { ! 18: # for(p=charset; *p != '\0' && *p != *q; ++p) ! 19: # ; ! 20: # if(*p != '\0') ! 21: # break; ! 22: # } ! 23: # return(q-string); ! 24: # } ! 25: .globl _strcspn ! 26: .text ! 27: .align 2 ! 28: _strcspn: ! 29: .word 0x0000 # pgm uses regs 0,1,2,3,4 ! 30: movab -256(sp),sp # get table space ! 31: movc5 $0,(ap),$0,$256,(sp) # and zero it out ! 32: movl 8(ap),r0 # charset ptr in r0 ! 33: bneq L1 # go ahead if arg non-NULL ! 34: movl 4(ap),r1 # string ptr in r1 ! 35: L0: ! 36: locc $0,$65535,(r1) # NULL charset - return length ! 37: beql L0 # of string arg ! 38: jmp L5 ! 39: L1: ! 40: movzbl (r0)+,r3 # byte from charset for index ! 41: beql L2 # hop if found ending NULL ! 42: movb $255,(sp)[r3] # make entry in scanc table ! 43: jmp L1 # get next byte from charset ! 44: L2: ! 45: movl 4(ap),r1 # string ptr in r1 ! 46: beql L5 # if it's NULL, return 0 ! 47: L3: ! 48: movl r1,r4 # preserve a copy of this ptr ! 49: locc $0,$65535,(r1) # get length of string ! 50: bneq L4 # skip if string not > 65535 ! 51: scanc $65535,(r4),(sp),$255 # else scanc the first 65535 ! 52: bneq L5 # hop ahead if we found one ! 53: jmp L3 # else go back and do next 65535 ! 54: L4: ! 55: subl3 r4,r1,r0 # length to end of string in r0 ! 56: scanc r0,(r4),(sp),$255 # this is the main function ! 57: L5: ! 58: subl3 4(ap),r1,r0 # length of segment returned ! 59: movab 256(sp),sp # restore the stack pointer ! 60: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.