UNIHIVE

Study Hub UNIPORT CSC 382

CSC 382 · Computer Architecture 1

Instruction formats and addressing modes

The fields of an instruction, zero- to three-address formats, and the main addressing modes with worked examples.

Our notes

2 min read

Instruction 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

ModeOperand isExample
Immediatein the instructionLOAD #5 → AC = 5
Directat the address givenLOAD 500 → AC = M[500]
Indirectat the address stored at the addressLOAD @500 → AC = M[M[500]]
Registerin a registerADD R2
Register indirectat the address in a registerLOAD (R1)
Indexedat address + index registerLOAD 500(X) → M[500 + X]
Relativeat PC + offsetJUMP +12
Baseat base register + offsetused 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.

All CSC 382 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.