KTU S1

The Computer as a Model of Computation

By the end you should be able to: Describe the computer as a model of computation, explain the fetch-decode- execute cycle and stored-program concept, and state what this implies for how problems must be expressed.

Before writing programs it helps to know what kind of machine is reading them, because its limitations shape how every problem must be expressed.

The stored-program computer

A modern computer follows the von Neumann model:

        ┌─────────────────────────────┐
        │          MEMORY             │
        │  (instructions AND data)    │
        └──────────┬──────────────────┘
                   │
        ┌──────────▼──────────────────┐
        │            CPU              │
        │  ┌────────┐  ┌───────────┐  │
        │  │Control │  │Arithmetic │  │
        │  │ Unit   │  │  & Logic  │  │
        │  └────────┘  └───────────┘  │
        └──────────┬──────────────────┘
                   │
        ┌──────────▼──────────────────┐
        │       INPUT / OUTPUT        │
        └─────────────────────────────┘

The essential insight — and it is genuinely a deep one — is that instructions and data live in the same memory, in the same form. A program is just numbers. This is why one machine can run a spreadsheet and a game: you change the numbers, you change the machine's behaviour.

The fetch-decode-execute cycle

The CPU repeats three steps, billions of times a second:

  1. Fetch — read the next instruction from memory
  2. Decode — work out what it means
  3. Execute — carry it out

Then repeat. That's all a computer does.

What the machine can actually do

The instruction set is small and dull:

  • Move a value between memory and a register
  • Add, subtract, multiply, divide
  • Compare two values
  • Jump to a different instruction, possibly conditionally
  • Read input, write output

Everything — every game, every AI model, every video call — is built from these.

The consequences that matter to you

1. It has no understanding. "Sort these names sensibly" means nothing. You must specify the comparison rule exactly.

2. It does exactly what you wrote. Not what you meant. Most bugs are the gap between the two.

3. Steps happen one at a time, in order. Unless you say otherwise, execution is strictly sequential.

4. It is finite. Memory is limited, numbers have limited precision, and some problems are simply too large to compute.

5. It is unimaginably fast at the boring parts. A person checks maybe one number a second. The machine does a billion. This is why brute force is sometimes a perfectly good strategy on a computer and never one for a human.

Why this is called a model of computation

It is one model among several. The Turing machine is another; lambda calculus a third. They differ in structure but turn out to be equivalent in what they can compute.

The practical point: when you plan a solution, you are planning it for this model. Your algorithm must reduce to steps this machine can perform — which is exactly why the next topics are about turning a real problem into precisely such a sequence.