22-Elec-A4 Digital Systems and Computers · December 2014
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Paper format. National Exams, December 2014 — 07-Elec-A4, Digital Systems & Computers. Three hours, closed book (one approved Casio or Sharp calculator). Six questions, each worth 12 marks; the rubric states that five questions constitute a complete paper. A table of Boolean identities and a flip-flop excitation table are supplied with the paper. All six questions are solved below, because this set is intended as a study resource rather than a timed attempt.
Reference texts.
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
The system has two distinct interfaces, and the question deliberately treats them separately. On the processor side, the CPU and the I/O interface communicate over the data bus, with control signals outbound and an interrupt request inbound. On the device side, the interface and the peripheral exchange data over the data lines, coordinated by the two protocol signals H1 and H2.
The two methods by which a program makes the CPU aware that the interface has new data, or is ready to accept data, are polling (programmed I/O) and interrupt-driven I/O.
Under polling, the processor takes the initiative. The interface maintains a status register containing flags such as READY or DATA AVAILABLE, and the program executes a tight loop that repeatedly reads that register and tests the flag. When the flag is finally set, the program falls out of the loop and executes the data-transfer instruction that reads the input register or writes the output register. The transfer itself is performed by ordinary load and store instructions to the memory-mapped interface addresses; nothing is transferred until the CPU asks. The scheme is simple to write, needs no additional hardware beyond the status flag, and gives entirely predictable timing, which is why it is still used in small dedicated controllers and in initialisation code.
Under interrupt-driven I/O, the interface takes the initiative. When the device sets the condition the CPU cares about, the interface asserts the IRQ line shown in the figure. The processor completes the instruction in progress, saves the program counter and status register, and vectors to an interrupt service routine that performs the transfer and clears the interrupt source before returning. Between interrupts the CPU is free to execute unrelated work, so the processor and the device proceed concurrently.
The more efficient method is interrupt-driven I/O, and the reason is the enormous mismatch between processor and peripheral speeds. A peripheral such as a keyboard, a printer or a serial link delivers events on a millisecond timescale, while the processor executes an instruction in microseconds or less. A polling loop therefore spends essentially all of its iterations reading a flag that is still clear: the CPU is fully occupied but performs no useful work, and that wasted time scales with how slow the device is. Interrupt-driven transfer replaces that busy-wait with a single hardware signal, so the only processor time charged to the device is the interrupt latency plus the service routine itself. The gain grows with the number of devices, because one polling loop must interrogate every device in turn whereas interrupts arrive only from the device that actually needs service, already identifying itself through its vector.
The advantage is not unconditional, and a complete answer should say so. Interrupts carry a fixed overhead for saving and restoring context, so for a device that is nearly always ready — or when the CPU has nothing else to do — polling can transfer a block faster and with lower latency. Interrupts also introduce concurrency, and therefore the need for priority arbitration and for care over shared data. For sustained high-rate transfers both methods are eventually displaced by direct memory access, in which a DMA controller moves the block and interrupts the CPU only once at completion.
The two protocols used between the I/O interface and the external device are the strobe (one-way, non-interlocked) protocol and the handshake (interlocked) protocol. In the strobe protocol only one of the two signals is used: the sender places data on the lines and issues a single timing pulse to announce it, and simply assumes the receiver keeps up. There is no reply, so the sender learns nothing about whether the data was taken; the scheme is fast and cheap but only safe when the receiver's timing is known in advance. In the handshake protocol both H1 and H2 are used, and each transition of one signal is a response to a transition of the other. This makes the exchange self-timed: it runs at the speed of the slower party and cannot overrun, at the cost of two round trips per byte. The fully interlocked form described below is the one normally meant by "handshake".
INPUT of data (device to interface). Here the external device is the source, so it owns the data lines and the VALID DATA signal, while the interface replies. The sequence is:
OUTPUT of data (interface to device). The direction of the data reverses, and with it the ownership of the two signals — but the roles stay attached to the same signal names, with H1 always driven by the sender of the data and H2 by the receiver:
The symmetry is the point worth stating explicitly: in both directions H1 signals VALID DATA and is driven by whichever party is sending, while H2 signals ACKNOWLEDGEMENT and is driven by whichever party is receiving. What changes between input and output is not the meaning of the signals but which side of the interface drives each one. Because every edge in the sequence is caused by the preceding edge, neither party can run ahead of the other, and the transfer rate adapts automatically to the slower device — the property that makes the interlocked handshake safe across a cable of unknown length, where the strobe protocol is not.
| Item | Answer |
|---|---|
| (a) The two methods | Polling (programmed I/O) and interrupt-driven I/O |
| (a) More efficient | Interrupt-driven — removes the busy-wait, so CPU time is charged only for the service routine |
| (b) i. Two protocols | Strobe (non-interlocked) and handshake (fully interlocked) |
| (b) ii. INPUT | H1 = VALID DATA (from device); H2 = ACKNOWLEDGE (from interface) |
| (b) ii. OUTPUT | H1 = VALID DATA / DATA READY (from interface); H2 = ACKNOWLEDGE (from device) |
| General rule | H1 is always driven by the sender, H2 always by the receiver |