		ASSEMBLY LANGUAGE - WEEK II					November 2, 1986



THE DATA MOVEMENT INSTRUCTIONS


Data may be moved from any one register to any other register. Whenever any of these move instructions are executed, the data is copied from the source register to the destination register. The content of the source register remains unchanged when a move instruction is executed.

		Format: LD d,
s

Action: Load a destination register with the contents of the source register.

Any register may be used as source and destination.



Example
:

LD A,49		3E  49

LD B,A		47

LD D,C		51

LD E,D		5A

LD H,E		63

LD L,H		6C







When a data word is moved between the internal Z-80 registers, the source and destination of the data word must be specified. The same is true when a data word is moved between memory and the Z-80. However, there are 65,536 possible memory locations to or from which you can move data. This means that you must uniquely specify which memory location to or from which you wish the Z-80 to move data.


The 16-bit memory address must be stored in registers H and L. The H register is used to hold the high byte, or most-significant eight bits of address. Once these two address bytes have been loaded into register H and L, a single-byte instruction can be used to transfer a single eight-bit byte of data between the memory location specified by the address in the registers H and L, and the A, B, C, D, or E registers in the Z-80.





LD r,(HL)




	LD A,(HL)		7E

	LD B,(HL)		46

	LD C,(HL)		4E

	LD D,(HL)		56

	LD E,(HL)		5E





LD (HL),r




	LD (HL),A		77

	LD (HL),B		70

	LD (HL),C		71

	LD (HL),D		72

	LD (HL),E		73





How does one initially get data values into any of the Z-80's general-purpose registers? One of the methods for loading a data value into a register is to execute an instruction that contains a data byte. This is a two byte instruction set. Two-byte instructions require two consecutive memory locations for storage, where the first memory location is used to store the eight-bit op code for the instruction, and the second memory location is used to store the immediate data byte. The move-immediate instructions load the data byte contained in the second byte of the instruction into the specified register. Any of the Z-80's general-purpose registers can be loaded with an eight-bit data value by executing one of these instructions.




LD A,n		3E  n

LD B,n		06  n

LD C,n		0E  n

LD D,n		16  n

LD E,n		1E  n






Simple register pair instructions


There is also a three-byte instruction that can be used to load 16 bits of data (or address) into register pair HL.


When the load immediate instruction is executed, which of the data bytes is loaded into H, and which data byte is loaded into L? The second byte of the three-byte instruction is loaded into register L, and the third byte of the instruction is loaded into register H. 


There are also load immediate instructions that can be used to load 16-bit values into register pairs B and D. 


These load immediate instructions are all three bytes long. When the op codes for these instructions are stored in memory, the two data bytes must be stored in the next two consecutive memory locations, with the least significant byte first, and then the most significant byte.

 

LD HL,nn nn		21  nn nn
 

LD BC,nn	nn		01  nn
 nn
 LD DE,nn	nn   	11  nn nn

Review the directions in your manual for using DEBUG. Using DEBUG, you can enter the above exercises in memory and, using the I (Instruction Single Step) feature of debug, verify that the registers change values according to the instructions given. 

The Alphabetical list of instruction mnemonics from you EDASM manual give the hexadecimal op code values and is a valuable reference.
                    