← 🧩 Instruction Formats & Addressing Modes
Subtopic 3 of 8

1.3Expanding opcode

The idea

Expanding opcode reuses patterns of a long opcode as an "escape": leftover patterns mean "look at more bits" and encode shorter-format instructions.

Think of it like this: Like telephone numbers: most numbers start with a normal code, but a reserved prefix means "keep dialling, a longer number follows".

Why it exists

A fixed instruction length would waste bits on instructions that need few operands. Expanding the opcode packs more instruction types into the same word.

How it works

  1. Start with the opcode bits of the largest format (2-address). It has 2op patterns.
  2. Give some patterns to real 2-address instructions. The unused ones become escapes.
  3. Each escape pattern is followed by an extra opcode field taken from freed operand bits: multiply leftover by 2a.
  4. Repeat for the 0-address level.

Worked example: 8-bit opcode, 4-bit address fields

Use 14 of 256 patterns for 2-address instructions. Leftover 242 × 16 = 3872 possible 1-address instructions. If you use 30 of those, (3872 − 30) × 16 = 61,472 zero-address instructions are still possible.

Now play with it

  • →Change "2-address used" to 250 and watch the 1-address capacity collapse to 96.
  • →Click through the bit diagrams to see where the extra opcode bits come from.
Opcode bits of 2-address format8
Total 2-address patterns256
Max 1-address instrs3872
Max 0-address instrs61472

Max 1-addr = (2^op − x)·2^a. Max 0-addr = (that − y)·2^a. Opcode bits assumed to be L − 2a.

Total 16 bits. Click a field for details.

Uses most of the 8-bit opcode space, but keeps some patterns unused.

Check yourself

8-bit opcode, 4-bit address fields. 250 patterns are used by 2-address instructions. Max number of 1-address instructions?

Remember: Leftover patterns × 2address bits at every level.
Exam notes (the dense version)

Unused opcode patterns of a longer-address format are 'borrowed' to encode shorter-address instructions. Each level multiplies leftover patterns by 2field width.

Previous year questions: Instruction Formats & Addressing Modes (12)

PYQs are grouped by topic, so this is the full set for Instruction Formats & Addressing Modes; try the ones that match this subtopic. Open all 12 on the topic page.