Peripheral Devices and Input-Output Interface
Overview: A printer may accept bytes more slowly than the CPU can send them.
What are Peripheral Devices?
- A computer processor by itself is just a microscopic chip that crunches 0s and 1s.
- Input Devices: Keyboard, mouse, barcode scanner, microphone.
- Output Devices: Monitor screen, printer, speakers.
- Storage Devices (Secondary Memory): Solid-State Drives (SSD), Hard Disks (HDD), USB pen drives.
Why Can’t Peripherals Connect Directly to the CPU?
- You cannot plug a keyboard or printer directly into the CPU’s internal system wires.
- Speed Mismatch:
- Data Format Mismatch:
- Signal Voltage Levels:
View diagram · Role of the I/O Interface Bridge
Isolated I/O vs. Memory-Mapped I/O
- How does the CPU talk to an I/O device?
- Address Space: Separate address spaces for RAM and I/O ports
- Control Signals: Uses separate control wires (
IOR,IOWvs. - Instructions Used: Only special commands:
IN port,OUT port - Addressing Modes: Very limited (only port numbers)
- Effect on RAM: Full RAM address space remains free for programs
- Hardware Design: Needs extra decoding circuits
Data Transfer Schemes: Programmed I/O, Interrupts, DMA, and IOP
Overview: For a large file transfer, DMA can move a block between the device and memory after the CPU sets it up.
Introduction: Moving Data Between Peripherals and Memory
- Transferring files between external drives (SSDs, USB pen drives) and RAM memory needs to be fast and efficient.
- 1. Programmed I/O CPU constantly checks (polls) the device in a loop.
- 2. Interrupt-Initiated I/O Device rings an electronic bell only when ready.
- 3. DMA Transfer A hardware controller moves data blocks directly between drive and RAM without CPU help!
- 4. I/O Processor (IOP) A dedicated helper CPU with its own instruction set managing all device traffic.
View diagram · Evolution of Data Transfer Schemes
Programmed I/O (Polling)
- The CPU executes an instruction that checks if the device is ready.
- If the device is busy, the CPU gets trapped in an infinite waiting loop (Busy-Waiting):
- Huge Drawback: Wastes almost all CPU processing power waiting for slow humans or mechanical disks.
Interrupt-Initiated I/O
- The CPU does not ask the device anything.
- When the device is ready with data, it sends an electrical Interrupt Request (INTR) to the CPU.
- The CPU pauses its current program, saves its
PCreturn address on the stack, and runs the Interrupt Service Routine (ISR) to copy… - Once finished, the CPU returns right back to its original program.
- Daisy Chaining (Priority Resolution): When multiple devices ask for attention at the same time, a Daisy Chain connects them like a series line of students.
- The device physically closest to the CPU has the highest priority and gets served first!
Direct Memory Access (DMA Transfer)
- When loading a large 4 GB movie or game file from an SSD into RAM, having the CPU move each byte one-by-one through its Accumulator is painfully…
- Key Registers Inside a DMA Controller: Address Register: Stores the starting RAM memory address where data must go.
- Word Count Register: Stores how many bytes to transfer (counts down to zero).
- Control Register: Sets the direction (Read from disk or Write to disk).
- Two Main DMA Modes: Burst Transfer (Block Mode):
- Cycle Stealing:
View diagram · DMA System Architecture
Input-Output Processor (IOP)
- In enterprise mainframes and web servers, an I/O Processor (IOP) is a dedicated separate mini-CPU.
- The main CPU simply tells the IOP: “Load this 10 GB database from disk into RAM.”
- The IOP handles everything independently: addresses, error checks, buffers, and bus management.
- When the transfer is 100% complete, it sends one final interrupt to let the main CPU know!
Memory Hierarchy, Processor vs. Memory Speed, and Memory Technologies
Overview: A loop that reads neighbouring array elements benefits from spatial locality.
What is Memory Hierarchy?
- Every computer user dreams of infinite memory that runs at lightning speed and costs zero rupees!
- If a memory is super fast, it is super expensive and small (like CPU registers and Cache).
- If a memory is huge and cheap, it is slow (like SSDs and Hard Disks).
- 2. Cache Memory (L1, L2, L3) Ultra-fast (1–10 ns) | Megabytes (MB) | SRAM Technology
- 3. Main Memory (RAM) Moderate (50–100 ns) | Gigabytes (8–64 GB) | DRAM Technology
- 4. Auxiliary Storage (SSD / HDD) Slow (Microseconds/ms) | Terabytes (TB) | Lowest Cost per bit
View diagram · The Memory Hierarchy Pyramid
Processor vs. Memory Speed: “The Memory Wall”
- Over the last 40 years:
- CPU processor speeds improved rapidly at 50% every year.
- But RAM memory speeds only improved by 7% per year.
- When a fast 4GHz CPU requests data directly from slow DRAM, it must freeze and wait for over 300 clock cycles!
- The memory hierarchy solves this: by keeping 95%+ of active data in high-speed Cache Memory, the CPU keeps running at top speed without…
- An everyday example
- Think of studying for exams at your desk:
-
- CPU Registers: The pen in your right hand (instant access).
High-Speed RAM: SRAM vs. DRAM
- Primary system RAM is built using semiconductor silicon chips.
- Internal Cell: Built using 6 transistors as a flip-flop
- Refreshing Needed?: No refresh needed (holds data steadily)
- Speed: Extremely Fast (1 to 5 ns)
- Storage Density: Lower (6 transistors take more space)
- Cost: Very expensive per megabyte
- Main Usage: CPU Cache Memory (L1, L2, L3)
Read-Only Memory (ROM) Technologies
- ROM chips hold permanent boot firmware (like BIOS / UEFI) that never disappears when the power is turned OFF (Non-Volatile):
- Mask ROM: Programmed permanently at the chip factory during manufacturing.
- PROM (Programmable ROM): A blank chip that you write onto once by burning microscopic internal fuses.
- EPROM (Erasable PROM): Can be erased by shining ultraviolet (UV) light into its quartz glass window for 20 minutes, then rewritten.
- EEPROM (Electrically Erasable PROM): Can be erased and rewritten electrically byte-by-byte without removing it from the circuit.
- Flash Memory: A modern, fast block-erasable version of EEPROM used in all SSDs, pen drives, and smartphones.
Cache Memory, Mapping Techniques, and Associative Memory (CAM)
Overview: With four direct-mapped cache lines, blocks 1 and 5 both map to line 1 using the block number modulo four.
What is Cache Memory?
- Cache Memory is an extremely fast, small SRAM storage buffer built right inside the CPU chip.
- Its only job is to store copies of the data and instructions the CPU will need next.
- When the CPU finds its data in cache, it answers in 1 to 2 clock ticks instead of waiting 50 to 100 ticks for slow RAM!
The Principle of Locality of Reference
- Why does a tiny 8 MB cache work so well when your computer has 16,000 MB (16 GB) of RAM?
- 1. Temporal Locality (Time) If you access a variable now, you will likely access it again very soon.
- 2. Spatial Locality (Space) If you access one address, its nearby neighbor addresses will be accessed next.
- An everyday example
- Think of doing your college homework:
-
- Temporal Locality: You keep your favorite pen on your notebook because you keep using it every 10 seconds.
-
- Spatial Locality: You open chapter 3 of your book; once you finish page 45, you naturally read page 46 next!
View diagram · The Two Dimensions of Locality
Hit Ratio and Average Access Time Formula
- Cache Hit: The CPU looks for data in Cache and finds it immediately!
- Cache Miss: The data is not in Cache; the CPU must fetch it from slow RAM.
- Hit Ratio (H):
- Average Memory Access Time (T_avg):
T_avg = (H × T_c) + ((1 - H) × T_m) - Where
T_cis Cache speed (e.g. - If your system has a 95% hit rate (
H = 0.95):
Cache Mapping Techniques
- How does a block from large RAM get placed into the smaller cache?
- 1. Direct Mapping Each RAM block maps to strictly ONE fixed cache line.
- 2. Associative Mapping Any RAM block can be placed in ANY free cache line.
- 3. Set-Associative Mapping Cache is divided into sets (e.g., 2-way or 4-way).
View diagram · Cache Mapping Comparison
Associative Memory (Content Addressable Memory - CAM)
- In normal RAM, you provide an address number to get data: “Give me what is stored at address 500”.
- Hardware Registers: Argument Register (A): Holds the specific word or number you are searching for.
- Key / Mask Register (K): Chooses which bits to compare and which bits to ignore.
- Match Register (M): Has 1 bit for every row in memory.
- Where is CAM Used?: TLB (Translation Lookaside Buffer): In Virtual Memory to translate page addresses in 1 nanosecond.
- Internet Routers: To match destination IP addresses at Gigabit network speeds.
Virtual Memory, Paging, Address Translation, and Memory Interleaving
Overview: With pages of 1,024 bytes, virtual address 2,050 means page 2 and offset 2.
What is Virtual Memory?
- In early computers, if a heavy software or game required 16 GB of RAM but your computer only had 8 GB of RAM, the system would crash with an…
- It is a smart partnership between CPU hardware (the MMU - Memory Management Unit) and the Operating System (Windows/Linux).
- It creates the magic illusion that your computer has a massive, limitless pool of RAM.
- It does this by secretly using a section of your fast SSD or hard disk as an emergency overflow reservoir!
- An everyday example
- Think of your college study desk:
- Your small desk only has room for 4 notebooks at a time (like physical RAM).
- But you have 20 notebooks in your college bag under the desk (like the SSD).
Logical Address vs. Physical Address
- Logical (Virtual) Address: The memory address generated by the CPU while executing your program code.
- Physical Address: The actual hardware pin address in the physical DRAM chips.
Paging and Address Translation
- In a Paging system:
- Virtual memory is chopped into equal-sized blocks called Pages (typically 4 KB each).
- Physical RAM is chopped into slots of the exact same size called Page Frames.
- How Address Translation Works: The CPU gives a virtual address containing two parts: Page Number (
p) and Offset (d). - The Offset (
d) specifies the exact byte inside the page and passes straight through untouched. - The Page Number (
p) looks up an entry in the Page Table. - The Page Table returns the physical Frame Number (
f). - Combine
fanddto get the final real address in physical DRAM!
View diagram · Virtual-to-Physical Address Translation
What is a Page Fault?
- When the CPU requests a virtual page that is currently sitting on the SSD and has not yet been copied into physical RAM, a Page Fault occurs!
- 5-Step Page Fault Handling: Trap: The CPU hardware triggers an internal alarm called a Page Fault.
- Pause: The CPU halts the user program and calls the Operating System kernel.
- Locate on Disk: The OS finds the missing page on the secondary SSD.
- Frame Replacement: If physical RAM is full, the OS evicts an unused page using a replacement rule like LRU (Least Recently Used).
- Load & Resume: The missing page is copied into the empty RAM frame, the Page Table is updated, and the CPU restarts the trapped instruction!
Memory Interleaving
- Reading or writing to a DRAM memory chip requires a tiny recharge time.
- Low-Order Interleaving: Consecutive addresses are spread across different banks:
- Address 0 is in Bank 0
- Address 1 is in Bank 1
- Address 2 is in Bank 2
- Address 3 is in Bank 3
- Result: The CPU can read from all 4 banks at the exact same time, multiplying memory transfer speeds by up to 400%!
Ancient Manuscript Storage (Nalanda and Takshashila Libraries) and Modern Memory Hierarchy
Overview: Picture a manuscript kept in a distant storeroom and a working copy on a reader’s desk.
Introduction: Ancient Knowledge Systems Meet Computer Architecture
- In the official BCA Computer Architecture syllabus of Devi Ahilya Vishwavidyalaya (DAVV), students study a unique topic:
- They were written on delicate natural materials: palm leaves (Tāla-patra) and birch bark (Bhūrja-patra).
- Managing 9 million texts without computers required a brilliant multi-level storage hierarchy—just like the memory architecture inside our…
Ancient Library vs. Modern Computer Memory Hierarchy
- The grand library complex of Nalanda, named Dharmagañja (The Treasury of Truth), had three majestic nine-story buildings:
- Ratnasāgara (Ocean of Jewels)
- Ratnodadhi (Sea of Jewels)
- Ratnarañjaka (Jewel-Adorned)
- Scholar’s Study Desk Holds 1 or 2 active palm leaves being studied right now.
- Reading Hall Racks Holds frequently used reference scrolls for fast access.
- Main Granthāgāra Towers Nine-story organized shelves holding the active collection.
- Underground Stone Vaults Climate-safe sandalwood chests preserving master archive copies.
View diagram · Direct Structural Comparison: Ancient vs. Modern Memory
Grantha Indexing Methods vs. Computer Memory Addressing
- How did an ancient student find one specific text among 9 million palm-leaf scrolls?
- A. Granthas and Pattikā (Master Catalog) ↔ Virtual Memory Page Table: Ancient Method: Manuscripts were bundled between wooden boards called Granthas.
- Computer Equivalent: Just as the CPU uses a Page Table to translate a virtual address into a physical RAM frame, ancient librarians used…
- B. Colophons (Puṣpikā) ↔ Associative Memory (CAM): Ancient Method: The last page of an ancient scroll, called the Puṣpikā (Colophon), listed metadata: author, subject discipline (Vidyā),…
- Computer Equivalent: This is identical to Content Addressable Memory (CAM), where data is searched by its content attributes rather than a…
- C. Locality of Reference in Study Halls: Librarians kept root sutras and their famous commentaries together on the same shelf:
- When a scholar read Panini’s Sanskrit grammar, they almost always asked for Patanjali’s commentary right afterwards!
- Placing related scrolls side-by-side reduced walking time—the exact same principle as Spatial Locality of Reference in CPU cache design!
Comparison Table for DAVV Exams
- Storage Medium: Palm-leaf (Tāla-patra), Birch-bark (Bhūrja-patra)
- Fastest Level: Scholar’s study desk and nearby reading racks
- Main Working Level: Central shelves in 9-story towers
- Deep Storage Level: Underground sandalwood chests with insect-repellent neem leaves
- Address Indexing: Pattikā / Master Cataloging Boards
- Content Search: Puṣpikā (Colophon) keyword metadata tags