Skip to main content
← Informatics

FOLLOW EACH STEP

CPU & von Neumann architecture

You enter the number 7, and 12 appears on the screen. Although the result seems immediate, no fixed circuit inside the machine inherently knows how to add 5. For one computer to handle different tasks, such as arithmetic, text editing, or audio playback, the steps themselves must be written as instructions, stored in memory alongside data, and carried out in order by the central processing unit, or CPU. Storing instructions and data together in memory is the central idea of the von Neumann architecture.

We begin with the concrete task of reading 7, adding 5, and displaying 12. First we examine how instructions and numbers sit in memory, then we trace address, data, and control signals through fetch, decode, and execute on a 3D hardware model, read how a 12-bit binary instruction encodes an operation, and see how a pipeline overlaps several instructions. Once the path of a single instruction is clear, comparing it with how a GPU organises its work shows why hardware takes a different form when many pixels require the same calculation at once.

After this page, you should be able to solve

  • Given a short program such as IN, ADD [12], STORE [13], OUT, trace the values held in PC, MAR, MDR, IR, and ACC through fetch, decode, and execute, and explain why IR and MDR cannot be merged into a single register.
  • Divide a 12-bit binary or hexadecimal instruction into its opcode and operand field, distinguish an immediate addition such as ADD 5 from a memory addition such as ADD [12], and convert the operand to decimal.
  • Identify the role of the address bus, data bus, and control signals during a memory read or write, and explain why an address signal specifies a memory location while the computed value travels on the data bus.
  • Calculate the clock cycles required for kk independent instructions on a 5-stage pipeline versus separate execution, comparing k+4k + 4 with 5k5k, and identify which cycle stalls when a data dependency or single-port memory conflict occurs.
01

Start with a task: read a number, add 5, display the answer.

+ 5 =12

The computer keeps instructions and numbers in memory. One place can hold 5. An instruction somewhere else says to add that 5 to the number just entered. Keeping the instructions there too is the stored-program idea.

InputPrepare the value
→
CPURead and execute
↔
MemoryInstructions + data
·
OutputCPU → display

Think of memory as a row of numbered drawers. Drawer 12 can hold the number 5. Its address is 12. Its contents are 5.

Information is represented by bits: each bit is a 0 or a 1. A bus is a set of connections carrying signals. An address bus identifies where to access; a data bus carries bits; control signals specify actions such as READ or WRITE. Instructions also travel as bits on the data bus. These colours distinguish signal roles, not three types of instruction.

02

How does the CPU know what to do next?

Suppose the instruction is “add the value at address 12”. We must remember both that instruction and the number already entered. Otherwise, reading the next value could overwrite something we still need. The CPU therefore uses several small, fast stores, called registers. One keeps the instruction; another keeps the working number. A third remembers where to find the next instruction. The short labels in the apparatus name these different stores. The guide below explains each label, so we can follow what is stored and moved during a transfer.

The CPU takes an instruction from memory; this is called fetching. It identifies the required operation and its operand—the value or location used—which is called decoding. With that information, it can execute the instruction. Each phase may contain smaller transfers, called micro-operations. The starting program has five instructions; you can replace them with your own commands below. Play step demonstrates the current transfer; the starting state stays still until you choose to advance. After each transfer, look for where the value came from, which part received it and which values did not change. You can replay a transfer, return to an earlier step or choose automatic playback. Its four-second pauses are viewing time, not a reading deadline.

Give each stored value a job

LabelNeedStore
PCWhere should the next instruction be read?Program counter: keeps that memory address.
MARWhich memory location are we using now?Memory address register: holds the selected address.
MDRWhat value crosses the memory connection?Memory data register: holds the value being transferred.
IRWhich instruction are we carrying out?Instruction register: keeps the current instruction.
ACCWhat number are we working on?Accumulator: keeps the current working number.

These stores do not decide the next action by themselves. The control unit, CU, organises operations. The arithmetic logic unit, ALU, performs operations such as addition. This teaching processor keeps a working result in ACC; real processors may organise their registers differently.

For example, after entering 7, ADD [12] means “add the value stored at address 12”. If that location holds 5, IR keeps ADD [12], MAR keeps 12, MDR receives 5 and ACC still holds 7 before the addition. Only after the ALU calculates does ACC become 12. Address 12 and result 12 happen to be the same number, but serve different purposes.

Give the computer your own instructions

We want to read 7, add 5, keep the answer and show it. Each line asks the CPU to do one operation. The sample below produces 12; change a number or instruction and the registers, memory and screen will follow your new program.

  1. IN 7 puts 7 on the input port; the CPU reads it into ACC, its working register.
  2. ADD 5 adds 5 to ACC: 7 + 5 = 12. SUB 5 would subtract 5 instead.
  3. STORE 13 copies the answer into memory location 13. LOAD [13] retrieves that saved answer; LOAD 13 puts the number 13 itself into ACC. Brackets distinguish an address from a value.
  4. OUT sends ACC to the screen. HALT ends the program. Use “Load program”, then “Run program” or the step controls to follow each transfer.
Instruction reference and machine limits

IN n reads the next prepared keyboard number. LOAD n replaces ACC; ADD n and SUB n change it. Use [12], [13], [14] or [15] with LOAD, ADD or SUB to read memory instead. STORE 12–15 saves ACC. OUT updates the display; HALT stops. Numbers are integers.

This teaching machine has 16 memory words of 12 bits. Addresses 0–11 hold up to 12 instructions; 12–15 hold data, initially zero. A word represents signed values −2048…2047. An instruction reserves four bits for its operation, leaving eight for an immediate value (−128…127). IN accepts the full 12-bit range because its value arrives from the keyboard separately. Results outside the range are rejected with an explanation instead of silently wrapping. This is a teaching instruction set, not a commercial CPU’s assembly language.

1 / 37
Instruction 1/5: IN 7fetchReady to follow this step

Choose the instruction address

PC is 0. Copy this address to MAR so memory knows which location to read.

Data bus PC → MAR0
Loading the computer model…
Drag to rotate · scroll to zoom · click a component
Functional cutaway · signal motion is slowed for inspection

Board map: IN input · OUT output · RAM memory · PC program counter · MAR memory address register · MDR memory data register · IR instruction register · CU control unit · ACC accumulator · ALU arithmetic logic unit.

Blue selects a memory address. Amber carries bits, including addresses copied between registers. Violet carries control signals such as READ. A light marker represents a transfer; the travel time is enlarged for learning.

Inspect memory and number notation

Addresses and values are decimal. 0x marks a hexadecimal word: each digit represents four binary bits. Instructions start at address 0. Locations 12–15 hold your data; their initial value is zero. Negative data use 12-bit two’s complement, so −1 is stored as 0xFFF.

AddressWordMeaning
00x100IN 7
10x205ADD 5
20x30DSTORE 13
30x400OUT
40x500HALT
50x0000
60x0000
70x0000
80x0000
90x0000
100x0000
110x0000
120x0000
130x0000
140x0000
150x0000

Select a component: why does it need to exist?

PC · Program counter

Remembers the address of the next instruction. Otherwise the CPU would not know where to continue. In this word-addressed machine every instruction occupies one word, so sequential execution adds 1 to PC.

This three-dimensional model shows a functional cutaway, with extra space between parts so the signals can be followed. It is not the transistor layout of a particular commercial chip. This machine uses one accumulator, 12-bit words, a 4-bit address space, and explicit input/output instructions. Modern CPUs may arrange these functions very differently.

03

The memory stores bits. Where did “ADD” come from?

A bit has two possible values, 0 and 1. A word is a fixed-size group of bits; here it has 12. The first four bits form the operation code, or opcode. The final eight form the operand field. ADD 5 puts the number 5 in this field; ADD [12] puts the address 12 there instead. They need different opcodes so the control unit knows whether to use the field itself or read memory. STORE also uses an address. Our editor reserves locations 12–15 for data, keeping them separate from the program.

Readable instructionOpcode | operandMeaning
IN0001 | 00000000Input → ACC
ADD [12]1001 | 00001100ACC + memory[12] → ACC
STORE [13]0011 | 00001101ACC → memory[13]
OUT0100 | 00000000ACC → output
HALT0101 | 00000000Stop fetching instructions

From right to left, binary positions have values 1, 2, 4, 8, 16 and so on, doubling at each step. In 00001100, only the 8 and 4 positions contain 1, so the value is 8+4=128+4=12. Hexadecimal uses one digit for values from 0 to 15, with A to F representing 10 to 15. Thus 12 is C. The prefix 0x marks hexadecimal: 0x00C, binary 000000001100 and decimal 12 represent the same number. For example, 1001 selects ADD from memory; 00001100 represents 12. So 1001 00001100 means “add the value at address 12”. IR keeps these bits, and the control unit decodes them. ADD is the readable name of that code, not a word that the hardware understands as English. By comparison, ADD 5 is 0010 00000101: opcode 0010 chooses an immediate number, and 00000101 is 5.

Why do instruction and data registers stay separate?

Suppose we have stored 5 at address 12, then execute ADD [12]. MDR must now receive that 5 from memory. If MDR were our only copy of the instruction, that read would replace the instruction with 5. Fetching copied the instruction into IR first, so we can read data without losing the operation we are carrying out.

The clock coordinates when stored values change. A program instruction is not necessarily one clock cycle: fetching, decoding, and execution can need several cycles. The animation slows transfers so you can inspect them; its seconds are not a CPU speed measurement.

04

Must the next instruction wait for everything to finish?

Now that we can follow one instruction, imagine dividing its work between five stages. Once the first instruction leaves the fetch stage, that stage can begin fetching another instruction while the first is decoded elsewhere. This overlapping arrangement is a pipeline. It is an implementation technique, not a requirement of the von Neumann idea.

IF · Instruction fetch

Read the instruction from memory.

ID · Decode / read registers

Identify the operation and obtain its inputs.

EX · Execute

Perform arithmetic or calculate an address.

MEM · Memory access

Read or write data if the instruction needs it.

WB · Write back

Store a result in its destination register.

The next demonstration uses a separate five-stage machine with registers R1, R2, … rather than a single accumulator. Ri names storage location i in the register bank. Each row is an instruction, each column one clock cycle. The gold banks between stages are pipeline registers: they hold intermediate values, destination numbers, and control bits between clock edges.

Cycle 0 / 8
0 / 8 cycles
I1 · R1 ← R2 + R3

Cycle 0: This instruction has not entered the pipeline yet.

IF—
ID—
EX—
MEM—
WB—
Instruction / cycle →12345678
I1: R1 ← R2 + R3IFIDEXMEMWB
I2: R4 ← R6 + R5IFIDEXMEMWB
I3: R7 ← R8 + R9IFIDEXMEMWB
I4: R10 ← R11 + R12IFIDEXMEMWB

Different instructions can use different stages together.

In cycle 3, I1 is executing, I2 is decoding, and I3 is being fetched. Registers between stages retain each instruction’s intermediate information, so the next cycle can move each one forward without mixing them up.

Assume five stages of one cycle each, independent instructions, and no stalls. Completing four instructions separately takes 4×5=204 \times 5 = 20 cycles. With overlap, the first takes 5 cycles, then one finishes in each of the next 3 cycles: 8 in total. For k instructions:

Tseparate=5kTpipeline=5+(k−1)=k+4\begin{gathered}T_{\mathrm{separate}}=5k\\T_{\mathrm{pipeline}}=5+(k-1)=k+4\end{gathered}

The first instruction still takes five cycles. What improves is throughput: how many instructions finish over time. Switch to the dependency example to see why real pipelines cannot always finish one instruction per cycle. A result that is not ready forces a wait unless another mechanism, such as forwarding, can safely supply it earlier.

Can fetch and data access use the same memory together?

Not if it has only one access port. A load or store in MEM can conflict with IF, requiring a stall or a different memory arrangement. The instructions in our table only add registers, so their MEM stages pass values along without accessing memory. The example therefore does not assume two simultaneous accesses to our single-port memory.

Check: does a blue address packet contain the answer?

No. It identifies a location. The data signal carries its contents, and a control signal says whether to read or write. To store an answer, the machine needs all three roles.

Sign in to see more

Sign in to continue the rest of this lesson and keep your progress in sync.