Direct
References the given memory location which contains the wanted value.
// Adds value at memory location 12
ADD 12
Immediate
References the given value itself.
// Adds value 12
ADD 12
Note: limited in bit size due to mnemonic structure:
[
opcode,
memory addressing mode,
operand <-- cannot take full advantage of bit size
]
Indirect
References the given memory location which references a memory location which contains the wanted value.
// Adds value at memory location represented in memory location 12
// (12: 47 -> 47: 15) = 15
ADD 12
Why? Computer RAM registers only have a limited storage, this is much more constricting on 8-bit computers which only have 256-bits.
Indirect memory addressing allows referencing memory outside the given block.
If we could only ever use direct addressing, there would be no point putting any more physical memory into your machine beyond 4 bits, as we could not physically reference the memory locations beyond address 15 (1111).
Indexed
References the index register memory location with the given memory location as an offset, containing a set of continuous data in memory.
// Adds value at index memory location plus memory location 12
// (IR = 15 | (15 + 12 = 27): 74)
ADD 12
Example
Memory Location | Data |
---|---|
0 | LDC 0 |
1 | ADD 1 |
2 | ADD 2 |
3 | ADD 3 |
4 | ADD 5 |
5 | OUT |
6 | 1 |
7 | 2 |
8 | 3 |
9 | 4 |
10 | 5 |
Index register = 5