Annotation of researchv10dc/libc/gen/strncmp.s, revision 1.1

1.1     ! root        1:        .file   "strncmp.s"
        !             2: #      @(#)strncmp.s   1.4
        !             3: # Fast assembler language version of the following C-program
        !             4: #                      strncmp
        !             5: # which represents the `standard' for the C-library.
        !             6: 
        !             7: # Compare strings (at most n bytes): return *s1-*s2 for the last
        !             8: # characters in s1 and s2 which were compared.
        !             9: 
        !            10: #      strncmp(s1, s2, n)
        !            11: #      register char *s1, *s2;
        !            12: #      register n;
        !            13: #      {
        !            14: #              if(s1 == s2)
        !            15: #                      return(0);
        !            16: #              while(--n >= 0 && *s1 == *s2++)
        !            17: #                      if(*s1++ == '\0')
        !            18: #                              return(0);
        !            19: #              return((n < 0)? 0: *s1 - *--s2);
        !            20: #      }
        !            21:        .globl  _strncmp
        !            22:        .text
        !            23:        .align  2
        !            24: _strncmp:
        !            25:        .word   0x0000          # uses regs. 0,1,2,3,4,5
        !            26:        movl    12(ap),r4       # arg `n'
        !            27:        bgtr    L1              #      should be > 0
        !            28: L0:
        !            29:        clrl    r0              # else return a zero
        !            30:        ret
        !            31: L1:
        !            32:        movl    4(ap),r1        # working copy of s1
        !            33:        movl    8(ap),r3        # working copy of s2
        !            34:        cmpl    r1,r3           # if pointers are eql, strings are also
        !            35:        beql    L0              # return a zero
        !            36: L2:
        !            37:        subl3   $65535,r4,r5    # memory for whether `n' <= 65535
        !            38:        blss    L3              # skip if r4 is not too big
        !            39:        movl    $65535,r4       # else use big number (remdr in r5)
        !            40: L3:
        !            41:        movl    r1,r2           # hide r1 while searching for end
        !            42:        locc    $0,r4,(r1)      # search for terminal null in s1
        !            43:        beql    L4              # hop, null not found
        !            44:        clrl    r5              # found, we sure won't need to go again
        !            45:        subl3   r2,r1,r4        # length of s1
        !            46:        incl    r4              # add 1 to account for the null
        !            47: L4:
        !            48:        movl    r2,r1           # restore copy of s1 for the cmpc3
        !            49:        cmpc3   r4,(r1),(r3)    # Compare s1 and s2
        !            50:        beql    L5              # skip if strings are ==, (so far)
        !            51:        subb3   (r3),(r1),r0    # else difference is returned
        !            52:        cvtbl   r0,r0           # gotta make it an int
        !            53:        ret
        !            54: L5:
        !            55:        movl    r5,r4
        !            56:        bgtr    L2              # if more compare is needed, go back
        !            57:        ret                     # note that r0 is already 0 in this case

unix.superglobalmegacorp.com

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