On Sun, 7 Sep 1997 Octavio Nogueira wrote: > I need a routine to pass one variable to another, example Var1 to Var2 or > Var3 to Var1, etc in any combination. Octavio, My solution probably won't be usefull to you. It is incredibly slow. I was treating this more as the puzzle, "how can I copy a 4 byte block, without destroying any RAM?" rather than trying to actually give you a usefull answer. Please don't be offended. You can do much, much better if you use one or two bytes of RAM. > I did one routine but it takes 38 ROM spaces and 3 RAM, does anyone > have a better idea? Using the xorwf trick pointed by Mike Keitz , I can exchange 2 4 byte blocks in 22 ROM words, 0 RAM, but I use 3 levels of calls. It also takes 186 cycles. For a rather dismal 46.5 cycles per byte copied. Umm, and status is toasted too. ; swap4 swaps a couple 4 byte regions of memory. To swap 4 byte var1 ; with 4 byte var2, put the address of var1 in FSR, and var2-var1 in ; W, and call swap4. ; This temporarily uses one word of ram, but restores it. ; 5 words, 186 cycles (22 words including routines it calls) swap4 call swap1 call swap1 call swap1 call swap1 return ; swap the memory byte pointed to by FSR with the one at FSR+w ; 7 words, 44 cycles, (not counting the call) ; (17 words, including the routing it calls) ; This temporarily uses one word of ram, but restores it. swap1 call tmpexch ; tmp = *region1, *region1 = tmp addwf FSR,f ; FSR = region2 call tmpexch ; *region2 = *region1, tmp = *region2 subwf FSR,f ; FSR = region1 (restore FSR) call tmpexch ; *region1 = *region2, tmp restored incf FSR,f; FSR = region1++ Ready for the next byte return ; Exchange a temporary location with the indf, leaving W unchanged. ; 10 words, 11 cycles (plus 2 for the call) tmpexch xorwf tmpf,w ; these 3 instructions exchange W and tmpf xorwf tmpf,f ; xorwf tmpf,w ; Now w = tmpf, tmpf = w xorwf indf,w ; these 3 exchange indf and W xorwf indf,f ; xorwf indf,w ; Now w = indf, indf = tmpf xorwf tmpf,w ; hmm, these 3 instructions are a repeat xorwf tmpf,f ; Make them a routine, and save a word xorwf tmpf,w ; Now tmpf = indf, indf = tmpf, w unchanged return I'm subscribed to the digest version, so I haven't yet seen the last 23 hours of postings, my apologies if this comes after a better solution. -- paulh@hamjudo.com http://www.hamjudo.com The April 97 WebSight magazine describes me as "(presumably) normal".