|
|
1.1 ! root 1: .file "strncpy.s" ! 2: # @(#)strncpy.s 1.6 ! 3: # Fast assembler language version of the following C-program ! 4: # strncpy ! 5: # which represents the `standard' for the C-library. ! 6: ! 7: # Copy s2 to s1, truncating or null-padding to always copy n bytes. ! 8: # Return s1 ! 9: ! 10: # char * ! 11: # strncpy(s1, s2, n) ! 12: # register char *s1, *s2; ! 13: # register int n; ! 14: # { ! 15: # register char *os1 = s1; ! 16: # ! 17: # while (--n >= 0) ! 18: # if ((*s1++ = *s2++) == '\0') ! 19: # while (--n >= 0) ! 20: # *s1++ = '\0'; ! 21: # return (os1); ! 22: # } ! 23: .globl _strncpy ! 24: .text ! 25: .align 2 ! 26: _strncpy: ! 27: .word 0x03c0 # uses regs. 0,1,2,3,4,5,6,7,8,9 ! 28: movl 12(ap),r5 # source length (arg `n') ! 29: bleq L4 # n <= 0, so return now! ! 30: movq 4(ap),r3 # dest ptr ! 31: movl r4,r6 # working copy of src ptr ! 32: movl r5,r2 # copy of `n' for dest. length ! 33: movl $65535,r9 # max length for vax string instructions ! 34: L0: ! 35: subl3 r9,r5,r8 # is max src.len VERY large? ! 36: bleq L1 # hop if not ! 37: movl r9,r5 # wow, src.limit > 65535, (and r8 > 0) ! 38: L1: ! 39: locc $0,r5,(r6) # look for terminal null in src. ! 40: beql L2 # none? then r5 is right, so hop ! 41: subl3 r6,r1,r5 # else src.len < `n'. (put in r5). ! 42: clrl r8 # indicate no more (src) iterations ! 43: L2: ! 44: subl3 r9,r2,r7 # is dest.len VERY large? ! 45: bleq L3 # hop if not ! 46: movl r9,r2 # dest.limit was > 65535 (and r7 > 0) ! 47: L3: ! 48: movc5 r5,(r6),$0,r2,(r3) # Move n bytes, pad with nulls ! 49: movl r7,r2 # was dst.ln > 65535? ! 50: bleq L4 # NO, we're done ! 51: movl r8,r5 # YES, was src.ln also > 65535? ! 52: bgtr L0 # YES, then go move some more ! 53: clrl r5 # NO, set up to pad nulls ! 54: jbr L2 # to dst.ln `n' ! 55: L4: ! 56: movl 4(ap),r0 # we're done - return s1 ! 57: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.