Instructions: Formats, Types and Instruction Sets

The fetch–decode–execute cycle in The Processor: CPU Components and the Fetch-Decode-Execute Cycle treats an instruction as a number in the IR, with an opcode and maybe an address. In this lesson you will look more carefully at that number: how many addresses an instruction can name (zero-, one-, two- and three-address formats), whether every instruction is the same length (fixed or variable length), the three types of instruction in the syllabus (data manipulation, control, input/output), and what an instruction set is. A short C program will decode a packed instruction word the way the control unit does.

What you will learn

  • How the same calculation, X = A + B, is written in four address formats, and what is implied in each one.
  • The trade-off between instruction size and the number of instructions needed.
  • Fixed-length versus variable-length instructions, and how that affects the PC.
  • How to classify an instruction as data manipulation, control, or input/output.
  • What an instruction set is, and how a C program can split an opcode from an address.

Part 1: How many addresses?

An instruction format is the layout of the bits in the IR: which bits are the opcode, and which bits (if any) are addresses or immediate values. CAPE classifies formats by how many addresses the instruction names.

Take the assignment X = A + B, and compare the four common formats. In every case the computer still has to get A and B and write X; what changes is how much of that is implied by the machine, and how many instructions you have to write.

FormatTypical instruction(s) for X = A + BWhat is implied
Three-addressADD X, A, BNothing: destination and both sources are named.
Two-addressMOV X, A then ADD X, BOne field is both a source and the destination, so X is overwritten.
One-addressLOAD A, ADD B, STORE XThe accumulator holds one operand and the result.
Zero-address (stack)PUSH A, PUSH B, ADD, POP XThe ALU takes its operands from the top of a stack.

Three-address instructions are easy to write but need a wide word (three address fields plus an opcode). Zero-address instructions are very short, but you need more of them and a stack. One-address is the format used in lesson 14, and it is a common CAPE example: a LOAD / ADD / STORE sequence on a single accumulator. Two-address is what you will see in many older CISC discussions: one operand is overwritten.

Try it 1Four ways to write X = A + B

Tap a format. The instructions that carry out the same addition change, and so does what the machine implies.


Part 2: Fixed length and variable length

In a fixed-length format every instruction occupies the same number of bits (for example 16 or 32). Fetch is simple: after reading one instruction the PC is always increased by the same amount. Many RISC sets are fixed length. In a variable-length format, short instructions (a HALT, or an ADD that uses only registers) can use fewer bytes than a long one (an instruction with a 32-bit address). Programs can be more compact, but the fetch stage must work out the length before it can update the PC, and instructions may straddle word boundaries. CAPE expects you to name both styles and give one advantage of each.

Part 3: Types of instruction, and the instruction set

The syllabus groups instructions into three types:

  • Data manipulation. The instruction changes or moves a data value: arithmetic and logic (ADD, SUB, AND, NOT), and data movement (LOAD, STORE, MOVE, PUSH, POP).
  • Control. The instruction changes what will be fetched next, or whether the machine keeps running: jumps and branches (JMP, JZ), calls and returns, and HALT.
  • Input/output. The instruction transfers a value between the CPU (or memory) and a device: IN, OUT, and similar names.

An instruction set is the complete list of instructions that a particular CPU can execute, together with their opcodes, formats and effects. Two processors with different instruction sets cannot run each other’s machine code. A compiler’s job, for a language like C, is to translate your program into this set. When a question asks you to say what a CPU’s instruction set is, that definition is what is wanted; when it asks for two types, pick from the three groups above and give an example of each.

Try it 2Type this instruction

Read the instruction and tap its type. Then try the next one. All eight examples appear in this lesson.

Part 4: Formats and types in C

The first program simply prints X = A + B in each of the four formats, so you can compare them side by side with Try it 1.

#include <stdio.h>

/* The same addition, X = A + B, written
   in four instruction formats. */
int main(void)
{
    printf("3-address:  ADD X, A, B\n");
    printf("  (one instruction)\n");
    printf("2-address:  MOV X, A\n");
    printf("            ADD X, B\n");
    printf("1-address:  LOAD A\n");
    printf("            ADD  B\n");
    printf("            STORE X\n");
    printf("0-address:  PUSH A\n");
    printf("            PUSH B\n");
    printf("            ADD\n");
    printf("            POP  X\n");
    return 0;
}

Output:

3-address:  ADD X, A, B
  (one instruction)
2-address:  MOV X, A
            ADD X, B
1-address:  LOAD A
            ADD  B
            STORE X
0-address:  PUSH A
            PUSH B
            ADD
            POP  X

The second program is a tiny decoder. Each instruction is a three-digit number: the hundreds digit is the opcode, and the rest is a one-address field. Opcode 1 is LOAD, 2 is ADD, 3 is STORE, 4 is JMP (control) and 5 is IN (input). 000 is HALT. This is the same idea as ir / 10 in The Processor: CPU Components and the Fetch-Decode-Execute Cycle, just with a wider address field.

#include <stdio.h>

/* Each instruction is a 3-digit code:
   hundreds = opcode, tens and units
   = a memory address (one-address).
   1xx LOAD, 2xx ADD, 3xx STORE, 000 HALT
   4xx JMP (control), 5xx IN (input). */
int main(void)
{
    int prog[6] = {114, 225, 336,
                   440, 501, 0};
    int i, ir, op, ad;
    const char *name;

    for (i = 0; i < 6; i++) {
        ir = prog[i];
        op = ir / 100;
        ad = ir % 100;
        if (op == 1) name = "LOAD";
        else if (op == 2) name = "ADD";
        else if (op == 3) name = "STORE";
        else if (op == 4) name = "JMP";
        else if (op == 5) name = "IN";
        else name = "HALT";
        printf("%03d -> %-5s", ir, name);
        if (op == 0)
            printf("\n");
        else
            printf(" %d\n", ad);
    }
    return 0;
}

Output:

114 -> LOAD  14
225 -> ADD   25
336 -> STORE 36
440 -> JMP   40
501 -> IN    1
000 -> HALT 

Try this: add opcode 6 for OUT and a seventh instruction 602. Then change the decoder so it also prints the type (data, control or input/output) of each instruction.

Try it 3Formats and types drill

Count the addresses named in the instruction, or classify it as data, control or input/output.

Summary

IdeaKey points
Three-addressADD X, A, B. All three operands named. Wide instruction, few of them.
Two-addressADD X, B. One operand is overwritten. Common in CISC discussions.
One-addressADD B, with the accumulator implied. LOAD / ADD / STORE sequences.
Zero-addressADD with both operands on a stack. Short instructions, more of them.
Fixed vs variable lengthFixed: every instruction is the same size, so the PC is easy to update. Variable: programs can be denser, but fetch is harder.
TypesData manipulation (arithmetic, logic, moves), control (jumps, HALT), input/output (IN, OUT).
Instruction setThe complete list of instructions a particular CPU can execute.

Practice questions

1. Write X = A + B as a one-address program and as a three-address program.

Show answer

One-address: LOAD A; ADD B; STORE X. Three-address: ADD X, A, B.

2. Why does a two-address ADD usually destroy one of its operands?

Show answer

One address field is both a source and the destination, so that location is overwritten with the result. (A MOV first can keep a copy if you need it.)

3. Give one advantage of a fixed-length instruction format and one advantage of a variable-length format.

Show answer

Fixed length: the PC is always increased by the same amount, so fetch is simple. Variable length: short common instructions can use fewer bits, so programs can be smaller.

4. Classify each of these: SUB R1, R2; JZ 20; OUT 3; HALT.

Show answer

SUB is data manipulation; JZ is control; OUT is input/output; HALT is control.

5. Write a one-sentence answer to the question: what is a CPU’s instruction set?

Show answer

It is the complete list of instructions that CPU can execute, including their opcodes, formats and effects.

6. A one-address machine uses 8 bits for the opcode and 8 bits for the address. How many different opcodes can it have, and how many memory locations can an instruction name?

Show answer

28 = 256 opcodes, and 256 addresses.

7. The C decoder reads 225 as ADD 25. Show the two calculations.

Show answer

225 / 100 = 2 (ADD) and 225 % 100 = 25 (the address).

Homework

  1. From memory, write X = A − B in all four address formats. Check against the idea of Try it 1 (use SUB, or ADD a negated B).
  2. Make a table of ten instructions from this lesson and from The Processor: CPU Components and the Fetch-Decode-Execute Cycle, with a column for format and a column for type. Ask someone to hide the type column and test you.
  3. Extend decode.c so it prints the type of each instruction. Add two more instructions of your own, one control and one data.
  4. Read 2024 U1 Q1, which discusses one-address and two-address formats, and try that part before you open the solution.

Exam tips

Specimen Unit 1 Paper 01 (2021), Item 15. A short item on the address format of a small program segment (LOAD / ADD / STORE). The important observation is that each instruction names only one address, so the machine is using a one-address format, with the other operand implied in a register (the accumulator).

Specimen Unit 1 Paper 02 (2021), Question 2(b). Asks you to say what a CPU’s instruction set is, and to name two types of instruction. Give the definition from Part 3, then name two of the three groups (data manipulation, control, input/output) with a short example of each.

2024 Unit 1 Paper 02, Question 1. Includes instruction format, and a comparison of one-address and two-address forms. Worked solution: 2024 U1 Q1.

General advice: when you classify a format, count the addresses named in the instruction, not the number of values the ALU uses; when you classify a type, ask whether the instruction changes data, changes the flow of control, or talks to a device. More worked answers are on the CS Solutions page.

Previous: The Processor: CPU Components and the Fetch-Decode-Execute Cycle. Next: Processor Performance: Clock Speed, Cache, GPUs and Multi-Core.

Syllabus link: CAPE Computer Science (CXC A19/U2/21), Unit 1, Module 1: Computer Architecture. Specific Objective 5: describe the main characteristics of a processor (instruction format: number of addresses per instruction, fixed and variable length; types of instructions: data manipulation, control, input/output; instruction sets).

Video search terms

Search YouTube for: "zero one two three address instructions", "instruction set architecture explained", "fixed vs variable length instructions".

Try it 4Quick quiz

Tap an answer. All eight questions are self-checks on this lesson.

Updates

2026/11/23

- Removed the Print this lesson button.

- Published.

© 2026 Vedesh Kungebeharry. All rights reserved.

Leave a Reply