Z80 assembly: Loading data
Load one byte from memory, move it through registers, and write it to a new address.
LD means Load. It copies a value. These forms do not change flags. LD r,n takes 7 T-states. LD r,r′ takes 4. The two memory forms take 7.
What happened
Program listing
| Address | Machine code | Label | Instruction | Comment |
|---|
The source byte starts at 010Dh, immediately after the 13-byte code block. The program copies it to 010Eh. The highlighted instruction is at PC.
Registers, flags and memory
Flags
A register stores a small value inside the CPU. HL is a register pair. The value in HL is a memory address. PC means Program Counter. A T-state is one CPU clock period. This page ignores undocumented X and Y bits.
Source HL points here
Destination HL points here before writing
Execution trace
| # | Address | Instruction | Result | T-states |
|---|
Another way to copy one byte
; direct transfer through DE LD HL,source LD DE,dest LD A,(HL) LD (DE),A HALT
| Program | Code size | Time |
|---|---|---|
| This lesson’s register path | 13 bytes | 53 T-states |
| Direct transfer through DE | 9 bytes | 38 T-states |
Both examples include address setup and HALT. The direct path needs DE, an extra register pair for the destination address.
Simplification: memory is a flat 64 KB array. Interrupts and input/output devices are not modeled.
Mnemonic glossary
Program mnemonics and directives
| Name | Stands for | What it does here |
|---|---|---|
| LD | Load | Copies a value into a register or memory. |
| HALT | Halt | Stops this lesson’s CPU. Interrupts are not modeled. |
| ORG | Origin | Assembler directive, not a CPU instruction. Sets the code address. |
| DB | Define Byte | Assembler directive, not a CPU instruction. Places the source byte in memory. |
| DS | Define Space | Assembler directive, not a CPU instruction. Reserves the destination byte. |