Memory and CPU Design

Memory and CPU Design

CPU Design Components

The CPU (Central Processing Unit) is composed of several key functional units, each with a specific role in processing instructions:

Unit

Role

Arithmetic Logic Unit (ALU)

Performs arithmetic (e.g., addition, subtraction) and logical operations (e.g., AND, OR).

Control Unit (CU)

Directs the operation of the CPU by decoding instructions and coordinating data flow.

Registers

Provide temporary, high-speed storage for data and instructions during processing.

Program Counter (PC)

Holds the memory address of the next instruction to be fetched.

Instruction Register (IR)

Stores the current instruction being decoded and executed.

Memory Hierarchy

Memory systems are organized in a hierarchy based on speed, size, and proximity to the CPU. The hierarchy balances performance and cost:

Memory Type

Speed

Size

Location

Registers

Fastest

Very small (e.g., KB)

Inside CPU

Cache (L1, L2, L3)

Very fast

Small (e.g., MB)

Near CPU (on-chip or close)

Main Memory (RAM)

Moderate

Large (e.g., GB)

On motherboard

Secondary Storage (HDD/SSD)

Slowest

Very large (e.g., TB)

Disk or external

  • Registers: Used for immediate data access during instruction execution.

  • Cache: Stores frequently accessed data to reduce access time to RAM.

  • Main Memory: Holds active programs and data during execution.

  • Secondary Storage: Provides long-term storage for data and programs.

Communication via Buses

The CPU and memory communicate through buses, which are sets of wires carrying specific types of information:

Bus Type

Purpose

Data Bus

Transfers actual data between CPU, memory, and devices.

Address Bus

Specifies the memory location for reading or writing data.

Control Bus

Carries control signals (e.g., read/write, interrupts) to coordinate operations.

  • Data Bus: Determines the width of data transfers (e.g., 64-bit bus transfers 64 bits at once).

  • Address Bus: Defines the number of addressable memory locations (e.g., a 32-bit address bus supports 2^32 addresses).

  • Control Bus: Ensures proper timing and synchronization of operations.

CPU and Memory Coordination

The CPU and memory work together to execute instructions through a coordinated process:

  1. Control Unit: Decodes instructions and sends control signals to orchestrate operations.

  2. ALU: Performs arithmetic or logical computations as instructed.

  3. Buses: Facilitate communication by carrying data, addresses, and control signals.

  4. Memory: Responds to read (retrieve data) or write (store data) requests from the CPU.

The process follows the fetch-decode-execute cycle:

  • Fetch: The control unit retrieves an instruction from memory using the program counter.

  • Decode: The instruction is interpreted to determine the required actions.

  • Execute: The ALU or other components perform the operation, and results are stored.

Example: Executing an ADD Instruction

Consider the instruction ADD R1, R2, which adds the contents of registers R1 and R2 and stores the result in R1:

  1. Fetch:

    • The program counter provides the address of the instruction.

    • The instruction is retrieved from memory via the data bus and stored in the instruction register.

  2. Decode:

    • The control unit interprets the instruction as an addition operation involving R1 and R2.

  3. Execute:

    • The ALU retrieves the contents of R1 and R2 from registers.

    • The ALU performs the addition (R1 + R2).

    • The result is written back to R1 via the data bus.

  4. Update:

    • The program counter is incremented to point to the next instruction.

Last updated