Explain the various modes of data transfer and discuss direct memory access mode in detail. Also explain how DMA is superior to other modes.
Explain the various modes of data transfer and discuss direct memory access mode in detail. Also explain how DMA is superior to other modes.
Quick answer
There are three modes of data transfer between the CPU, memory and I/O devices.
Modes of data transfer
Programmed I/O. The CPU runs a program that polls the status flag of the device. When the device is ready, the CPU moves one word. The CPU is busy waiting for the whole time, which wastes its power.
Interrupt-initiated I/O. The device interrupts the CPU when it is ready. The CPU saves its state, runs the service routine to move a word, and returns. The CPU is free between interrupts, but each word costs the time of an interrupt.
Direct memory access (DMA). A DMA controller moves a whole block between the device and memory, without involving the CPU in each word.
Direct memory access in detail
The CPU first loads the DMA controller with the starting memory address, the word count and the direction of the transfer, and then goes on with its work.
When the device is ready, it sends a DMA request to the controller. The controller sends a bus request to the CPU. The CPU completes the present cycle, puts its buses in the high impedance state, and sends back a bus grant. The controller now controls the buses. It places the memory address on the address bus, activates the read or write signal, and the word passes between the device and memory.
After each word, the address register increases by one and the word count decreases by one. The cycle is repeated until the count is zero. The controller then removes the bus request and interrupts the CPU to say that the block is finished.
DMA can work in burst mode, where the whole block is moved at one go. It can also work in cycle stealing mode, where one word is moved and the bus is given back to the CPU each time.
Why DMA is better than the other modes
| Point | Programmed | Interrupt-initiated | DMA |
|---|---|---|---|
| CPU involvement | Every word | Every word | Start and end only |
| Speed of transfer | Slow | Medium | Fast |
| CPU waiting | Busy waits | Free, but with overhead | Free for the whole block |
| Best for | Simple tasks | Slow devices | Disks, bulk data |
In programmed I/O the CPU is occupied by waiting. In interrupt-initiated I/O the CPU is not waiting, but it spends time saving and restoring state for each word, and the rate of transfer is limited by this. In DMA, the data goes straight to memory at the speed of the device and memory. The CPU only sets up the transfer and handles one interrupt at the end. Therefore DMA is the best choice for large blocks of data, and it gives the best use of the CPU. Its only costs are the extra hardware of the controller and some bus sharing.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextList the steps involved in an instruction cycle.