Welcome to How Computers Think: Storing and Executing Instructions!

Have you ever wondered what actually happens inside a computer when you click a mouse, type a message, or launch your favourite game? It might seem like magic, but underneath the screen, a computer is simply following millions of tiny, step-by-step commands called instructions.

In these notes, we will look "under the hood" of a computer system to discover how instructions are stored in memory, how the computer's processor reads them, and how it carries them out billions of times every single second. Don't worry if this seems tricky at first—we will break down every part step-by-step with simple everyday analogies!

---

1. The Big Idea: The Stored Program Concept

Long ago, early computers had to be rewired by hand every time someone wanted them to perform a different task. Modern computers are much smarter thanks to a groundbreaking idea called the Stored Program Concept, introduced as part of the Von Neumann Architecture.

What is the Stored Program Concept?
It is the principle that program instructions and the data those instructions use are both stored together in the same primary memory (RAM) in the form of binary digits (sequences of \(0\)s and \(1\)s).

Everyday Analogy: Think of a cooking recipe book. On the very same page, you have the list of ingredients (the data) and the step-by-step cooking directions (the instructions). You don't need two separate books; both live in the same place side-by-side!

Did You Know?
To a computer, both instructions and data look identical—they are all just long strings of binary \(0\)s and \(1\)s! The computer knows the difference based on how and when it reads them.

Key Takeaway for Section 1:

Modern computers are based on the Von Neumann Architecture, where a single central processor reads both instructions and data stored together in RAM in binary form.

---

2. The Hardware Team: Key Components

To run programs smoothly, different pieces of computer hardware work together like a well-trained sports team. Let's meet the key players:

A. The Central Processing Unit (CPU)

The CPU is the "brain" or processing engine of the computer. Its main job is to continuously fetch instructions, decode what they mean, and execute them. Inside the CPU, we find several vital parts:

Control Unit (CU): The conductor of the orchestra. The CU manages the execution of instructions, decodes instructions so the computer understands what to do, and sends control signals to coordinate the flow of data around the computer.

Arithmetic Logic Unit (ALU): The master mathematician. The ALU performs two main types of jobs:
1. Mathematical calculations: Addition (\(+\)), subtraction (\(-\)), multiplication (\(\times\)), and division (\(\div\)).
2. Logical comparisons: Making decisions using logic like AND, OR, NOT, or testing if one number is greater than (\(>\)) or equal to (\(=\)) another.

Registers: Tiny, super-fast temporary storage locations inside the CPU. They hold small pieces of data, memory addresses, or the current instruction while it is being worked on (for example, the Program Counter tracks which instruction is next, and the Accumulator temporarily holds calculation results).

Internal Clock: The heartbeat of the CPU. It sends out regular electrical pulses at a constant speed to synchronise all internal operations. Clock speed is measured in Hertz (Hz) or Gigahertz (GHz). A \(3\text{ GHz}\) clock ticks \(3\text{ billion}\) times every second!

B. Primary Memory (RAM – Random Access Memory)

RAM is the computer's fast, temporary working memory.
• It holds the operating system, currently open apps, and the instructions and data currently being processed by the CPU.
RAM is Volatile: This means that when the computer is turned off, everything stored in RAM is immediately lost!

C. Secondary Storage (SSDs, Hard Drives)

• Secondary storage (such as Solid-State Drives or Hard Disk Drives) is non-volatile, meaning it keeps your files, apps, and games saved permanently even when the power is switched off.
• When you want to run a program, it is copied from secondary storage into RAM so the CPU can access it quickly.

Desk Analogy:
Secondary Storage is like your school bag (stores your books permanently when you go home).
RAM is your open desk top (holds only the open exercise book you are working on right now).
The CPU is your brain (doing the reading, thinking, and writing).

Key Takeaway for Section 2:

The CPU (containing the CU, ALU, Registers, and Clock) processes instructions. It pulls active programs from RAM (fast, temporary, volatile memory), while files are saved long-term in secondary storage (non-volatile).

---

3. What Does an Instruction Look Like?

All instructions must be converted into binary machine code (patterns of \(0\)s and \(1\)s) so the CPU can understand them. A single machine code instruction is split into two distinct parts:

1. Opcode (Operation Code): This tells the CPU what action to perform (for example: `ADD`, `LOAD`, or `STORE`).

2. Operand: This tells the CPU what data to use, or gives the memory address in RAM where the data can be found.

Simple Language Analogy:
Think of a simple sentence like "KICK THE BALL":
"KICK" is the Opcode (the action you must do).
"THE BALL" is the Operand (the object you are doing the action to).

Key Takeaway for Section 3:

Every basic CPU instruction is made of an Opcode (the command/operation) and an Operand (the data value or memory address to be operated on).

---

4. The Fetch–Decode–Execute (FDE) Cycle

How does the CPU actually carry out instructions? It repeats a continuous three-step loop called the Fetch–Decode–Execute Cycle. This cycle runs billions of times every second without stopping!

Step 1: FETCH

• The CPU checks the memory address of the next instruction (kept track of by a register called the Program Counter).
• The instruction is fetched across internal connections from RAM into the CPU's internal registers.
• The CPU gets ready for the next cycle by updating the counter to point to the next instruction address.

Step 2: DECODE

• The Control Unit (CU) inspects and breaks down the fetched instruction.
• It splits the instruction into its opcode and operand to figure out what action needs to be taken (e.g., "Is this an addition? Do we need to load data from memory?").

Step 3: EXECUTE

• The CPU carries out the action required by the instruction!
• This might mean the ALU performs a calculation, data is read from or written back to RAM/registers, or the CPU jumps to a new instruction.

And then what? The cycle immediately repeats for the next instruction: Fetch \(\rightarrow\) Decode \(\rightarrow\) Execute \(\rightarrow\) Repeat!

Memory Trick: Remember F-D-E as "Fast Dogs Explore" or "Fetch, Decide, Execute"!

Key Takeaway for Section 4:

The CPU operates on a never-ending 3-step loop: Fetch (bring instruction from RAM), Decode (the CU works out what the instruction means), and Execute (the instruction is carried out).

---

5. Common Pitfalls & Mistakes to Avoid

Don't lose marks on common misconceptions! Here are the most frequent mistakes students make:

Mistake 1: "The CPU stores all your photos and video games."
Correction: The CPU has almost no storage capacity other than tiny temporary registers. Permanent files live in secondary storage (like an SSD or Hard Drive).

Mistake 2: "RAM saves your work forever."
Correction: RAM is volatile. If power is cut, everything in RAM disappears. This is why you must click "Save" to copy your work to non-volatile secondary storage!

Mistake 3: "Instructions and data are stored in separate types of hardware."
Correction: Under the Stored Program Concept, both instructions and data live together in the exact same RAM as binary numbers.

Mistake 4: "The Control Unit does calculations."
Correction: The ALU (Arithmetic Logic Unit) does all math and logic. The CU (Control Unit) only decodes instructions and directs data signals.

---

Quick Review Checklist

Test your understanding with these quick questions:

1. Where are instructions held while a program is running?
Answer: In primary memory (RAM).

2. What are the two parts of a machine code instruction?
Answer: The Opcode (the action) and the Operand (the data or memory address).

3. Which component inside the CPU performs mathematical sums and comparisons?
Answer: The Arithmetic Logic Unit (ALU).

4. What are the three stages of the CPU processing cycle?
Answer: Fetch, Decode, and Execute.

5. Why is RAM called 'volatile'?
Answer: Because it loses all its contents when the power is switched off.