Unit 5: Input / Output
INPUT / OUTPUT (I/O) ORGANIZATION & INTERRUPTS
Peripheral Devices
Peripheral devices are external devices connected to the computer system to:
- Input data
- Output results
- Store data
They are slower than the CPU and main memory.
Types of Peripheral Devices
(a) Input Devices
Used to enter data into the system.
Examples:
- Keyboard
- Mouse
- Scanner
- Webcam
(b) Output Devices
Used to display results.
Examples:
- Monitor
- Printer
- Speaker
- Plotter
(c) Storage Devices
Used for secondary storage.
Examples:
- Hard disk
- Pen drive
- CD/DVD
I/O Interface
An I/O interface is a hardware unit that connects peripheral devices to the system bus.
Why I/O Interface is Needed
- Speed mismatch between CPU and devices
- Data format differences
- Control and status management
Functions of I/O Interface
- Data buffering
- Device control
- Error detection
- Synchronization
Components of an I/O Interface
- Data register
- Status register
- Control register
I/O Ports
An I/O port is a logical address through which the CPU communicates with an I/O device.
Types of I/O Ports
(a) Input Port - Receives data from external devices
(b) Output Port - Sends data to external devices
I/O Addressing Methods
(a) Memory-Mapped I/O
- I/O devices share address space with memory
- Uses same instructions as memory
Advantage: Flexible
Disadvantage: Reduces memory space
(b) Isolated I/O (Port-Mapped I/O)
- Separate address space for I/O
- Uses special I/O instructions
Advantage: Memory space saved
Disadvantage: Limited instructions
Interrupts
An interrupt is a signal that temporarily stops the CPU from executing the current program and transfers control to an Interrupt Service Routine (ISR).
Need for Interrupts
- Efficient CPU utilization
- Avoids constant polling
- Fast response to I/O devices
Interrupt Hardware
Interrupt Controller
- Manages multiple interrupt requests
- Determines priority
- Sends interrupt to CPU
Example: - Programmable Interrupt Controller (PIC)
Interrupt Vector Table
- Stores addresses of ISRs
- Used in vectored interrupts
Interrupt Handling Steps
- Interrupt request generated
- CPU completes current instruction
- CPU saves context (PC, registers)
- Control transferred to ISR
- ISR executed
- Context restored
- Program resumes
Types of Interrupts
Hardware Interrupts
Generated by external devices.
Examples:
- Keyboard interrupt
- Disk interrupt
Software Interrupts
Generated by program instructions.
Examples:
- System calls
- INT instruction
Maskable Interrupts
-
Can be disabled by CPU
Non-Maskable Interrupts (NMI)
- Cannot be disabled
- Used for critical errors
Vectored Interrupts
-
ISR address is predefined
Non-Vectored Interrupts
-
ISR address determined by software
Exceptions
An exception is an interrupt caused by internal CPU events during instruction execution.
Types of Exceptions
| Exception | Description |
|---|---|
| Divide by zero | Arithmetic error |
| Overflow | Result exceeds limit |
| Invalid opcode | Undefined instruction |
| Page fault | Page not in memory |
Interrupts vs Exceptions (Important Comparison)
| Feature | Interrupt | Exception |
|---|---|---|
| Source | External device | CPU/internal |
| Timing | Asynchronous | Synchronous |
| Example | Keyboard | Divide by zero |
Exam-Ready Summary Points
- Peripheral devices enable I/O operations.
- I/O interface bridges CPU and devices.
- I/O ports provide communication addresses.
- Interrupts improve CPU efficiency.
- Exceptions handle internal CPU errors.
Frequently Asked Exam Questions
- Explain I/O interface and its functions.
- Compare memory-mapped and isolated I/O.
- Explain interrupt hardware and handling.
- Types of interrupts with examples.
- Differentiate interrupts and exceptions.
MODES OF DATA TRANSFER
Programmed I/O, Interrupt-Initiated I/O, DMA, I/O Channels & I/O Processors
Data transfer refers to the movement of data between:
- CPU
- Main memory
- Peripheral devices
Because I/O devices are much slower than the CPU, special transfer modes are required to ensure efficiency.
Programmed I/O
In Programmed I/O, the CPU directly controls the data transfer by repeatedly checking the status of the I/O device.
This method is also called Polling.
Working of Programmed I/O
- CPU sends I/O command to device
- CPU checks device status repeatedly
- When device is ready, data is transferred
- CPU continues program execution
Characteristics
- CPU is fully involved
- No interrupts used
- Simple hardware
Advantages
- Easy to implement
- Low hardware cost
Disadvantages
- CPU time wasted in polling
- Very slow for large data transfer
Example: Reading a character from keyboard using polling.
Interrupt-Initiated I/O
In Interrupt-Initiated I/O, the CPU initiates the I/O operation and continues executing other tasks.
The device interrupts the CPU when it is ready.
Working of Interrupt-Initiated I/O
- CPU sends I/O command
- CPU continues other work
- Device generates interrupt when ready
- CPU saves context
- Interrupt Service Routine (ISR) transfers data
- CPU resumes normal execution
Characteristics
- CPU not continuously waiting
- Interrupt hardware required
Advantages
- Better CPU utilization
- Faster than programmed I/O
Disadvantages
- Interrupt handling overhead
- Not efficient for very large data blocks
Example:Printer interrupt after completing printing.
Direct Memory Access (DMA)
DMA allows an I/O device to transfer data directly to or from main memory without CPU involvement.
A special hardware unit called DMA Controller is used.
Working of DMA
- CPU initializes DMA controller
- DMA controller takes control of system bus
- Data transferred directly between device and memory
- DMA controller sends interrupt after completion
DMA Modes
- Burst Mode – transfers entire block at once
- Cycle Stealing – DMA steals memory cycles from CPU
- Transparent Mode – DMA works only when CPU is idle
Advantages
- Very high speed
- Minimal CPU involvement
- Best for large data transfer
Disadvantages
- Complex hardware
- Higher cost
Example: Hard disk data transfer.
Comparison of I/O Data Transfer Modes (Very Important Table)
| Feature | Programmed I/O | Interrupt I/O | DMA |
|---|---|---|---|
| CPU involvement | Full | Partial | Minimal |
| Speed | Slow | Medium | Very Fast |
| Hardware | Simple | Interrupt hardware | DMA controller |
| Efficiency | Poor | Better | Best |
| Data size | Small | Medium | Large |
I/O Channels
An I/O channel is a specialized processor that controls I/O operations independently of the CPU.
Types of I/O Channels
- Selector Channel - Controls one high-speed device at a time
- Multiplexer Channel - Controls multiple low-speed devices
Advantages of I/O Channels
- Offloads I/O work from CPU
- Increases system performance
I/O Processors
An I/O Processor (IOP) is a dedicated processor that executes I/O programs and manages devices.
Functions of I/O Processor
- Executes I/O instructions
- Handles interrupts
- Performs error checking
- Controls data transfer
Difference Between DMA and I/O Processor
| Feature | DMA | I/O Processor |
|---|---|---|
| Intelligence | Limited | High |
| Program execution | No | Yes |
| Control | Block transfer only | Complete I/O management |
Exam-Ready Summary
- Programmed I/O uses polling and wastes CPU time.
- Interrupt I/O improves CPU efficiency.
- DMA is best for large, high-speed transfers.
- I/O channels and processors further reduce CPU workload.
Most Important Exam Questions
- Explain Programmed I/O with diagram.
- Compare Programmed I/O, Interrupt I/O, and DMA.
- Explain DMA controller and its modes.
- What are I/O channels and their types?
- Differentiate DMA and I/O Processor.
SERIAL COMMUNICATION
Synchronous & Asynchronous Communication, Standard Communication Interfaces
Serial communication is a method of data transfer in which bits are transmitted one after another over a single communication line.
It is widely used because:
- Requires fewer wires
- Suitable for long-distance communication
- Low cost and reliable
Examples:
- USB
- RS-232
- Ethernet
Types of Serial Communication
Serial communication is broadly classified into:
- Synchronous Communication
- Asynchronous Communication
Synchronous Communication
In synchronous communication, data is transmitted continuously in blocks or frames with the sender and receiver sharing a common clock signal.
Working of Synchronous Communication
- Sender and receiver are synchronized by a clock
- Data is sent as a continuous stream
- No start and stop bits are used
Characteristics
- High data transfer speed
- Clock synchronization required
- Efficient for large data transfer
Advantages
- Faster transmission
- Less overhead
- High efficiency
Disadvantages
- Complex hardware
- Clock synchronization required
Examples
- SPI (Serial Peripheral Interface)
- I²C (Inter-Integrated Circuit)
- Ethernet
Asynchronous Communication
In asynchronous communication, data is transmitted one character at a time, and no common clock is shared.
Each character is framed with start and stop bits.
Working of Asynchronous Communication
- Sender adds start bit before data
- Stop bit is added after data
- Receiver detects start bit to synchronize
Characteristics
- Uses start and stop bits
- Slower than synchronous communication
- Simple design
Advantages
- Simple hardware
- No clock synchronization needed
- Suitable for low-speed communication
Disadvantages
- Extra bits increase overhead
- Lower efficiency
Examples
- RS-232
- UART communication
- Keyboard communication
Comparison Between Synchronous and Asynchronous Communication
(Very Important for Exams)
| Feature | Synchronous | Asynchronous |
|---|---|---|
| Clock | Shared | Not shared |
| Data transfer | Continuous | Character-wise |
| Speed | High | Low |
| Overhead | Low | High (start/stop bits) |
| Complexity | High | Low |
| Examples | SPI, I²C | RS-232, UART |
Standard Communication Interfaces
RS-232
- Asynchronous communication standard
- Used for serial ports
- Point-to-point communication
- Low speed and short distance
USB (Universal Serial Bus)
- High-speed serial interface
- Plug-and-play support
- Supports multiple devices
SPI (Serial Peripheral Interface)
- Synchronous communication
- Master-slave architecture
- High speed and full duplex
I²C (Inter-Integrated Circuit)
- Synchronous communication
- Uses only two lines (SDA & SCL)
- Supports multiple devices
Ethernet
- High-speed serial communication
- Used in computer networks
- Reliable and scalable
Summary Table of Standard Interfaces
| Interface | Type | Speed | Usage |
|---|---|---|---|
| RS-232 | Asynchronous | Low | Serial ports |
| USB | Both | High | Peripheral connection |
| SPI | Synchronous | Very High | Embedded systems |
| I²C | Synchronous | Medium | Chip-to-chip |
| Ethernet | Synchronous | Very High | Networking |
Exam-Ready Key Points
- Serial communication sends data bit by bit.
- Synchronous communication uses a shared clock.
- Asynchronous communication uses start and stop bits.
- RS-232 is asynchronous, SPI and I²C are synchronous.
- USB and Ethernet support high-speed data transfer.
Frequently Asked Exam Questions
- Explain serial communication with advantages.
- Differentiate synchronous and asynchronous communication.
- Explain RS-232 interface.
- What are standard serial communication interfaces?
- Compare SPI and I²C.