--:-- --
↓ Scroll for more

Unit 3.6

How Computers Use Memory: The CPU and Memory Interaction

IT 231: IT and Application

Learning Objectives 🎯

By the end of this session, you will be able to:

  • ✅ Describe how a computer uses memory to run a program.
  • ✅ Explain the three steps of the CPU's fetch-decode-execute cycle.
  • ✅ Understand the flow of data from secondary storage to RAM to the CPU.

The Big Picture: From Click to Action

How does a computer run a program like a web browser or a game?

1. Storage: The program waits on your slow, long-term storage (SSD/HDD).

2. Memory (RAM): When you open it, it's copied into fast, temporary RAM.

3. CPU: The CPU then takes instructions from RAM to actually run the program.

Think of it as moving ingredients from the pantry (storage) to the kitchen counter (RAM) so the chef (CPU) can cook.

The Data Flow 📊

Data moves through a hierarchy based on speed and proximity to the CPU.

1. Secondary Storage

(SSD, HDD)

Slowest

Long-term, permanent storage.

Loads into

2. Primary Memory (RAM)

(DDR4, DDR5)

Fast

Workspace for active programs.

3. CPU (Cache & Registers)

Fastest

Immediate processing area.

The CPU's Heartbeat ⚡

Once a program is in RAM, the CPU takes over. It runs a continuous loop to process instructions.

This process is called the Fetch-Decode-Execute Cycle. It's the fundamental operation of the CPU, repeated billions of times per second.

The Fetch-Decode-Execute Cycle

1. Fetch 🔍

The CPU's Control Unit fetches the next instruction from its memory address in RAM.

"What is the next thing I need to do?"

2. Decode 🧠

The Control Unit decodes the instruction, figuring out what operation it needs to perform (e.g., add, subtract, move data).

"What does this instruction mean?"

3. Execute ⚡

The Arithmetic Logic Unit (ALU) performs the operation, like a calculation or moving data to a register.

"Okay, I'm doing it now!"

This cycle repeats continuously, allowing your computer to function.

Analogy: Making Chiya (Tea)

Let's compare the cycle to a simple, everyday task.

  • Fetch: You get the recipe book (RAM) and find the next step: "Add sugar".
  • Decode: Your brain understands this means grabbing the sugar jar and a spoon.
  • Execute: You physically take the sugar and add it to the pot.
  • Then you repeat the cycle for the next instruction: "Stir".

Practical Application in Nepal

How does this apply to using a digital wallet like eSewa or Khalti?

eSewa Logo
  1. Launch: You tap the eSewa app. The OS loads it from your phone's storage into RAM.
  2. Fetch: CPU fetches the instruction for "Send Money".
  3. Decode: It understands it needs to access the amount field, recipient number, and the 'confirm' button logic.
  4. Execute: When you hit confirm, the ALU performs the calculations and sends the data to complete the transaction.

What Happens When You Save?

The data flow also works in reverse.

When you are typing a document, where are the words being stored before you hit "Save"?

Answer: In RAM! 💡

Crucial Point: RAM is volatile (temporary). If the power goes out, all your unsaved work is lost. Hitting "Save" writes the data from RAM back to your non-volatile secondary storage (SSD/HDD) for safekeeping.

Discussion Point: Out of RAM?

What happens if you try to run too many programs at once and you run out of RAM?

  • Your computer slows down dramatically.
  • The operating system starts using a part of your secondary storage (SSD/HDD) as "virtual memory," which is much slower than actual RAM.
  • This process is called "swapping" or "paging."
  • Programs may become unresponsive or even crash.

Summary & Key Takeaways

Let's review the core concepts of CPU and memory interaction.

  • Programs must be loaded from secondary storage into faster RAM to be executed by the CPU.
  • The CPU continuously performs the Fetch-Decode-Execute cycle to process program instructions.
  • Data flows from storage ➡️ RAM ➡️ CPU Cache/Registers for processing, and back to storage when you save.
  • This coordinated system allows computers to perform complex tasks efficiently.

Thank You!

Any questions?


Next Topic: Unit 4.1 - Introduction to Operating Systems