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

  1. Interrupt request generated
  2. CPU completes current instruction
  3. CPU saves context (PC, registers)
  4. Control transferred to ISR
  5. ISR executed
  6. Context restored
  7. 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

ExceptionDescription
Divide by zeroArithmetic error
OverflowResult exceeds limit
Invalid opcodeUndefined instruction
Page faultPage not in memory

Interrupts vs Exceptions (Important Comparison)

FeatureInterruptException
SourceExternal deviceCPU/internal
TimingAsynchronousSynchronous
ExampleKeyboardDivide 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

  1. Explain I/O interface and its functions.
  2. Compare memory-mapped and isolated I/O.
  3. Explain interrupt hardware and handling.
  4. Types of interrupts with examples.
  5. 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

  1. CPU sends I/O command to device
  2. CPU checks device status repeatedly
  3. When device is ready, data is transferred
  4. 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

  1. CPU sends I/O command
  2. CPU continues other work
  3. Device generates interrupt when ready
  4. CPU saves context
  5. Interrupt Service Routine (ISR) transfers data
  6. 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

  1. CPU initializes DMA controller
  2. DMA controller takes control of system bus
  3. Data transferred directly between device and memory
  4. 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)

FeatureProgrammed I/OInterrupt I/ODMA
CPU involvementFullPartialMinimal
SpeedSlowMediumVery Fast
HardwareSimpleInterrupt hardwareDMA controller
EfficiencyPoorBetterBest
Data sizeSmallMediumLarge

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

  1. Selector Channel - Controls one high-speed device at a time
  2. 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

FeatureDMAI/O Processor
IntelligenceLimitedHigh
Program executionNoYes
ControlBlock transfer onlyComplete 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

  1. Explain Programmed I/O with diagram.
  2. Compare Programmed I/O, Interrupt I/O, and DMA.
  3. Explain DMA controller and its modes.
  4. What are I/O channels and their types?
  5. 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:

  1. Synchronous Communication
  2. 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)

FeatureSynchronousAsynchronous
ClockSharedNot shared
Data transferContinuousCharacter-wise
SpeedHighLow
OverheadLowHigh (start/stop bits)
ComplexityHighLow
ExamplesSPI, I²CRS-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

InterfaceTypeSpeedUsage
RS-232AsynchronousLowSerial ports
USBBothHighPeripheral connection
SPISynchronousVery HighEmbedded systems
I²CSynchronousMediumChip-to-chip
EthernetSynchronousVery HighNetworking

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

  1. Explain serial communication with advantages.
  2. Differentiate synchronous and asynchronous communication.
  3. Explain RS-232 interface.
  4. What are standard serial communication interfaces?
  5. Compare SPI and I²C.