paulba (03/31/83)
: <CMOVE
( Copy n bytes starting at addr1 to addr2. The move )
( proceeds from high memory to low memory. )
( addr1 addr1 n --- )
DUP ROT + ( Calculate addr2 + n )
SWAP ROT ( and put it on bottom of stack )
1 - ( DO-LOOP end = addr1 - 1 )
DUP ROT + ( DO-LOOP start = addr1 + N - 1 )
DO
1 - ( Decrement last string 2 address )
I C@ ( Fetch next byte from string 1 )
OVER C! ( and copy it to string 2 )
-1 ( Decrement index )
+LOOP
DROP ; ( Discard the string 2 address )
: CMOVE$
( Copy n bytes starting at addr1 to addr2. If addr2 )
( is forward of addr1, the move proceeds from high )
( memory to low memory; otherwise the move proceeds )
( from low memory to high memory. )
OVER 4 PICK ( Copy addr2 addr1 on top of stack )
> ( Copying to a higher address? )
IF <CMOVE ( if so, use <CMOVE )
ELSE CMOVE ( if not, use CMOVE )
THEN ;
( if you don't have PICK ... )
: PICK
2 * SP@ + @ ; ( without comments )
( these were taken ( except PICK ) from a book by LEO J. SCANLON )
( a HOWARD SAMS book ISBN 0-672-22007-5 $16.95 suggested price.)