← r0mheat z80 lessons: all projects

Z80 assembly: Index registers

Use IX or IY as a base address. A small signed offset selects a byte near that base.

IX · IY · (IX+d)

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.

Run speed

What happened

Program listing

AddressMachine codeLabelInstructionComment

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

#AddressInstructionResultT-states

Indexed address or pointer in HL?

FormAddress usedBytesTime
LD A,(HL)HL directly17 T
LD A,(IX+d)IX plus signed d319 T
LD A,(IY+d)IY plus signed d319 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
NameStands forMeaning here
LDLoadReads or writes a byte using an index register and offset.
INCIncrementAdds 1 to IX without changing flags.
ORGOriginAssembler directive. Sets the code address.
DBDefine ByteAssembler directive. Places data bytes in memory.
HALTHaltStops this lesson’s CPU.