Memory, in hex. The shaded slot is the drawer on the bus.
LOAD brings a value into the accumulator, A. The instruction has to say where that value is. It carries one 16 bit field, and the addressing mode says how to read the field: as the value, as the address of the value, or as the address of the address. Fig 1 runs the same LOAD in each mode. The field is 2000 every time, and A ends up holding 2000, 2003 or 7B10.
Every drawer has a number, its address. In this machine an address is 16 bits, so there are 216 = 65,536 drawers. In hex that is 0000 to FFFF, four digits of four bits each. Fig 1 shows eight of them, 2000 to 2007. The address bus has 16 wires, one per bit, and if each drawer held one byte the machine could reach 64 KiB.
A word is also 16 bits, so a drawer can hold an address. Drawer 2000 holds 2003. Whether that is a number or an address depends only on how the CPU reads it. Indirect mode reads it as an address.
An instruction takes two words. The first says what to do and how to read the field. The second is the field.
| Word | Bits | Holds |
|---|---|---|
| 1 | 15 to 8 | Opcode: LOAD, ADD, STORE and so on |
| 1 | 7 to 6 | Mode: 00 immediate, 01 direct, 10 indirect |
| 2 | 15 to 0 | The field: a 16 bit value or address |
In assembly the mode is written around the field. The three forms of the LOAD in Fig 1:
| Mode | Written | The field is | A gets | Memory reads |
|---|---|---|---|---|
| Immediate | LOAD #2000 | the value | 2000 | 0 |
| Direct | LOAD 2000 | the address of the value | M[2000] = 2003 | 1 |
| Indirect | LOAD (2000) | the address of the address | M[M[2000]] = M[2003] = 7B10 | 2 |
M[x] means the word in drawer x. Some books write indirect as @2000 or [2000].
The value is inside the instruction, so the execute phase is one transfer:
Nothing goes out on the address bus. Use immediate mode for a constant the program knows when it is written: add 1, load 0, compare with 10.
The field is where the value lives. The CPU reads that drawer once:
This is the LOAD from the fetch-execute article, with a 16 bit address instead of a 3 bit one. Use direct mode for a variable kept at a fixed address.
The field points to a drawer that holds the real address. The CPU reads twice:
The middle transfer, MAR ← MDR, is the whole difference: the word that came back is sent out again as an address. Use indirect mode when the address itself changes while the program runs. A program that walks through a list keeps the current item's address in one drawer. The same LOAD (2000) then fetches a different item each time round, because the program changes the word in 2000 between rounds.
Count the memory reads: immediate 0, direct 1, indirect 2. Each read is one trip out on the address bus and back on the data bus, so an indirect LOAD takes about twice as long as a direct one. That is the price of an address that can change.
LOAD #2007, LOAD 2007 and LOAD (2007)?