|
|
1.1 ! root 1: .file "strncat.s" ! 2: # @(#)strncat.s 1.6 ! 3: # 3.0 SID # 1.2 ! 4: # Fast assembler language version of the following C-program ! 5: # strncat ! 6: # which represents the `standard' for the C-library. ! 7: ! 8: # Concatenate s2 on the end of s1. S1's space must be large enough. ! 9: # At most n characters are moved. Return (null terminated) s1. ! 10: ! 11: # char * ! 12: # strncat(s1, s2, n) ! 13: # register char *s1, *s2; ! 14: # register n; ! 15: # { ! 16: # register char *os1; ! 17: # ! 18: # os1 = s1; ! 19: # while(*s1++) ! 20: # ; ! 21: # --s1; ! 22: # while(*s1++ = *s2++) ! 23: # if(--n < 0) { ! 24: # *--s1 = '\0'; ! 25: # break; ! 26: # } ! 27: # return(os1); ! 28: # } ! 29: .globl _strncat ! 30: .text ! 31: .align 2 ! 32: _strncat: ! 33: .word 0x03c0 # uses regs. 0,1,2,3,4,5,6,7,8,9 ! 34: movq 4(ap),r6 # dest in r6, src in r7 ! 35: movl 12(ap),r8 # max src length (arg `n') ! 36: bleq L6 # done if <= 0 ! 37: movl r6,r1 # working copy of dest ! 38: L0: ! 39: locc $0,$65535,(r1) # gotta find the end of dest ! 40: beql L0 # BIG string, go around again ! 41: movl r1,r3 # found the null to cat onto ! 42: L1: ! 43: subl3 $65535,r8,r9 # may have to take it in chunks ! 44: blss L2 # skip if `n' < 65535 ! 45: movl $65535,r8 # else use 65535 as `chunk' length ! 46: L2: ! 47: locc $0,r8,(r7) # see if there's a null in src ! 48: bneq L3 # found null, go move string & quit ! 49: movc3 r8,(r7),(r3) # else move a `chunk' of data ! 50: tstl r9 # ask if `n' is bigger than 65535 ! 51: bleq L5 # skip to finish if `n' was small ! 52: movl r9,r8 # else reduce `n' by 65535, ! 53: movl r1,r7 # update source ptr, ! 54: jmp L1 # and go again ! 55: L3: ! 56: subl3 r7,r1,r5 # calculate length of piece to move ! 57: cmpl r8,r5 # is `n' <= length of src? ! 58: bleq L4 # YES, then hop onward and use `n' ! 59: movl r5,r8 # NO, then use length ! 60: L4: ! 61: movc3 r8,(r7),(r3) # and then move it ! 62: L5: ! 63: movb $0,(r3) # stick in the terminating null ! 64: L6: ! 65: movl r6,r0 # return pointer to dest ! 66: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.