Welcome to the World of Hardware!

Hello there! Today, we are going to dive into the physical world of Computer Science. While software is the set of instructions that tells a computer what to do, hardware is the "stuff you can touch." We will explore how computers think, how they remember things, and how they communicate with the outside world. Don't worry if it sounds like a lot—we’ll break it down piece by piece!


3.1 Computers and Their Components

Every computer system needs four main things to work: Input, Output, Storage, and Memory. Think of it like a kitchen: you bring ingredients in (Input), you cook them on the counter (Memory), you store leftovers in the pantry (Storage), and you serve the final meal (Output).

1. Memory: RAM vs. ROM

It’s easy to get these mixed up, but here is a simple trick: RAM is for things happening now, and ROM is for things that never change.

  • RAM (Random Access Memory): This is volatile memory. This means when you turn the power off, everything inside it is deleted! It stores the data and programs currently in use.
  • ROM (Read Only Memory): This is non-volatile. It keeps its data even without power. It usually contains the "start-up" instructions (BIOS) for the computer.
Deep Dive: Types of RAM
  • DRAM (Dynamic RAM): Needs to be refreshed thousands of times per second. It’s cheaper and used for main memory.
  • SRAM (Static RAM): Faster and doesn’t need refreshing, but it's more expensive. It is used for Cache memory inside the CPU.
Deep Dive: Types of ROM
  • PROM: Programmable ROM (written to once).
  • EPROM: Erasable Programmable ROM (can be erased using UV light).
  • EEPROM: Electrically Erasable Programmable ROM (can be erased using an electrical signal—this is how Flash memory works!).

2. Input and Output Devices

How do we talk to the computer, and how does it talk back?

  • Laser Printer: Uses a laser beam and powdered ink (toner) to print high-quality documents quickly.
  • 3D Printer: Creates physical objects by "printing" layers of material (like plastic) on top of each other.
  • Microphone & Speakers: Microphones convert sound waves into electrical signals (Input); speakers do the opposite (Output).
  • Virtual Reality (VR) Headset: Uses sensors to track your head movement and screens to show you a 3D world.

3. Storage: Where do the files go?

  • Magnetic Hard Disk: Uses spinning platters and a moving head. It's cheap for lots of space but can be slow and fragile.
  • Solid State (Flash) Memory: No moving parts! It's very fast and durable. This is what's inside your phone or a USB stick.
  • Optical Discs: (CDs, DVDs, Blu-rays) Use lasers to read and write data on a reflective surface.

4. Embedded Systems

An Embedded System is a small computer built into a larger device to perform a specific task. Examples: The timer in your microwave, the engine management system in a car, or the controller in a washing machine.

Benefits: Small, cheap to make, and very reliable.
Drawbacks: Hard to update and can only do one specific job.

Quick Review: RAM is volatile (forgets when power is off), ROM is non-volatile (remembers forever). Embedded systems are "hidden" computers inside appliances.


Virtual Machines (VMs)

Imagine you have a Mac, but you really need to run a piece of software that only works on Windows. Instead of buying a new computer, you can use a Virtual Machine.

A Virtual Machine is a software program that acts like a physical computer. It runs an "Operating System" inside another "Operating System."

  • Host OS: The main operating system actually installed on the hardware.
  • Guest OS: The operating system running inside the virtual machine.

Benefits: You can run multiple OSs at once, and if a virus hits the VM, it usually doesn't hurt your real computer!
Drawback: It requires a lot of RAM and a powerful CPU to run two computers at the same time.


4.1 CPU Architecture (The Brain)

Most modern computers follow the Von Neumann Model. This means the Program and the Data are both stored in the same memory (RAM).

Key Components of the CPU:

  • ALU (Arithmetic and Logic Unit): The calculator. It handles math (plus, minus) and logic (AND, OR).
  • CU (Control Unit): The manager. It coordinates all the parts of the CPU and manages the flow of data.
  • System Clock: The heartbeat. It sends out pulses to keep everything in sync.

The Registers (Tiny, Super-Fast Storage)

Don't let the names scare you! Think of them as "sticky notes" the CPU uses to remember what it's doing right this second.

  • PC (Program Counter): Holds the address of the next instruction to be fetched.
  • MAR (Memory Address Register): Holds the address of the location in memory currently being accessed.
  • MDR (Memory Data Register): Holds the actual data that was just read from or is about to be written to memory.
  • ACC (Accumulator): Holds the results of calculations from the ALU.
  • CIR (Current Instruction Register): Holds the instruction that is currently being decoded and executed.

The Three Buses (The Roads)

Data travels around the computer on "buses":

  1. Address Bus: Carries the "address" of where data is going. It is one-way (unidirectional) from CPU to Memory.
  2. Data Bus: Carries the actual data. It is two-way (bidirectional).
  3. Control Bus: Carries signals to coordinate everything (like "Read" or "Write"). It is two-way.

Did you know? The "Bus Width" is like the number of lanes on a highway. A 64-bit bus can move much more data at once than a 32-bit bus!


The Fetch-Execute (F-E) Cycle

This is the "circular" process the CPU does billions of times per second. It happens in three main stages:

  1. Fetch: The CPU gets the next instruction from RAM (using the address in the PC).
  2. Decode: The Control Unit (CU) figures out what the instruction actually means.
  3. Execute: The CPU carries out the instruction (like adding two numbers in the ALU).

Memory Aid: Just remember "F-D-E" — Fetch it, Decode it, Execute it!


Interrupts

An Interrupt is a signal sent to the CPU that says, "Stop what you're doing, I need attention!"

Common causes: A printer running out of paper, a user clicking a mouse, or a hardware failure.

When an interrupt happens, the CPU finishes its current task, saves its "place" in the registers, and runs a special program called an Interrupt Service Routine (ISR) to handle the problem. Once finished, it goes back to what it was doing before.

Key Takeaway: The CPU is the brain, registers are its quick notes, and the F-E cycle is its constant thought process. Interrupts are just "polite" ways for hardware to get the CPU's attention.