MOVE - Move a block of memory to another

Language reference ›› Built-in procedures ›› Miscellaneous ››
Parent Previous Next

MOVE(source, destination [, size] )

Raw untyped move of bytes from one variable to another variable for the optional given size in bytes.

If <size> is not specified, the number of moved bytes is the smallest size of <source> and <destination>.

If the given <size> is greater than <source> or <destination> size, an error is produced.

This procedure cannot move outside of <source> or <destination> if <size> is constant (compile time check); if <size> is not constant, no check is made.

<source> and <destination> may be indexed. The indexed element will be the first element to be used. If one is indexed, <size> must be specified.

<source> and <destination> may be RAM or EEPROM.

<source> may be a constant array.

Restrictions: In the current implementation, only RAM arrays may be indexed by a dynamic index, all other types may be indexed by a constant index only.

WARNING:        In a common case the compiler generates inline code to move small amount of bytes. Nevertheless, if dynamic indexes are used or if the byte size is more than 6-8 bytes (depending on the processor and optimization mode), the compiler generates code to deal with area overlapping to generate a backwards or forwards move. As this code may be quite heavy, it may be more effective to move bytes by a loop where behavior is well determined.

 T1: ARRAY[5] OF BYTE;  // RAM array
 T2: ARRAY[10] OF BYTE; // RAM array

 MOVE(T1, T2); // This is equivalent to T2[0..4] := T1;
 MOVE(T2, T1); // This is equivalent to T1 := T2[0..4];
 MOVE(T1[2], T1[0], 3); // No overlapping: This is equivalent to T1[0] := T1[2]; T1[1] := T1[3]; T1[2] := T1[4];
 MOVE(T1[0], T1[2], 3); // Static overlapping: This is equivalent to T1[4] := T1[2]; T1[3] := T1[1]; T1[2] := T1[0];
 MOVE(T1[0], T1[2], N); // Generates code for runtime overlapping control