IndexRegister

Inputs

PinTypeDescription
Databus8Input value to load (8 bits)
ClockbitClock signal
WEbitWrite Enable: 1 = load Data into IX
IncbitIncrement: 1 = add 1 to current value

Outputs

PinTypeDescription
Qbus8Current value stored in the index register

How It Works

Think of a bookmark in a book: it marks the page you are currently reading. The index register IX is the same bookmark, only for memory: it holds the address of the RAM cell the program is touching right now. You can move the bookmark one page forward (Inc) or jump straight to a specific page (loading via WE and Data).

The key property is indirect addressing: a command takes its address not from itself but from IX. Example: LDX 16 puts 16 into IX; LDAX reads RAM[16] into the accumulator; INX moves the bookmark to 17; another LDAX now reads RAM[17]. The same piece of code can thus process an array of any length.

A nuance: Inc has priority over WE. If both signals are 1 on the same edge, the register increments by one and the Data load is ignored. That is why LDX and INX are never combined in a single tick.

Examples (clock sequence)

TickCommandWEIncIX after the edge
1LDX 161016 — bookmark at the array start
2INX0117 — moved to the next element
3LDAX0017 — unchanged, RAM[17] is read
4LDX 20010200 — a sharp jump to a new address

Tick 3 shows that indirect reads use the bookmark without moving it.

Usage

Level 21 "Pointers" introduces IX, and from then on (levels 21–29) no work with arrays goes without it: the snake's body queue, data buffers, table walks in Snake. The instructions LDX, INX, LDAX and STAX are the complete vocabulary for talking to the index register.

A concrete use is a loop over an array: LDX places the bookmark on the first element, in the loop body LDAX or STAX reads and writes data at address IX, INX advances the bookmark, and a conditional jump returns to the start until the last element is processed.

Build it yourself →

Related components

Related articles

Frequently Asked Questions

What is the index register for?

Indirect addressing: the address comes from the register instead of the instruction — that is how loops over arrays work.

How is IX different from the accumulator?

The accumulator holds the data being worked on, IX holds the address where that data lives. The LDAX command connects them: it reads into the accumulator whatever IX points to.

What happens if WE = 1 and Inc = 1 are applied together?

Only the increment fires: Inc has the higher priority, and the Data value is ignored.