Nexus Learn

Lecture 5: Von Neumann Architecture

Lecture Notes CS-307 Programming Fundamentals 9 min read Updated 8 Nov 2026

↓ Download notes (Word)

On this page
  1. Learning Outcomes
  2. 1. Why Learn What Is Inside?
  3. 2. The Von Neumann Architecture
  4. 3. The Fetch–Decode–Execute Cycle
  5. 4. Variables Live in Memory
  6. 5. Word Bank (Key Terms)
  7. 6. Self-Check Questions

UNIVERSITY OF AGRICULTURE, FAISALABAD

Department of Computer Science

LECTURE 5 · STUDENT NOTES

Von Neumann Architecture: What Happens Inside the Computer

CS-307 Programming Fundamentals · BSCS Semester 1

Week

Slides

Linked practical

Reference ID

3

Lecture5_Von_Neumann_Architecture.pptx

Practical 4

N05

Learning Outcomes

SLO

By the end of this lecture you can…

Builds CLO

Bloom level

SLO 5.1

Name the parts of the Von Neumann architecture (CPU, memory, input/output, buses) and say what each does

CLO4: Describe the syntax and semantics of the C++ programming language.

C1

SLO 5.2

Explain the stored-program idea and the fetch–decode–execute cycle

CLO4: Describe the syntax and semantics of the C++ programming language.

C2

SLO 5.3

Relate a C++ variable to memory: bytes, addresses and sizeof

CLO4: Describe the syntax and semantics of the C++ programming language.

C2

How to use these notes

Read these notes after the lecture and before the practical. Section numbers (for example §3.2) are used in the question bank, so you can always find where an answer comes from. Type every code example yourself — do not copy-paste.

1. Why Learn What Is Inside?

Until now we wrote C++ lines and saw results. Today we open the computer and see who carries out each line and where the values are kept. Knowing this makes later topics easy: sizeof and memory (today), the build process (Lecture 6), arrays (Lecture 17), the call stack (Lecture 27) and pointers (Lecture 33). (Slide L05-S05)

Real-world picture: a dhaba kitchen

Order slip = input · Chef = CPU · Shelf of numbered jars = memory (RAM) · Waiter = bus · Plate served = output. The recipe card is kept on the same shelf as the ingredients — that is the stored program.

2. The Von Neumann Architecture

2.1 The stored-program idea

Architecture means the basic design or plan of something, like the map of a house. In 1945 the mathematician John von Neumann described a plan that almost every computer still follows. Before it, machines such as ENIAC were "programmed" by re-plugging cables by hand, which took days. (Slide L05-S06)

Stored-program concept

Program instructions and data are both kept in the same memory, and the CPU reads the instructions from memory one by one.

So a new program only needs a new file loaded into memory — your phone runs WhatsApp, then a game, on the same hardware.

2.2 The five main parts

(Slide L05-S07)

Figure 5.1 – Von Neumann architecture: CPU, memory, input, output, joined by the system bus

Part

Job

Example

Input unit

Brings data and commands into the computer

keyboard, mouse, scanner, microphone

CPU (Central Processing Unit)

Carries out instructions; has the Control Unit, ALU and registers

Intel Core i5, AMD Ryzen, phone chip

Main memory (RAM)

Holds the running program and its data

8 GB RAM in a lab PC

Output unit

Shows or sends the results

monitor, printer, speaker

Buses

Sets of wires that carry addresses, data and control signals between the parts

the system bus on the motherboard

2.3 Inside the CPU

(Slide L05-S08)

Part

Job

Real-world comparison

Control Unit (CU)

Reads each instruction and tells the other parts what to do

A cricket captain directing the fielders

ALU (Arithmetic Logic Unit)

Does arithmetic (+ - * / %) and logic/comparisons (<, ==, &&)

A shopkeeper's calculator

Registers

Tiny, very fast storage inside the CPU for values in use right now. Two important ones: PC (Program Counter – address of the next instruction) and IR (Instruction Register – the instruction being worked on)

The chef's hands: only a few items, but instantly

Clock

Gives the beat; each tick is one small step

A drummer keeping time

Link to Lectures 3 and 4: every +, , % and every comparison such as `marks >= 50` that you write is finally done by the ALU*.

2.4 Main memory: numbered boxes

Memory is a long row of boxes. Each box holds 1 byte (8 bits) and has its own number called its address. A variable that needs 4 bytes (an int) uses 4 boxes next to each other. (Slide L05-S09)

RAM (main memory)

Storage (SSD / hard disk)

Speed

Fast – the CPU works with it directly

Slower

Keeps data with power off?

No – it is volatile (temporary)

Yes – it is non-volatile (permanent)

What lives there

The program that is running and its variables

Your saved files: .cpp, .exe, photos

Typical size

8–16 GB

256 GB – 1 TB

2.5 Buses

A bus is a set of parallel wires that carries signals between the parts. (Slide L05-S10)

Bus

Carries

Courier comparison

Address bus

The address of the memory box the CPU wants

Address written on the parcel

Data bus

The data or instruction itself (both directions)

The parcel itself

Control bus

Commands such as READ or WRITE, and the clock signal

"Deliver" or "collect" on the slip

Example: to read marks, the CPU puts address 1000 on the address bus and READ on the control bus; memory sends 85 back on the data bus.

3. The Fetch–Decode–Execute Cycle

3.1 The three steps

The CPU repeats these three steps, billions of times a second, until the program ends. (Slide L05-S11)

Figure 5.2 – The instruction cycle

1. Fetch – copy the next instruction from memory (its address is in the PC) into the IR, then add 1 to the PC.

2. Decode – the Control Unit works out what the instruction means (add? store? jump?).

3. Execute – do it: the ALU calculates, or data moves between memory, registers and output.

3.2 Watching a C++ program run

The compiler turns each C++ line into machine instructions. Below, each line is shown as one simplified step. (Slide L05-S12)

cycle.cpp

#include <iostream>

using namespace std;

int main() {

int a = 5; // instruction 1: store 5 in memory box a

int b = 7; // instruction 2: store 7 in memory box b

int sum = a + b; // instruction 3: CPU's ALU adds them

cout << sum; // instruction 4: send result to the screen

return 0;

}

Output

12

Line

Decoded as…

Executed by

int a = 5;

store 5 in a

CU writes 5 into memory

int b = 7;

store 7 in b

CU writes 7 into memory

int sum = a + b;

load a and b, add, store

ALU adds 5 + 7 = 12; result written to sum

cout << sum;

send sum to output

12 appears on the screen

3.3 Speed, cores and the bottleneck

(Slides L05-S13, S14)

  • Clock speed is measured in gigahertz (GHz). Giga = billion, so 3 GHz ≈ 3,000,000,000 ticks per second. While a fast bowler's ball travels to the batsman (about 0.5 s), the CPU ticks about 1.5 billion times.
  • A core is one complete processing unit. A quad-core CPU has 4 cores, each running its own cycle. Our programs use one core.
  • Von Neumann bottleneck: program and data share one bus, and the CPU is much faster than RAM, so the CPU often waits — like one busy road at rush hour. Cache memory (small, very fast, near the CPU) keeps recently used items close, like keeping salt and mirch on the kitchen counter.

Memory

Speed

Typical size

Kept when power off?

Registers

fastest

a few bytes

No

Cache

very fast

a few MB

No

RAM

fast

8–16 GB

No

SSD / hard disk

slow

256 GB – 1 TB

Yes

4. Variables Live in Memory

4.1 Bytes and sizeof

A variable is a named group of memory boxes. The operator sizeof gives how many bytes a type or variable uses. (Slide L05-S15)

memory.cpp

#include <iostream>

using namespace std;

int main() {

int marks = 85;

double cgpa = 3.45;

char grade = 'A';

bool passed = true;

cout << "int uses " << sizeof(marks) << " bytes" << endl;

cout << "double uses " << sizeof(cgpa) << " bytes" << endl;

cout << "char uses " << sizeof(grade) << " byte" << endl;

cout << "bool uses " << sizeof(passed) << " byte" << endl;

return 0;

}

Output (g++ on a 64-bit PC)

int uses 4 bytes

double uses 8 bytes

char uses 1 byte

bool uses 1 byte

Remember

1 byte = 8 bits; a bit is one 0 or 1. An int uses 4 × 8 = 32 bits.

These sizes are for our lab compiler. C++ only guarantees minimum sizes, so another system may differ for some types.

sizeof gives bytes, not digits: sizeof(marks) is 4 whether marks is 7 or 7000000.

4.2 Addresses and the & operator

Every variable has an address — where its first box is in memory. Putting & in front of a variable name gives its address. (Slide L05-S16)

address.cpp

#include <iostream>

using namespace std;

int main() {

int marks = 85;

double cgpa = 3.45;

cout << "marks = " << marks << " is stored at " << &marks << endl;

cout << "cgpa = " << cgpa << " is stored at " << &cgpa << endl;

return 0;

}

Output (one run — your addresses will be different)

marks = 85 is stored at 0x7ffff074b9ec

cgpa = 3.45 is stored at 0x7ffff074b9f0

  • Addresses are printed in hexadecimal (base 16), which starts with 0x.
  • They change every time the program runs, because the operating system loads the program at a different place. This is normal.
  • Name vs value vs address: marks → the name; 85 → the value in the box; &marks → where the box is. We use addresses properly with pointers in Lecture 33.

5. Word Bank (Key Terms)

Word

Simple meaning

Architecture

The basic design or plan of a computer

Stored-program concept

Program and data are kept in the same memory

CPU

Central Processing Unit – the part that carries out instructions

Control Unit

Part of the CPU that directs all other parts

ALU

Arithmetic Logic Unit – does calculations and comparisons

Register

Tiny, very fast storage inside the CPU

Program Counter (PC)

Register that holds the address of the next instruction

Instruction Register (IR)

Register that holds the current instruction

RAM

Main memory; fast but volatile

Volatile

Loses its contents when the power goes off

Bus

A set of wires that carries signals between parts

Fetch–decode–execute

The cycle the CPU repeats for every instruction

Byte / bit

A bit is one 0 or 1; a byte is 8 bits

Address

The number of a memory box

sizeof

C++ operator that gives the size in bytes

Bottleneck

A narrow point that slows everything down

Cache

Small, very fast memory close to the CPU

6. Self-Check Questions

1. Draw the Von Neumann block diagram and label all parts.

2. What is the stored-program concept? Why was it a big improvement over ENIAC?

3. Give the job of the Control Unit, the ALU and the registers.

4. Differentiate between RAM and storage (two differences).

5. Name the three buses and what each carries.

6. Explain the fetch–decode–execute cycle. What does the Program Counter do?

7. int n = 7; — what do n, sizeof(n) and &n give?

8. What is the Von Neumann bottleneck, and how does cache help?

Answers are in §2.2, §2.1, §2.3, §2.4, §2.5, §3.1, §4.1–4.2 and §3.3. Homework is on Slide L05-S20.

← All CS-307 material