Z80 assembly: Index registers
Use IX or IY as a base address. A small signed offset selects a byte near that base.
IX and IY are 16-bit index registers. They hold base addresses. The signed displacement d is added to the base to find a memory address. A displacement from −128 to 127 fits in one byte.
LD IX,nn takes 14 T-states. LD r,(IX+d) and LD (IX+d),r each take 19. These forms do not change flags. The IY forms use the FD prefix instead of DD.
What happened
Program listing
| Address | Machine code | Label | Instruction | Comment |
|---|
IX points to 0118h. The program reads the byte at IX+1, writes a copy to 0119h, then reads the byte before IX with offset −1. IY points to 011Bh and reads from a second base address.
Registers and indexed memory
Flags
IX+d means “the address in IX, plus d.” FFh as a displacement is −1. The 16-bit address wraps at the edge of memory. This page ignores undocumented X and Y bits.
Data near IX and IY
Execution trace
| # | Address | Instruction | Result | T-states |
|---|
Indexed address or pointer in HL?
| Form | Address used | Bytes | Time |
|---|---|---|---|
| LD A,(HL) | HL directly | 1 | 7 T |
| LD A,(IX+d) | IX plus signed d | 3 | 19 T |
| LD A,(IY+d) | IY plus signed d | 3 | 19 T |
IX and IY make it easy to address fields inside a record. For example, IX+0 can hold a type and IX+1 can hold a length.
This lesson implements the documented immediate index load, indexed byte loads and stores, and INC IX. Other IX/IY instructions will be added in later lessons.
Mnemonic glossary
Program mnemonics and directives
| Name | Stands for | Meaning here |
|---|---|---|
| LD | Load | Reads or writes a byte using an index register and offset. |
| INC | Increment | Adds 1 to IX without changing flags. |
| ORG | Origin | Assembler directive. Sets the code address. |
| DB | Define Byte | Assembler directive. Places data bytes in memory. |
| HALT | Halt | Stops this lesson’s CPU. |