The LD (load) Instruction

Alright, so we have our registers to hold data for us. How do we put the data in there? We use the LD instruction. If you've ever programmed in C or Java, then it can be thought of as equivalent to the variable = number assignment.

The 8-bit LD Instruction
So here's an example where we want to load the number 12 into our 8-bit A register: ld a, 12    ;now A holds the value 12 Simple as that. We can also load one register into another one: ld a, 8    ;load 8 into A ld h, a     ;load A into H (now H also holds 8)

16-Bit LD Instruction
We can also load larger values into a 16-bit register in the same way: ld hl, 4812	;load 4812 into HL Unfortunately, we can’t directly load one 16-bit register into another. Instead, we must separate them into their 8-bit parts and do two separate loads like this: ld hl, 3141    ;load 3141 into HL ld d, h         ;load H into D ld e, l         ;load L into E (now DE = HL) Another example, using IX: ld ix, 1280 ld h, ixh ld l, ixl The table below shows which combinations are possible: (TBC)