CAO Unit 3
CAO Unit 3
Core Components:
1. Control Unit (CU):The "brain" of the CPU. It fetches instructions from
memory, decodes them, and generates control signals to direct the other
components (ALU, registers, memory interfaces) on what to do and
when.
2. Arithmetic Logic Unit (ALU):Performs arithmetic operations (addition,
subtraction, multiplication, division) and logical operations (AND, OR,
NOT, XOR, shifts). It takes operands from registers and returns the result
to a register.
3. Registers:Small, extremely fast storage locationswithinthe CPU. Used
to hold data, instructions, addresses, and status information temporarily
during execution. Key types include:
○ Program Counter (PC):Holds the memory address of thenext
instruction to be fetched.
○ Instruction Register (IR):Holds the instructioncurrentlybeing
decoded and executed.
○ Memory Address Register (MAR):Holds the address of the
memory location to be accessed (read from or written to).
○ Memory Data Register (MDR) / Memory Buffer Register
(MBR):Temporarily holds data being transferred to or from
memory.
○ General Purpose Registers (GPRs):Used to hold operands and
results for ALU operations. Accessible by the programmer (via
assembly language).
○ Status Register / Flags Register:Holds status bits (flags)
indicating results of operations (e.g., Zero flag, Carry flag,
Overflow flag, Negative flag).
4. Internal Buses:Pathways connecting the different components (CU,
ALU, Registers) within the CPU, allowing data and control signals to
travel between them.
● T
emporal Locality:If an item (instruction or data) is accessed, it's likely
to be accessed again soon. (Loops, reuse of variables). Caching keeps
recently used items close.
● S
patial Locality:If an item is accessed, items whose addresses are close
by are likely to be accessed soon. (Sequential code execution, array
processing). Caching fetches blocks of data around the requested item.
oal:To provide the CPU with an average memory access time close to the
G
cache speed, while offering the large capacity of main memory and secondary
storage.
○ M
echanism:A dedicated hardware controller, the DMA Controller
(DMAC), manages the data transfer directly between the I/O
device and main memory,withoutinvolving the CPU except at the
beginning (to set up the transfer: source address, destination
address, data count) and the end (DMAC sends an interrupt when
done).
○ P ros:Most efficient for large data transfers. Frees the CPU almost
entirely during the transfer. Reduces CPU overhead significantly.
○ Cons:Requires a dedicated DMAC. Can lead to bus contention if
the DMAC and CPU need the memory bus simultaneously (cycle
stealing).
● C -> Adder -> Mux -> PC (For incrementing PC)
P
● PC -> MAR
● Memory Interface <-> MAR, MDR
● MDR -> IR
● IR -> Control Unit
● I R (register fields) -> Register File (Read/Write addresses)
● Register File (Read Ports) -> ALU Inputs (possibly via Muxes)
● IR (immediate field) -> Sign Extender -> ALU Input B (via Mux)
● ALU Output -> MAR (for address calculation)
● ALU Output -> Register File (Write Port) (for R-type results)
● MDR -> Register File (Write Port) (for Load results)
● Register File (Read Port) -> MDR (for Store data)
● Control Unit -> Control signals to Muxes, ALU, Register File (Write
Enable), Memory Interface (Read/Write).
1. Fetch:
○ Get the address from the PC.
○ Load the instruction from memory at that address into the IR.
○ Increment the PC to point to the next instruction.
2. Decode:
○ Interpret the opcode in the IR.
○ Identify the operands needed.
○ Generate control signals for the execute stage.
○ Fetch operands from registers if needed.
3. Execute:
○ Perform the operation specified by the instruction (using the ALU,
accessing memory, changing PC for jumps/branches, writing
results to registers).
1. IF (Instruction Fetch):Fetch instruction from memory using the address
in PC, store in IR, increment PC.
2. ID (Instruction Decode & Register Fetch):Decode instruction in IR,
identify required registers, read operand values from the Register File.
Decode immediate values. Check for hazards.
3. EX (Execute / Address Calculation):
○ For ALU instructions: Perform the operation using the ALU on
operands fetched in ID.
○ F or Load/Store: Calculate the effective memory address using the
ALU (Base + Offset).
○ For Branches: Calculate branch target address and evaluate branch
condition.
4. MEM (Memory Access):
○ For Load: Read data from memory using the address calculated in
EX.
○ For Store: Write data (fetched from register in ID) to memory using
the address calculated in EX.
○ Other instructions usually do nothing at this stage.
5. WB (Write Back):Write the result back into the Register File.
○ For ALU instructions: Write the result from the EX stage.
○ For Load instructions: Write the data fetched in the MEM stage.
I n a non-pipelined CPU, one instruction goes through all 5 stages before the
next one starts IF.
F
● ast memory (like SRAM used in caches) isexpensive.
● Slower memory (like DRAM or hard disks) ischeaperand provides
more capacity.
➤
Solution:Usesmall amounts of fast memoryandlargeramounts of
slow memory.
➤
Caches exploit thisby storing recently or nearby used data to speed up
access.
1. Cache Memory:This is the fastest type of memory, located closest to the
CPU. It is used to store frequently accessed data and instructions to speed
up processing. Cache memory is typically divided into levels (L1, L2,
L3), with L1 being the fastest and smallest.
2. Main Memory (RAM):This is the primary storage usedby the CPU to
hold data and instructions that are currently in use. It is slower than cache
but larger in capacity. Main memory is volatile, meaning it loses its
contents when power is turned off.
3. Secondary Memory:This includes storage devices like hard drives,
SSDs, and optical disks. Secondary memory is non-volatile and is used
for long-term data storage. It is much slower than both cache and main
memory but offers much larger storage capacity at a lower cost.
Memory Parameters
ccess Time: Time between a memory request and delivery of data.
A
Cycle Time: Time between successive accesses.
ache memory has the shortest access time, followed by main memory,
C
and then secondary memory.
ost per Bit:This is a measure of how much it costs to store one bit of
C
data. Cache memory is the most expensive per bit, followed by main
memory, and then secondary memory, which is the least expensive.
Main Memory
Semiconductor RAM & ROM Organization
tatic RAM (SRAM):Uses bistable latching circuitry to store each bit. It
S
is faster and more expensive than DRAM but is used for cache memory
due to its speed.
Memory Expansion
emory expansion refers to the ability to increase the amount of RAM in a
M
system. This can be done by adding more RAM modules to the motherboard,
allowing for improved performance and the ability to run more applications
simultaneously.
Cache Memory
Associative & Direct Mapped Cache Organizations
Cache memory can be organized in different ways to optimize performance:
1. Direct Mapped Cache:Each block of main memory maps to exactly one
cache line. This is simple and fast but can lead to cache misses if multiple
memory blocks map to the same cache line (known as conflict misses).
2. Associative Cache:Any block of main memory can be stored in any
cache line. This flexibility reduces conflict misses but requires more
complex hardware to search for data, making it slower than
direct-mapped caches.
3. Set-Associative Cache:This is a compromise betweendirect-mapped
and fully associative caches. The cache is divided into sets, and each set
can hold multiple blocks. A block of memory can be placed in any line
within a specific set, balancing speed and complexity.
Summary Table
ache
C Very fast High Volatile Speed up access
(SRAM)
AM
R Moderate Medium Volatile Main memory
(DRAM)