2019 20 2e

Computer Organization and Architecture2019-2010 marksModes of Data Transfer

What is DMA? Describe how DMA is used to transfer data from peripherals.

What is DMA? Describe how DMA is used to transfer data from peripherals.

Quick answer

Direct Memory Access (DMA) is a method in which an I/O device transfers a block of data directly to or from main memory without passing each word through the CPU. A special hardware unit called the DMA controller takes charge of the memory buses for the duration of the transfer. This is much faster than programmed or interrupt-driven I/O, because the CPU does not execute instructions for every word.

How the DMA controller is organised

The controller has an address register, a word count register, a control register and a data buffer. It also has request and grant lines to the CPU and the device.

The address register holds the memory location of the next word. The word count register holds the number of words still to move. The control register holds the direction (read or write) and the mode of transfer.

How a transfer takes place

First, the CPU initialises the controller. It writes the starting memory address into the address register, the number of words into the word count register, and the direction into the control register. After this the CPU carries on with other work.

When the device is ready, it raises a DMA request to the controller. The controller then sends a bus request (HOLD) to the CPU. The CPU finishes its current bus cycle, floats its address, data and control buses to the high impedance state, and replies with a bus grant (HLDA).

Now the controller owns the buses. It puts the address from its address register on the address bus. It then activates the memory read or write signal and the DMA acknowledge to the device. The word moves directly between the device and memory.

After each word the controller increments the address register and decrements the word count register. This repeats until the count becomes zero.

When the count reaches zero, the controller releases the buses by removing the bus request. It also sends an interrupt to the CPU to say that the whole block has been transferred. The CPU then resumes normal control of the buses.

Modes of DMA transfer

In burst (block) mode, the controller keeps the bus until the whole block is moved. In cycle stealing mode, it takes the bus for one word at a time and gives it back, so the CPU is slowed only slightly. In transparent mode, it uses the bus only when the CPU is not using it.

Advantages

DMA gives a high transfer rate and frees the CPU from word-by-word work. It is the best method for fast devices like disks. Its cost is the extra hardware of the controller.

A small example

Suppose a disk must write 512 words into memory starting at address 2000. The CPU loads 2000 into the address register and 512 into the word count register, sets the direction to "write to memory", and starts the controller. The CPU then runs another program. The controller moves all 512 words, one after another, and finally interrupts the CPU. The CPU spent time only on the set-up and on the final interrupt, not on 512 separate transfers.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.

Up nextDescribe in detail the different kinds of addressing modes with an example.