Saturday, June 23, 2018

How does Input/Output work in a Processor with basic Keyboard Monitor example

When we press a key on keyboard how does processor tells monitor to display that key, this example is directly taken from book by Carl Hamacher.

We know that processor, keyboard and monitor are connected via a bus structure, as rate of data transfer from keyboard to processor is limited few characters per second which is not likely to exceed. While rate of transfers from processor to display is much higher, typically few thousand characters per second, but this is still much slower than a processor which can execute many millions of instructions per second. So a mechanism is used to synchronise this transfer.

Solution is : On output side, processor sends a character and waits for a confirmation signal form display that it has received that character then sends another character. On input, processor waits till a character key is struck on keyboard and its available in some kind of buffer register. Then processor read that character and waits for next key to be struck on input.



So we need buffer registers on both input/output devices of 8-bits, as ASCII needs at-least 7-bits to represent, and a status control flag on both input/output to actually know when to read or write. Lets assume DIN a buffer register and SIN a status control flag for it to inform processor that it holds a character. SIN is 1 when DIN holds a value and is automatically cleared to 0 after processor transfers that value. This process is repeated to to get a stream of characters from a input device, in this case keyboard. Similar process takes place at display, assume DOUT is a buffer register and SOUT is status control flag. SOUT is 1 when display is ready to receive a character, then contents form processor are transferred to DOUT and SOUT is cleared 0; when display is ready to receive another character SOUT is set to 1 and process continues.

We assume initial state of SIN is 0 and SOUT is 1. Processor is branched to a wait loop until value of SIN is set to 1 on input side and on output side it waits till SOUT is 1 by initial condition its always ready to transfer data but when keyboard key is struck and character is transferred to processor and it goes in a wait loop till another key is struck. Similarly in display when a character is transferred to it from processor wait loop starts until it is ready for another character.
This is only basic of how a processor handles input/output but in actual computers this is done more efficiently and with many more registers. If you are interested in assembly code for this process please comment.

Suggestions:-

Amit's post: Computer basics input device and output

1 comment: