Code: Select all
PROCEDURE* MoveWords*(fromAdr, toAdr, nBytes: INTEGER);
VAR
word, lastAdr: INTEGER;
BEGIN
lastAdr := fromAdr + nBytes;
REPEAT
SYSTEM.GET(fromAdr, word, 4);
SYSTEM.PUT(toAdr, word, 4);
UNTIL fromAdr = lastAdr
END MoveWords;
PROCEDURE* MoveBytes*(fromAdr, toAdr, nBytes: INTEGER);
VAR
byte: BYTE;
lastAdr: INTEGER;
BEGIN
lastAdr := fromAdr + nBytes;
REPEAT
SYSTEM.GET(fromAdr, byte, 1);
SYSTEM.PUT(toAdr, byte, 1);
UNTIL fromAdr = lastAdr
END MoveBytes;
PROCEDURE Move*(fromAdr, toAdr, nBytes: INTEGER);
VAR
nBytes4, nBytes1: INTEGER;
BEGIN
nBytes1 := nBytes MOD 4;
nBytes4 := nBytes - nBytes1;
IF nBytes4 > 0 THEN
MoveWords(fromAdr, toAdr, nBytes4);
END;
IF nBytes1 > 0 THEN
MoveBytes(fromAdr + nBytes4, toAdr + nBytes4, nBytes1);
END
END Move;
An example of their use is a function to shift all the bytes in an array by one position. The normal way to do this would be something like:
Code: Select all
PROCEDURE* ShiftArray(VAR a: ARRAY OF BYTE);
VAR
i: INTEGER;
BEGIN
FOR i := 1 TO LEN(a) - 1 DO a[i-1] := a[i] END
END ShiftArray;
Code: Select all
PROCEDURE ShiftArray(VAR a: ARRAY OF BYTE);
BEGIN
Move(SYSTEM.ADR(a[1]), SYSTEM.ADR(a[0]), LEN(a) - 1)
END ShiftArray;