MOVE <EA>,<EA> ^ ^ | | | +--- Source operand 2 and Destination +-------- Source operand 1 (Use MOVEA when destination is an address register !)
(An) where n = 0, 1, 2, 3, 4, 5, 6, or 7
MOVEA.L #1000,A0 (set up address register) MOVE.L (A0), D0 will move a long word from memory location 1000 into D0 On the other hand: ------------------ MOVEA.L #5678,A0 (set up address register) MOVE.L (A0), D0 will move a long word from memory location 5678 into D0So the address used by "MOVE.L (A0), D0" depends on the value of register A0 at the moment the CPU executes the instruction.
(1) Copy the value of an int variable i into register D0 i: DS.L 1 MOVEA.L #i,A0 MOVE (A0),D0 * Effect of these 2 instructions is to move the value * stored in the variable i into register D0 * Which is the same as: MOVE.L i,D0 <---- more efficient way to move i into D0 :-)
(2) Copy the value of the int array variable A[0] into register D0
MOVE.L #A,A0 * A0 "points" to the first elem of array A MOVE.L (A0),D0 * Moves the value in the first elem of array A to D0 |
MOVE.L #A,A0 * A0 "points" to the first elem of array A ADDA.L #4,A0 * NOW A0 "points" to the 2nd elem of array A MOVE.L (A0),D0 * Moves the value in the 2nd elem of array A to D0 |
MOVE.L #A,A0 * A0 "points" to the first elem of array A ADDA.L #8,A0 * NOW A0 "points" to the 3rd elem of array A MOVE.L (A0),D0 * Moves the value in the 3rd elem of array A to D0 |
How to run the program:
|
(5) Copy the value of a byte array variable A[i] into register D0 A: DS.B 10 A byte (tiny integers) array: byte A[10] i: DS.L 1 i contains an index into array A You need to understand that: The address of the variable A[i] is equal to: value of the symbolic name (label) A + i Program code: MOVEA.L #A,A0 A0 = base address of array A (start of the array A) MOVE.L i, D0 D0 = i ADDA.L D0,A0 A0 = base address of array A + i = address of array element A[i] MOVE.B (A0), D0 Get value of A[i] in D0 * Sum effect of all these instructions is to move the byte value * of array element A[i] into D0
(6) Copy the value of an int array variable A[i] into register D1 A: DS.L 10 An integer array: int A[10] i: DS.L 1 i contains an index into array A You need to understand that: The address of the variable A[i] is equal to: value of the symbolic name (label) A + 4×i (Because each array element occupies 4 bytes of memory. So you need to skip 4 bytes to get to the next array element) Program code: MOVEA.L #A,A0 A0 = base address of array A MOVE.L i, D0 D0 = i ADD.L D0,D0 D0 = i+i = 2*i ADD.L D0,D0 D0 = 2*i + 2*i = 4*i ADDA.L D0,A0 A0 = base address of array A + 4*i = address of array element A[i] MOVE.L (A0), D1 Get value of A[i] in D1 * Sum effect of all these instructions is to move the int (4 bytes) value * of array element A[i] into D1
How to run the program:
|
(7) Copy the value of a short array variable A[i] into register D0 A: DS.W 10 An array of short var: short A[10] i: DS.L 1 contains an index into array A MOVEA.L #A,A0 A0 = base address of array A MOVE.L i, D0 D0 = i ADD.L D0,D0 D0 = 2*i ADDA.L D0,A0 A0 = base address of array A + 2*i = address of array element A[i] (because shorts are 2 bytes) MOVE.W (A0), D0 Get value of A[i] in D0 * Sum effect of all these instructions is to move the short (2 bytes) value * of array element A[i] into D1