Skip to content
BetterDL

Instruction format

Also called: instruction layout, instruction word format

How an instruction's bits are divided into fields, such as an opcode saying what to do and an address saying which data to use.

An instruction format is the layout of an instruction word: which bits form which field. The CPU's decoder relies on it to pull each instruction apart.

Tiny8 has one format, 8 bits wide:

  • bits 7–4: the opcode, what to do;
  • bits 3–0: the address field, which memory word to use, or where to jump.

So every Tiny8 instruction is exactly two hex digits: opcode, then address. ADD E is 3E.

Sizing a format uses one fact: n bits give 2ⁿ patterns.

  • Opcode bits for k instructions: the smallest n with 2ⁿ ≥ k. Round up.
  • Address bits for N words: the smallest n with 2ⁿ ≥ N.
  • The instruction width is the sum of its fields.

Other machines have several formats, with fields for registers or constants. A three-register format might be opcode | Rd | Rs | Rt, where each register field needs enough bits to name every register in the register file.

0
128
1
64
0
32
0
16
1
8
0
4
0
2
1
1

Worked examples

Example

Sizing a one-address format

A machine has 40 instructions and 512 words of memory. Each instruction is an opcode plus one address.

  1. 1.

    Opcode: 2⁵ = 32 is too few; 2⁶ = 64 is enough. 6 bits.

  2. 2.

    Address: 2⁹ = 512. 9 bits.

  3. 3.

    Instruction width: 6 + 9 = 15 bits.

Example

Reading a Tiny8 word

The word above is 0100 1001.

  1. 1.

    Opcode field 0100 = 4 = SUB.

  2. 2.

    Address field 1001 = 9.

  3. 3.

    So it's SUB 9, written 49 in hex.

Common mistakes

  • Rounding down. 40 instructions need 6 opcode bits, because 5 bits give only 32 codes.

  • Swapping the fields. In Tiny8 the opcode is the left hex digit.

  • Answering with a bit count when asked how many addresses a field can name, or the reverse.

Practice Instruction format

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Instruction format is taught in Basic CPU / Computer Architecture.