Course Content
Part 1: What Does the CPU Really Do?
What Is a CPU and Why Is It So Important? The Difference Between RAM, Storage, and the CPU What Happens When You Click a Button on Your Computer?
0/4
Part 5: How the CPU Talks to Memory and Storage
This part will explain how the CPU and memory are like two people trying to talk across a busy room — and why the CPU needs clever helpers like RAM and cache instead of going straight to the hard drive.
0/4
Part 6: Paths and Highways: How CPUs Talk to Everything
So far, we’ve learned how the CPU works with RAM, cache, and storage. But the CPU doesn’t live alone — it has to talk to memory, graphics cards, USB sticks, and more.
0/4
How Computers Think: Inside the CPU

🔄 Quick Recap from Lesson 2

Last time, we learned about logic gates.
Logic gates are tiny decision-makers inside the CPU that work using electricity:

  • AND gate: Says “YES” only if both inputs are YES.

  • OR gate: Says “YES” if at least one input is YES.

  • NOT gate: Flips YES to NO, and NO to YES.

These are built using switches called transistors, and they live inside a part of the CPU called the ALU — the Arithmetic Logic Unit.
The ALU is like the CPU’s math and thinking helper.

Now we’re going to learn something new:
💡 The CPU can compare things — like “Is number A bigger than number B?” — and then decide what to do next.

 

 

📏 What Does “Compare” Mean in a CPU?

When we compare in real life, it’s like this:

  • “Am I taller than my friend?”

  • “Is my ice cream bigger than yours?”

The CPU does the same thing — but instead of people or ice creams, it compares numbers.

⚠️ But remember: The CPU doesn’t see numbers like 7 or 5 the way we do.
It only understands binary — that’s numbers written in 1s and 0s.

 

⚙️ The Comparator — The CPU’s Tiny Judge

Inside the CPU, there is a special circuit called a comparator.
A comparator is like a judge that always answers YES or NO to questions like:

  • “Are these two numbers the same?”

  • “Is the first number bigger?”

  • “Is the first number smaller?”

The comparator doesn’t guess — it looks at the binary digits (bits) of both numbers and decides.

 

🧩 Example: Is 7 Bigger Than 5?

Let’s walk through this slowly:

Step 1: Write the numbers in binary.

  • 7 in binary = 111 (one-one-one)

  • 5 in binary = 101 (one-zero-one)

Step 2: Compare from the left.

  • First bit: 1 and 1 → same, move on.

  • Second bit: 1 and 0 → 1 is bigger, so we know 7 is bigger than 5.

The CPU does this super fast — millions or even billions of times in one second.

 

 

🧠 How Does the CPU Use Comparisons?

When the CPU makes a comparison, it doesn’t just stop there.
It uses the result to make a decision.

Think of it like a choose-your-own-adventure game:

  • If the answer is YES → Go one way.

  • If the answer is NO → Go another way.

In computer programs, this is often called “if-then” logic:

If something is true → Do this.
If not → Do that instead.

 

🚀 Example in a Video Game

Imagine a game where your health is a number:

  • If health is 0 or less → You lose the game.

  • If health is more than 0 → You keep playing.

The CPU will compare:

YourHealth > 0

And then choose what to do next.

 

📒 Flags — The CPU’s Little Notes

When the CPU compares two things, it writes down the result in tiny storage spots called flags.
Think of flags like sticky notes for the CPU.

Some common flags are:

  • Zero Flag (Z) → The “Yes, it’s zero” note. If the result of a comparison is exactly 0, the CPU sets this flag.

  • Carry Flag (C) → The “We had an extra bit” note. This happens when math makes a number too big for the space given.

  • Sign Flag (S) → The “It’s negative” note. This means the answer is a number below zero.

The CPU looks at these notes later to decide what to do.

 

⏩ Conditional Jumps — Choosing What Happens Next

Normally, the CPU reads instructions one after another, like reading sentences in a book.
But if a comparison gives a certain result, the CPU can jump to a different part of the program.

Example:

  • If “battery is less than 5%” → Jump to “Show Low Battery Warning.”

  • If not → Keep doing the current task.

This is called a conditional jump because the jump only happens if a certain condition is met.

 

📍 Real-Life Examples of CPU Comparisons

  • Elevator → “Am I on the same floor the button was pressed for?”

  • Microwave → “Has the timer reached 0?”

  • Traffic light controller → “Has the timer run out for the green light?”

Every decision you see in a device — big or small — comes from these tiny comparisons.

 

📚 Recap

  • A comparator is a special circuit in the CPU that checks if numbers are equal, bigger, or smaller.

  • The CPU compares numbers in binary, bit by bit.

  • After comparing, it stores the result in flags (little notes).

  • Using flags, the CPU can jump to different instructions instead of always going in order.

  • This lets computers play games, run apps, and make smart decisions.

 

 

0% Complete