Annotation of researchv10no/libc/gen/strspn.s, revision 1.1

1.1     ! root        1:        .file   "strcpn.s"
        !             2: #      @(#)strspn.s    1.6
        !             3: # Fast assembler language version of the following C-program
        !             4: #                      strspn
        !             5: # which represents the `standard' for the C-library.
        !             6: 
        !             7: #      Return the number of characters in the maximum leading segment
        !             8: #      of string which consists solely of characters from charset.
        !             9: 
        !            10: #      int
        !            11: #      strspn(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  _strspn
        !            26:        .text
        !            27:        .align  2
        !            28: _strspn:
        !            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:        beql    L5                      # return 0 if arg was NULL
        !            34: L0:
        !            35:        movzbl  (r0)+,r3                # byte from charset for index
        !            36:        beql    L1                      # hop if found ending NULL
        !            37:        movb    $255,(sp)[r3]           # make entry in spanc table
        !            38:        jmp     L0                      # get next byte from charset
        !            39: L1:
        !            40:        movl    4(ap),r1                # string ptr in r1
        !            41:        beql    L4                      # if it's NULL, return 0
        !            42: L2:
        !            43:        movl    r1,r4                   # preserve a copy of this ptr
        !            44:        locc    $0,$65535,(r1)          # get length of string
        !            45:        bneq    L3                      # skip if string not > 65535
        !            46:        spanc   $65535,(r4),(sp),$255   # else spanc the first 65535
        !            47:        bneq    L4                      # hop ahead if we ended the span
        !            48:        jmp     L2                      # else go back and do next 65535
        !            49: L3:
        !            50:        subl3   r4,r1,r0                # length to end of string in r0
        !            51:        spanc   r0,(r4),(sp),$255       # this is the main function
        !            52: L4:
        !            53:        subl3   4(ap),r1,r0             # length of the span
        !            54: L5:
        !            55:        movab   256(sp),sp              # restore the stack pointer
        !            56:        ret

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.