Page 1 of 2
The computer is a very simple machine and yet it can do complicated things. This is a consequence of the fact that, even if you can only do something very simple, if you can do it fast enough then it can seem as complicated as you like! In the case of the digital computer the trick is getting it to divide its attention between a number of tasks – like a juggler keeping a set of balls in the air.
Back in the early days of computing it was enough of a job to get the machine built at all without having to worry about how it could be used efficiently but as time went on it became clear that this was a real problem. You spend so much money on a computer and then it sits there not computing for most of its working life. For example, imagine what happens when it tries to print some letters on a printer. It takes, say, 0.1 of a second. The printer can print at 600 characters per minute so it’s very fast for a printer. But the computer is working with a clock cycle of say 100MHz (slow by todays standards), which means it can execute an instruction in 0.00000001s. So in the time it has to wait for the printer to print another character, i.e. 0.1s, it could have performed 10 million instructions.
If this doesn’t seem a waste to you then let’s stretch the time scale just a little. Suppose the new time scale is such that each beat of the machine’s clock is one second then in this new time scale the printer takes just short of 4 months to print a character. So in this sense the computer does one second’s work and then has 4 months off doing nothing at all...
Four months doing nothing after every character is printed – it’s a good life being a computer
Whenever a computer has to interact with the outside world, be it to read in data from a disk drive or write data to a printer or video screen, it generally has a long wait. In the early days the sense in trying to recover all that unused time was an economic imperative.
The solution involved some software and some hardware. The software had to manage what the processor did while it was waiting; the hardware had to make sure that the processor knew when it was safe to go off and do something else. The details of the software take us into all of the ideas of the multi-tasking/multi-user operating system. The hardware, however, is worth looking at on its own.
It is difficult to say who invented the interrupt because it’s one of those obvious things that really don’t need too much invention. (If anyone knows who, when and where the interrupt was invented please email me with the details.) The idea is simply that external hardware that operates at lower speeds than the electronics of the processor is provided with a connection – an interrupt line – that can be used to stop the processor doing whatever it is doing and get it to pay some attention to the needs of the peripheral. This might seem like the wrong way round from our first discussion of how everything works but it is much better to let the external hardware say when it needs attention than to say when it is busy.
For example, the steps in sending some data to a printer would be:
1) Send a character to the printer. At this point it is clear that there is going to be a long wait until the next character can be sent so
2) Get on with some other task while the printer is busy.
3) When the printer has printed the character it signals using the interrupt line that it needs attention.
4) The program responds to the interrupt and goes back to the printer routine and sends another character.
This sounds all very easy but there are some really difficult problems in this sequence of actions which have taken many years to sort out. The key factor is that the processor has to be able to make a task switch, both when moving away from the printer routine and when moving back to it in response to the interrupt.
Task switching is difficult because you have to be able to guarantee that task one will not do anything to upset task two and vice versa. At the deepest hardware level this means that the processor’s registers have to be shared and so too does the main memory and every hardware device connected to it.
While waiting for an interrupt the machine can get on with something else!