Computer Fundamentals

Computer Fundamentals

Computer Science

Computer Science

What's Really Happening Inside Your Computer?

You're reading this on a screen right now. Maybe a laptop, a tablet, your phone. You tap, click, swipe. Things happen instantly. Apps open. Videos play. Games respond to every move.

But what's actually happening inside that device? Most people use computers every day without thinking about the machinery underneath. It's like driving a car without knowing what's under the hood. You don't need to know. It just works.

Understanding how computers actually work changes everything. You start to see why some programs are fast and others slow. Why your phone heats up during certain tasks. Why adding more RAM helps. Why programmers talk about "efficiency" and "optimization."

This isn't just theory. This is how modern computing works at the most fundamental level—from the CPU processing billions of calculations per second to the operating system juggling dozens of programs simultaneously.

CPU Structure

The CPU (Central Processing Unit) is the primary component of a computer that performs instructions defined by software. It executes the fetch-decode-execute cycle to process data and control all other hardware components.

Inside the CPU

Essential Components

  • Control Unit (CU): Directs the operation of the processor by telling the computer's memory, ALU, and I/O devices how to respond. It fetches, decodes, and coordinates execution. Think of it as the conductor of an orchestra.
  • Arithmetic Logic Unit (ALU): Performs all arithmetic (+, -, *, /) and logical operations (AND, OR, NOT, comparisons). Every mathematical calculation goes through the ALU.
  • Registers: Small, high-speed storage locations within the CPU that temporarily hold data and instructions. These are the fastest memory in the computer.
    • Program Counter (PC): Stores the memory address of the next instruction to be fetched.
    • Memory Address Register (MAR): Holds the address in memory from which data will be fetched or to which data will be stored.
    • Memory Data Register (MDR): Temporarily stores data being transferred between CPU and memory.
    • Current Instruction Register (CIR): Holds the instruction currently being decoded and executed.
    • Accumulator: Stores the results of calculations performed by the ALU.
  • Cache Memory: High-speed memory on or very close to the CPU that stores copies of frequently accessed data.
    • L1 Cache: 32-64 KB per core, 1-2ns access time. Directly on each core.
    • L2 Cache: 256-512 KB per core, 3-10ns access time. On CPU chip.
    • L3 Cache: 8-32 MB shared across all cores, 10-20ns access time.

Performance & Multi-Core

Clock Speed: Measured in GHz (Gigahertz). A 3 GHz processor has a clock that ticks 3 billion times per second. Each tick is an opportunity to execute a basic operation.

Multi-Core Processors: Contains two or more independent processing units (cores) on a single chip. Allows Parallel Processing where different cores work on different tasks (e.g., core 1 renders video, core 2 scans for viruses) actually simultaneously.

Multithreading: Dividing a program into multiple independent sequences (threads). Note: Software must be written specifically to take advantage of multi-core hardware.

GPUs: Specialized Processors

Graphics Processing Units (GPUs) are specialists designed to rapidly process and render graphics by performing parallel operations on massive blocks of data simultaneously.

The Architecture Difference: While a CPU has 4-32 powerful cores, a modern GPU has thousands of small, simple cores (e.g., NVIDIA RTX 4090 has 16,384 CUDA cores). This achieves enormous throughput for repetitive tasks.

FeatureCPUGPU
Core count4-32 powerful cores1,000s of simple cores
Design philosophyLow latency, versatileHigh throughput, specialized
Best forSequential tasks, complex logicParallel tasks, repetition
Example tasksRunning OS, complex calculationsGraphics, AI training, mining, scientific computing

Pipelining: The Assembly Line Approach

Pipelining is a technique where multiple instructions are overlapped during execution by dividing the process into discrete stages. Imagine a car factory where one worker builds an entire car (slow) vs an assembly line where workers perform one task and pass the car along (fast).

Efficiency Gain

Without pipelining, 4 instructions might take 16 clock cycles. With pipelining, they can be completed in just 7 cycles. For large numbers of instructions, pipelining approaches a 4x speedup.

Clock1234567
Inst 1IFIDEXWB---
Inst 2-IFIDEXWB--
Inst 3--IFIDEXWB-
Inst 4---IFIDEXWB

IF: Fetch | ID: Decode | EX: Execute | WB: Write-back

Pipeline Hazards

  • Data Hazard: An instruction depends on a result not yet written. Solution: Forwarding/Bypassing.
  • Control Hazard: Branch instructions make the next instruction unknown. Solution: Branch Prediction (guessing the path).
  • Structural Hazard: Two instructions need the same hardware resource (e.g., ALU) simultaneously.

Memory: The Hierarchy of Storage

Why multiple types? Cost and physics. Fastest memory is expensive and large; you can't fit GBs of cache on a CPU chip economically.

Fastest to Slowest

  1. Registers: <1ns, 32-64 bits each, volatile. Directly in the CPU.
  2. Cache: 1-20ns, KB to MB, SRAM (Static RAM - no refreshing needed).
  3. Main Memory (RAM): 50-100ns, 4-64GB, DRAM (Dynamic RAM - needs refreshing thousands of times/sec). Stores programs currently in use.
  4. ROM: Non-volatile, read-only. Holds the Bootstrap Loader.
  5. Secondary Storage (Non-volatile):
    • SSD (Solid State Drive): Fast (0.1ms access), durable, no moving parts.
    • HDD (Hard Disk Drive): Cheap, large capacity, slower (5-10ms access) due to moving parts.
    • Optical: CD/DVD/Blu-ray using lasers to read pits and lands.
  6. Tertiary Storage: Cloud/Network storage. Effectively unlimited, 50-500ms access time.

Virtual Memory

The OS creates an illusion of more physical memory by using secondary storage. When RAM fills up, the OS moves less-used data to the hard drive (swap space) to free RAM for active programs.

Paging: Memory is divided into fixed 4KB pages. Programs are split across them, eliminating external fragmentation.

Swapping: Moving pages to disk. When done excessively, it causes Thrashing (severe lag) because disk access is 1000x slower than RAM.

Benefits: Run more programs than physically possible. Drawback: Significant performance hit during heavy swapping.

The Fetch-Decode-Execute Cycle: The Heartbeat of Computing

This cycle happens billions of times per second. Every program breaks down into simple instructions executed in this sequence.

Detailed Trace Example

Program: Add two numbers from memory.

  • Address 100: LOAD R1, 500
  • Address 101: LOAD R2, 504
  • Address 102: ADD R1, R2
  • Address 103: STORE R1, 508

Step-by-Step for Instruction 1:

  1. Fetch: PC(100) → MAR. Memory at 100 retrieved → MDR → CIR. PC increments to 101.
  2. Decode: CU decodes "LOAD" and sets up paths to Register R1 and Memory Address 500.
  3. Execute: MAR ← 500. Data read from 500 into R1.

Cloud Computing Stack

Today, much of what we do happens "in the cloud"—on remote servers accessed via the internet.

SaaS (Software as a Service)

Hosted apps accessible via browser (e.g., Gmail, Netflix).

  • Advantages: Lower upfront cost, automatic updates, access anywhere.
  • Disadvantages: Requires internet, subscription costs, data security concerns.

PaaS (Platform as a Service)

Development environment (e.g., Heroku, Azure App Service).

  • Advantages: Focus on code, faster development, automatic scaling.
  • Disadvantages: Vendor lock-in, less control over infrastructure.
ModelYou ManageProvider ManagesExample
SaaSYour dataEverything elseGmail, Microsoft 365
PaaSApplications, dataInfrastructure, OS, runtimeGoogle App Engine
IaaSOS, apps, dataPhysical hardwareAWS EC2

Binary and Hexadecimal

Computers work with electricity (High voltage = 1, Low = 0). Every piece of data—text, images, programs—is ultimately stored as binary.

Conversion Examples

Binary to Decimal: 11010₂ = (1x16) + (1x8) + (0x4) + (1x2) + (0x1) = 26₁₀

Decimal to Binary: 45 ÷ 2 (remainders): 45(1), 22(0), 11(1), 5(1), 2(0), 1(1) → 101101₂

Binary to Hex: Group 1010 1111 0100 1110 → AF4E₁₆

Hexadecimal Digits

DecBinHex
101010A
111011B
121100C
131101D
141110E
151111F

Where is Hex used?

  • Memory addresses: 0x7FFF...
  • Color codes: #FF5733
  • Hardware IDs: MAC addresses and IPv6.

Data Representation

Computers represent everything—text, images, sound—as numbers.

Character Encoding

  • ASCII: 7-bit encoding (128 characters). Includes English letters, numbers, and symbols. Limited to basic Western text.
  • Unicode: 16 or 32-bit encoding (140,000+ characters). Includes every language, ancient scripts, and even emojis. Standard for modern software.

Digital Images

  • Pixels: Smallest unit of an image (picture element).
  • Resolution: Total pixels (Width x Height).
  • Color Depth: Number of bits per pixel (e.g., 24-bit = 16.7M colors).
  • Metadata: Data about data (File size, dimensions, GPS, camera settings).

Digital Sound

  • Sampling: Converting analog waves to digital data at fixed intervals.
  • Sample Rate: Number of samples per second (Hz). CD quality is 44,100Hz.
  • Bit Depth: Number of bits per sample, determining dynamic range.

Logic Gates & Complex Circuits

At the lowest level, computers are built from transistors—tiny electronic switches. By combining them, we create logic gates.

Basic Gates

ABANDORXOR
00000
01011
10011
11110

Universal Gates

NAND and NOR are universal—any circuit can be built using only these gates. NAND outputs 0 only when all inputs are 1.

Building Adders

Half Adder: Adds two bits. XOR for Sum, AND for Carry.

Full Adder: Adds three bits (A, B, and Carry_in from previous). Built from two half adders + an OR gate.

ABC_inSumC_out
00000
01101
11111
...............

Operating Systems (OS)

An OS is system software that manages hardware and acts as an intermediary between users and computer hardware. Without an OS, every program would need to directly control hardware, which is impossibly complex.

Core OS Functions

  • Process Management: Creating/terminating processes, scheduling CPU time, and handling synchronization.
  • Memory Management: Allocating RAM (using Fixed or Dynamic Partitioning) and managing Virtual Memory via Paging.
  • File Management: Organizing storage, permissions, and space. Examples include NTFS (Windows), FAT32 (Cross-platform), ext4 (Linux), and APFS (macOS).
  • Device Management: Communicating with peripherals via Device Drivers.
  • Security: Managing user authentication, firewalls, and encryption.

User Interfaces

CLI (Command Line): Text-based (Terminal). Powerful, efficient for experts, scriptable, but steep learning curve.

GUI (Graphical): Visual icons/windows. Intuitive and easy to learn, but higher resource usage.

CPU Scheduling

  • Round Robin: Fixed time quantum in circular order.
  • Priority: Higher priority runs first. Uses Aging to prevent starvation.
  • Multilevel Queue: Separate queues for system vs user tasks.

Utility Software

Specialized programs like Disk Defragmentation (reorganizes HDD sectors), Compression (ZIP), Antivirus, and Backup utilities.

Control and Embedded Systems

A control system regulates the behavior of devices using control loops. Examples: Cruise control, thermostats, autopilot.

Open-Loop

Executes predetermined actions without monitoring output. Example: Traditional washing machine timer runs regardless of cleanliness.

Closed-Loop (Feedback)

Continuously monitors output and adjusts. Example: Thermostat compares temp to setpoint and adjusts heating.

Feedback Components (e.g., Cruise Control)

  1. Setpoint: Desired state (60 mph).
  2. Sensor: Measures actual output (58 mph).
  3. Controller: Calculates error (-2 mph).
  4. Actuator: Takes action (Increase throttle).
  5. Process: The system being controlled.

Embedded Systems

Specialized computers for dedicated functions within larger systems. Characteristics: Dedicated function, Real-time requirements, Limited resources, and High reliability.

Examples: Car engine controllers, medical devices (pacemakers), industrial robots, and traffic light controllers.

Computer Networking

Networks allow computers to communicate and share resources.

Network Types

  • LAN (Local Area Network): Covers a small area (Home, Office). High speed.
  • WAN (Wide Area Network): Covers large distances (Cities, Countries). The Internet is the largest WAN.
  • WLAN: A wireless local network (Wi-Fi).

Network Hardware

  • Router: Directs data packets between different networks.
  • Switch: Connects devices within a single LAN.
  • WAP: Wireless Access Point.
  • NIC: Network Interface Card (Unique MAC address).

Protocols & Topologies

Topologies: Star (central hub), Bus (single cable), and Mesh (all-to-all redundancy).

Common Protocols:

  • TCP/IP: The fundamental language of the Internet.
  • HTTP/HTTPS: Web browsing (secure).
  • FTP: File transfer.
  • SMTP/IMAP/POP: Email protocols.
  • Wi-Fi / Ethernet: Connectivity standards.

Compilers and Interpreters

Humans write in high-level languages (Python, C++), but computers only execute binary Machine Code. We bridge this gap using translators.

Compilers (C, C++, Rust)

  • Pros: Fast execution, early error detection, optimization, code protection (no source distributed).
  • Cons: Long compilation time, platform-specific, complex edit-compile-run cycle.

Interpreters (Python, JS)

  • Pros: Immediate execution, platform independence, interactive development, easier debugging.
  • Cons: Slower execution (5-100x slower), runtime errors only, requires interpreter installed.

Hybrid Approaches & JIT

Java: Compiles to Bytecode, then JVM interprets. JIT (Just-In-Time) compilation compiles frequently-used code to machine code during runtime for near-native performance.

Assemblers: Translates Assembly Language (MOV, ADD) directly into binary machine code. One-to-one mapping.

Putting It All Together

The CPU fetches, decodes, and executes billions of instructions per second. The Control Unit orchestrates, the ALU calculates, and Registers hold working data at incredible speed.

From logic gates forming circuits to operating systems managing resources, every layer of the computer works in harmony to turn ones and zeros into the apps, games, and tools we use every day.