memcpy

Purpose: Copy a block of data from one SRAM memory location to another SRAM location. This subroutine determines the "direction" to copy, so overlapping data ranges are handled correctly (i.e., so characters are not overwritten and lost while copying.)
Assumes:  bPtrTo and bPtrFrom are valid.
Passed:     R25:R24  BYTE *   bPtrTo the SRAM destination address
R23:R22  BYTE *   bPtrFrom the SRAM source address
R21:R20  WORD wCount number of BYTEs to copy
Returns: R25:R24  BYTE *   bPtrStart the caller's bPtrTo value (unmodified)
Alters: The memory block referenced and the FLAGs
Example:  Sometimes it is desired to make some room in a buffer in order to modify a command before passing it to the CommandParser() routine.
MakeRoomInBuffer:
   MOVW    R24, R26         ; Parsing buffer pointer received in 'X'
   ADIW    R24, 1           ; Set bPtrFrom to the BYTE after the count
   MOVW    R22, R24         ; Set bPtrTo to the location which is 3 BYTEs
   ADIW    R24, 3           ;  higher in memory than bPtrFrom
   LDI     R21, 0           ; Set the MSByte of the copy count
   LD      R20, Z           ; Get the command's buffered BYTE count
   SUBI    R20, -3          ; Adjust it by adding 3 (by subtracting -3)
   ST      Z, R20           ; Set the parsing buffer's new count
   CALL    Amemcpy          ; Call to insert 3 BYTEs into the buffer
;       ...                 ; More to do, before CommandParser gets it
Notes: The bPtrTo and bPtrFrom values are not checked for validity.
The wCount value is limited to 2,047 (= 0x7FF) BYTEs.
If wCount is zero, it exits immediately with no SRAM change.
Dropin: 
(setup
code)
;   Setup for the memcpy() call:
; Passed:  R25:R24 BYTE * bPtrTo   pointer to the SRAM destination buffer
;          R23:R22 BYTE * bPtrFrom pointer to the SRAM source buffer
;          R21:R20 WORD   wCount   number of BYTEs to copy
; Returns: R25:R24 BYTE * the caller's bPtrTo value (unmodified)
; Alters:  The memory block referenced and the FLAGSs
Also see:  The strcpy, meminit, and memcpyEEPROM System Functions and the EIS (in Edit) System Command.