Computer Science and IT‹›⌂ 0:00 studied

Module 3 · 12 min read · Free chapter

I/O interface: interrupts and DMA

In short

Programmed I/O makes the CPU poll the device, interrupts let the device call the CPU when ready, and DMA moves whole blocks with one interrupt at the end. In daisy chaining the device nearest the CPU has top priority, and cycle stealing takes one bus cycle per word.

See it in 3DI/O, interrupts and DMA on a motherboard. Turn it, cut it open, or just press Watch.
What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: the teacher and the notebooks

Imagine a teacher who has given homework to forty students. She can walk from desk to desk asking "Are you done?", which wastes most of her time on students who are not ready. Or she can keep teaching and let each student raise a hand when done, stopping only for those who need her.

There is a third way for a big job. She asks the class monitor to carry all forty notebooks to the staff room and to tell her only when the whole pile is there, while she carries on teaching.

A computer faces the same choice with its input and output devices. Asking a device again and again is programmed I/O, a raised hand is an interrupt, and the monitor carrying the whole pile is direct memory access (DMA). This chapter explains all three and when each one pays off.

Why it matters. Keyboards, disks and network cards are thousands to millions of times slower than the processor. How the CPU talks to them decides whether it spends its time computing or waiting, and GATE asks you to put numbers on that cost.

The device interface and how devices are addressed

A device cannot be wired straight onto the system bus. It is far slower than the CPU, it may send data one bit at a time, and it uses its own control signals, so an I/O interface (device controller) sits in between. The CPU sees the device only through a few registers in this interface.

A typical interface has three registers. The data register holds the byte or word being moved, the status register has flags such as "ready" or "error", and the control register takes commands such as "start reading". The CPU drives the device by writing commands and data and by reading status.

There are two ways to give these registers addresses. In memory-mapped I/O the device registers take some addresses in the ordinary memory space, so the same load and store instructions and addressing modes work on them. In I/O-mapped I/O, also called isolated I/O, devices have their own small address space reached by special IN and OUT instructions, and a control line tells memory cycles from I/O cycles.

Point Memory-mapped I/O I/O-mapped I/O
Address space Shared with memory Separate I/O space
Instructions Ordinary load and store Special IN and OUT
Memory left for RAM Reduced by device addresses Not reduced
Typical use Most RISC processors x86 family, along with memory mapping

Why it matters. Memory-mapped I/O keeps the instruction set small, which is why RISC designs prefer it. Exams ask which scheme needs special instructions and which one uses up memory addresses.

Programmed I/O and the cost of polling

In programmed I/O the CPU runs a small loop. It reads the status register, checks the ready bit, and if the device is not ready it reads the status again; once ready, it moves one data item and repeats until the job is done. This repeated checking is called polling or busy waiting.

The method needs no extra hardware, but the CPU does nothing useful while it waits. The cost of polling is easy to compute: count the polls or transfers per second, multiply by the cycles each one takes, and compare with the clock rate.

Worked example. A device sends data at 2 MB/s, taken as 2×1062 \times 10^6 bytes per second, and each poll that finds data moves 4 bytes. It needs 5×1055 \times 10^5 transfers per second, and if each poll and transfer takes 200 cycles on a 1 GHz CPU, the load is as follows.

5×105×200109=108109=0.1\frac{5 \times 10^5 \times 200}{10^9} = \frac{10^8}{10^9} = 0.1

So 10 percent of the CPU goes into just keeping up with this one device. For a mouse polled 30 times a second at the same cost, the share is only 30×200109\dfrac{30 \times 200}{10^9}, which is negligible.

Why it matters. Polling is fine for slow or rare events and wasteful for fast devices. That contrast is the reason interrupts and DMA exist, and GATE uses exactly this kind of percentage question to test it.

Interrupt-driven I/O

With interrupts, the CPU starts the device and goes back to its own work. When the device is ready it raises an interrupt request line. The CPU finishes the instruction it is running, saves the program counter and the status flags, usually on the stack, and jumps to an interrupt service routine (ISR) that moves the data.

At the end, the ISR runs a return-from-interrupt instruction, which restores the saved PC and flags. The main program then continues exactly where it stopped, without knowing it was interrupted. The time from the request to the start of the ISR is the interrupt latency.

How does the CPU find the right ISR? With a vectored interrupt the device places a vector on the bus, an address or an index into a table of ISR addresses, so the CPU jumps straight to the right routine. With a non-vectored interrupt the CPU always jumps to one fixed address, and that code must poll the devices to find out who called.

The CPU can mask (disable) ordinary interrupts during critical work. A non-maskable interrupt (NMI) cannot be disabled and is kept for emergencies such as a power failure. With nested interrupts, a request of higher priority may interrupt an ISR that is already running.

Worked example. A device delivers 10⁵ bytes per second, one byte per interrupt, and each interrupt costs 2 µs of CPU time including saving and restoring state. The CPU then spends 105×2 μs=0.2 s10^5 \times 2\ \mu\text{s} = 0.2\ \text{s} of every second, that is 20 percent, on this device.

Why it matters. Interrupts free the CPU from waiting, but each one has a fixed overhead. For a fast device the overhead per byte adds up, which is exactly what DMA removes.

Priority interrupts and daisy chaining

When several devices ask at once, someone must choose who goes first. There are three common schemes.

Software polling checks the devices one by one in a fixed order inside a common ISR, and the first device found requesting is served. It needs no extra hardware but is slow when many devices are attached.

Daisy chaining is a hardware method. All devices share one interrupt request line, and the CPU's interrupt acknowledge signal passes through the devices one after another. A device that is requesting keeps the acknowledge and places its vector on the bus, while a device that is not requesting passes it on, so the device nearest the CPU has the highest priority.

Daisy chaining is simple and cheap, and adding a device needs only one more link. But its priority is fixed by position, a busy device near the CPU can starve those further away, and the acknowledge takes longer to ripple through a long chain.

A parallel priority interrupt unit gives each device its own request line into a priority encoder, which outputs the number of the highest requesting device. A mask register can enable or disable each line, so priorities can be managed by software.

Why it matters. Priority decides which device waits, and a wrong choice can lose data from a fast device. Exams ask for the advantages and limits of daisy chaining more than any other scheme.

Direct memory access and its numericals

For a fast device such as a disk, even one interrupt per word is too much. Direct memory access (DMA) lets a DMA controller move a whole block between the device and memory while the CPU does other work. The CPU only sets it up at the start and handles one interrupt at the end.

The CPU writes three things into the controller: the starting memory address, the word count and the direction of transfer. The controller then raises bus request (often called HOLD), the CPU finishes its current bus cycle and answers with bus grant (HLDA), and the controller drives the bus itself. After each word it increases the address and decreases the count, and when the count reaches zero it interrupts the CPU.

There are three modes. In burst (block) mode the controller keeps the bus until the whole block is moved, which is fastest for the transfer but locks the CPU off the bus. In cycle-stealing mode it takes the bus for one word at a time, slowing the CPU slightly, and in transparent mode it uses only cycles in which the CPU does not need the bus.

Worked example 1. A device delivers 10⁵ bytes per second, and in cycle-stealing mode each byte steals one 20 ns bus cycle. The stolen time is 105×20 ns=2 ms10^5 \times 20\ \text{ns} = 2\ \text{ms} per second, only 0.2 percent, against 20 percent for one interrupt per byte at 2 µs each.

Worked example 2. A 4 KB block of 4,096 bytes moves in burst mode over a bus that carries 4 bytes in each 10 ns cycle. The burst needs 1,024 cycles, so the CPU is locked off the bus for 10.24 µs.

Worked example 3. A device takes XX = 2 ms to fill its buffer and then YY = 20 µs to burst it to memory. The CPU loses the bus for a fraction YX+Y=202020≈0.0099\dfrac{Y}{X + Y} = \dfrac{20}{2020} \approx 0.0099 of the time, about 1 percent.

Worked example 4. The DMA controller has a 16-bit word-count register and memory is byte-addressable. One grant can move at most 2162^{16} bytes, which is 64 KB, so a 1,000 KB file needs ⌈100064⌉=⌈15.625⌉=16\lceil \dfrac{1000}{64} \rceil = \lceil 15.625 \rceil = 16 bus grants.

Why it matters. DMA is how disks, network cards and graphics transfers work without swamping the CPU. GATE regularly asks for the CPU time lost in a DMA mode or the number of times the controller must take the bus.

Descriptive lens: how written papers ask this

Written papers for engineering services, IT officer posts and state Assistant Programmer exams ask about this topic in four ways:

  1. Compare programmed, interrupt-driven and DMA transfer, usually with a table or a timing argument.
  2. Explain the steps the CPU takes on an interrupt, and the meaning of vectored, maskable and nested interrupts.
  3. Draw and explain daisy chaining or a priority encoder scheme with its merits and limits.
  4. Describe a DMA controller, its registers and its burst and cycle-stealing modes, often with a numerical.

Practice questions (our own, not previous-year questions).

  1. Compare memory-mapped and I/O-mapped I/O under four heads, and say which one most RISC processors use and why. (10 marks)
  2. Explain daisy-chained priority interrupts with a diagram, and state two advantages and two drawbacks. (10 marks)
  3. Describe the working of a DMA controller with a block diagram, and compare burst and cycle-stealing modes with a numerical example. (15 marks)

Answer plan for question 3.

  • Begin by stating that DMA moves a block between a device and memory without the CPU moving each word.
  • Draw the CPU, memory, DMA controller and device on one bus, with bus request and bus grant lines.
  • Name the controller's address, word-count and control registers, and explain how the CPU loads them.
  • Describe the transfer: bus request, bus grant, one word at a time with the address increased and count decreased, and an interrupt at zero.
  • Compare burst mode, which holds the bus for the whole block, with cycle stealing, which takes one bus cycle per word.
  • Work a short example, such as 10⁵ bytes per second stealing one 20 ns cycle each, to show a 0.2 percent loss.
  • Conclude that DMA suits fast block devices, while interrupts suit slow devices with small transfers.

Quick revision

  • An I/O interface has data, status and control registers and hides the device's speed and format.
  • Memory-mapped I/O uses load and store in the memory space, while isolated I/O uses IN and OUT in a separate space.
  • Programmed I/O polls a status flag, and its CPU cost is polls per second times cycles per poll over the clock rate.
  • On an interrupt the CPU finishes the current instruction, saves PC and flags, runs the ISR and returns.
  • A vectored interrupt supplies the ISR address, and an NMI cannot be masked.
  • Daisy chaining passes the acknowledge serially, so the device nearest the CPU has top priority.
  • A DMA controller holds address, count and control, uses bus request and grant, and interrupts at the end.
  • Burst mode holds the bus for a whole block, and cycle stealing takes one bus cycle per word.
  • With an nn-bit count register, a transfer of FF units needs ⌈F2n⌉\lceil \dfrac{F}{2^n} \rceil grants.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 13 answered

  1. Which register of an I/O interface tells the CPU whether the device is ready?

  2. Special IN and OUT instructions are used in:

  3. Which scheme reduces the address space available for RAM?

  4. A device needs 5×1055 \times 10^5 polls per second, each taking 200 cycles, on a 1 GHz CPU. The fraction of CPU time used is:

  5. On an interrupt, the CPU first:

  6. A device causes 10510^5 interrupts per second, each costing 2 µs. The CPU time used is:

  7. In a vectored interrupt, the address of the service routine is supplied by:

  8. Which interrupt cannot be disabled by the CPU?

  9. In a daisy-chained priority scheme, the highest priority goes to the device:

  10. At the end of a DMA block transfer, the DMA controller:

  11. In which DMA mode is the CPU kept off the bus until the whole block is moved?

  12. A DMA controller has a 16-bit count register and memory is byte-addressable. The minimum number of bus grants for a 1,000 KB file is:

  13. A device takes 2 ms to fill its buffer and 20 µs to burst it to memory. The fraction of time the CPU loses the bus is about:

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the difference between memory-mapped and isolated I/O?

Memory-mapped I/O puts device registers in the memory address space and uses load and store, while isolated I/O uses a separate space with IN and OUT instructions.

What happens when an interrupt arrives?

The CPU finishes the current instruction, saves the PC and flags, runs the service routine and then returns to the program.

What is daisy chaining?

It is a hardware priority scheme where the interrupt acknowledge passes from device to device, so the device nearest the CPU gets the highest priority.

How is burst mode DMA different from cycle stealing?

Burst mode holds the bus for the whole block, while cycle stealing takes the bus for one word at a time and only slows the CPU slightly.

More in this module: Computer organisation and architecture

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Computer Organization and Architecture (IIT Madras, 106106166): input-output organisation, interrupts and DMA