CSC 382 · Computer Architecture 1
Our notes
2 min readInstruction fields
An instruction holds an opcode (what to do) and operand fields (where the data is). Others may give the addressing mode or a register number.
Example: 16-bit instructions with a 4-bit opcode and a 12-bit address allow 2⁴ = 16 operations and 2¹² = 4,096 directly addressable words.
Number of addresses
Computing X = (A + B) × C:
- Three-address: ADD T, A, B; MUL X, T, C.
- Two-address: MOV T, A; ADD T, B; MUL T, C; MOV X, T.
- One-address (accumulator): LOAD A; ADD B; MUL C; STORE X.
- Zero-address (stack): PUSH A; PUSH B; ADD; PUSH C; MUL; POP X.
Fewer addresses make shorter instructions but more of them.
Addressing modes
| Mode | Operand is | Example |
|---|---|---|
| Immediate | in the instruction | LOAD #5 → AC = 5 |
| Direct | at the address given | LOAD 500 → AC = M[500] |
| Indirect | at the address stored at the address | LOAD @500 → AC = M[M[500]] |
| Register | in a register | ADD R2 |
| Register indirect | at the address in a register | LOAD (R1) |
| Indexed | at address + index register | LOAD 500(X) → M[500 + X] |
| Relative | at PC + offset | JUMP +12 |
| Base | at base register + offset | used for relocatable programs |
Worked example
Memory: M[500] = 800, M[800] = 300, M[600] = 900. Index register X = 100. The instruction LOAD with address field 500:
- Immediate: AC = 500.
- Direct: AC = M[500] = 800.
- Indirect: AC = M[M[500]] = M[800] = 300.
- Indexed: AC = M[500 + 100] = M[600] = 900.
Effective address
The effective address (EA) is the actual memory address used after applying the mode. Indirect addressing needs one extra memory access; immediate needs none.
Uses
- Immediate: constants.
- Direct: simple variables.
- Indirect and register indirect: pointers.
- Indexed: arrays (the index register steps through the elements).
- Relative: branches, so code can be moved anywhere (position-independent code).
Exams usually ask
- Describe instruction formats and compare 0-, 1-, 2- and 3-address machines.
- Explain the addressing modes with examples.
- Compute effective addresses and operand values for a given memory state.
Common mistake
Confusing indirect with indexed. Indirect follows a pointer stored in memory; indexed adds a register to the address.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.