memcpyEEPROMtoEEPROM

Purpose: Copy a block of data from EEPROM to EEPROM, with attention to overlapped copying.
Assumes:  bPtrTo and bPtrFrom are valid.
Passed:     R25:R24  BYTE *   bPtrTo the EEPROM destination address
R23:R22  BYTE *   bPtrFrom the EEPROM source address
R21:R20  WORD wCount number of BYTEs to copy
Returns: R25:R24  BYTE *   bPtrStart the caller's bPtrTo value (unmodified)
Alters: The FLAGs and the memory block referenced.
Example: 
Source = 0x1D0
Target = 0x1E0
Count  = 50

EEtoEECopyTest:
   LDI     R23, Source >> 8
   LDI     R22, Source & 0xFF     ; R23:R22 = source address
   LDI     R25, Target >> 8
   LDI     R24, Target & 0xFF     ; R25:R24 = target address
   LDI     R21, Count >> 8
   LDI     R20, Count & 0xFF      ; R21:R20 = number of bytes to copy
   CALL    AmemcpyEEPROMtoEEPROM
   RET
Test it: Note that the range above is 50 BYTEs, starting at 0x1D0, so the last BYTE is at 0x1D0 + 0x32 = 0x202. They are being copied to 0x1E0, with the last BYTE at 0x212. To see the order of the BYTEs as they are changed, use the "#" key to enable EEPROM change reporting.
m>:1010000071E060ED91E080EE50E042E30E942A3012
m>:02101000089541
m>:00000001FF
m>; Initialize the 80 BYTEs in EEPROM (Edit LONGs, LSB first):
m>EL 0x1D0 = 0xD3D2D1D0 0xd7d6d5d4 0xdbdad9d8 0xdfdedddc
m>EL 0x1E0 = 0xe3e2e1e0 0xE7E6D5E4 0xebeae9e8 0xefeeedec
m>EL 0x1F0 = 0xf3f2f1f0 0xf7f6f5f4 0xFBFAF9F8 0xfffefdfc
m>EL 0x200 = 0x03020100 0x07060504 0x0b0a0908 0x0F0E0D0C
m>EL 0x210 = 0x13121110 0x17161514 0x1b1a1918 0x1f1e1d1c
m>D+e 0x1d0 80
EEPROM contents:
01D0:  D0 D1 D2 D3 D4 D5 D6 D7-D8 D9 DA DB DC DD DE DF  ................
01E0:  E0 E1 E2 E3 E4 D5 E6 E7-E8 E9 EA EB EC ED EE EF  ................
01F0:  F0 F1 F2 F3 F4 F5 F6 F7-F8 F9 FA FB FC FD FE FF  ................
0200:  00 01 02 03 04 05 06 07-08 09 0A 0B 0C 0D 0E 0F  ................
0210:  10 11 12 13 14 15 16 17-18 19 1A 1B 1C 1D 1E 1F  ................
m>e 0x1E0 = "This is the 32 BYTE test block."
m>de+ 0x1D0 0x50   ; Display the initial data range:
EEPROM contents:
01D0:  D0 D1 D2 D3 D4 D5 D6 D7-D8 D9 DA DB DC DD DE DF  ................
01E0:  54 68 69 73 20 69 73 20-74 68 65 20 33 32 20 42  This is the 32 B
01F0:  59 54 45 20 74 65 73 74-20 62 6C 6F 63 6B 2E 00  YTE test block..
0200:  00 01 02 03 04 05 06 07-08 09 0A 0B 0C 0D 0E 0F  ................
0210:  10 11 12 13 14 15 16 17-18 19 1A 1B 1C 1D 1E 1F  ................
m>@ 0x1000       ; Execute the EEtoEECopyTest routine:
m>D+E 0x1D0  80  ; Copy 50 BYTEs starting at 0x1D0 to 0x1E0:
EEPROM contents:
01D0:  D0 D1 D2 D3 D4 D5 D6 D7-D8 D9 DA DB DC DD DE DF  ................
01E0:  D0 D1 D2 D3 D4 D5 D6 D7-D8 D9 DA DB DC DD DE DF  ................
01F0:  54 68 69 73 20 69 73 20-74 68 65 20 33 32 20 42  This is the 32 B
0200:  59 54 45 20 74 65 73 74-20 62 6C 6F 63 6B 2E 00  YTE test block..
0210:  00 01 12 13 14 15 16 17-18 19 1A 1B 1C 1D 1E 1F  ................
m>; The first (0x1E0) and last (0x1E0 + 0x32 = 0x212) BYTEs are highlighted
m>                                                                              
Notes: This System Function determines to the copy "direction", so overlapping ranges are handled correctly, i.e., so they are not overwritten and lost before being copied.
The bPtrTo and bPtrFrom values are not checked for validity.
The wCount value is limited to 1,023 (= 0x7FF) BYTEs.
If wCount is zero, it exits immediately with no EEPROM change.
Dropin: 
(setup
code)
;   Setup for the memcpyEEPROMtoEEPROM() call:
; Passed:  R25:R24 BYTE * bPtrTo   pointer to the EEPROM destination
;          R23:R22 BYTE * bPtrFrom pointer to the EEPROM source buffer
;          R21:R20 WORD   wCount   number of BYTEs to copy
; Returns: R25:R24 BYTE * bPtrTo   the caller's bPtrTo value (unmodified)
; Alters:  The FLAGs and the memory block referenced
Also see:  The memcpyEEPROM, memcpySRAMtoEEPROM, and memcpy System Functions and the ECE (in Edit) System Command.