Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: String copy idiom. Message-ID: <4085@umcp-cs.UUCP> Date: Sat, 16-Mar-85 00:21:04 EST Article-I.D.: umcp-cs.4085 Posted: Sat Mar 16 00:21:04 1985 Date-Received: Sun, 17-Mar-85 02:37:46 EST References: <2040@sun.uucp> <55@decvax.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 39 > Note the following VMS Macro code from a routine in the Decus C library. > .entry strcpy,^M > movl 8(ap),r2 ; source string > locc #0,#-1,(r2) ; find null at end of source > subl2 r2,r1 ; length of source > incl r1 ; plus 1 for the null byte > movc3 r1,@8(ap),@4(ap); copy the string > movl 4(ap),r0 ; r0 -> destination > .end Unfortunately, this fails for strings longer than 65535 characters. This can be corrected by looping over the locc and movc3 instructions until the final 64K segment is reached (I believe locc sets the condition codes depending on whether it found the character or not). Here's a stab at it (without referring to the "black book" so I don't know if I've got things right): _strcpy:.globl _strcpy .word 0x0 movl 8(ap),r3 # source => r3 movl 4(ap),r5 # dest => r5 (movc3 requires this arrangement) brb 1f # go count up length 0: movc3 $65534,(r3),(r5)# copy current 64K segment 1: locc $0,$65534,(r3) # find null bne 0b # if not found, copy next 64K seg subl2 r3,r1 # r1 = len incl r1 # +1 for null, without overflow (65534+1 max) movc3 r1,(r3),(r5) # move final chunk movl 4(ap),r0 # dest => r0 as return val ret (I'm not sure if movc3'ing 65532 bytes would be better, so as to stay longword aligned when the arguments were originally....) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland