Interrupts

Posted 06 Jun 2024

I stumbled across a description of how an “interrupt” was implemented on the EDSAC 1. And I found an interesting parallel with the machine which taught me how computers worked.

EDSAC 1 Interrupts

Someone got the idea that since tape was slow and the machine was fast, it would be nice if a command to advance the tape to a specific position didn’t have to take up a long block of time that could be used for calculations.

The scheme they came up with was to have a routine that would count each block of data as it moved past the read head on the tape drive. So if the data you were looking for started at block 10, you’d count blocks from the start of the tape until you got to block 10. Then you’d do whatever I/O operation was needed.

The built a routine into the machine which would do the counting, increment the counter, and optionally jump to whatever code needed to read/write that block. They wired the machine so that whenever a block came under the read head, it would flip a relay in the machine.

The “counter” routine would check that relay state, and check to see if this was the wanted block. If not, it would release control and the machine would resume it’s previous activities. If it was the desired block, it would jump to the code which wanted to process that block, and then return to normal operations.

By this means, the machine could be performing calculations while the tape drive was advancing, only pausing briefly when a new block arrived. A more efficient use of the system. And since running a computer cost a lot of money back then, getting more done in less time saved a lot of money.

OK, but how did the system arrange to interrupt the current processing? The answer was simple: just insert a jump to the “counter” routine repeatedly throughout the main program. Knowing how long it takes to move the tape through the length of a block, you could space those jumps so that they were never further apart than that time. This guarantees you won’t miss a new block.

One small issue: every program you want to run has to have this jump instruction inserted throughout its code. Not ideal, but it did provide the efficiency everyone wanted, so the trade-off was accepted.

It’s not an interrupt in the modern sense, but it’s easy to see how this klunky system would inspire designers to build hardware to make this work without the trade-off of polluting all programs.

The Apple //e

This is the machine I bought when I wanted to lean what these new-fangled “computer” thingies were all about. I picked that machine, instead of the brand-new IBM PC, because I’d been to computer stores, and knew that there were lots of books with explanations of how all the hardware was built.

This was in addition to the 5 books that came with every Apple //e, right in the box. One was the Technical Reference manual, which had the source code for the firmware, and complete electrical schematics. That was normal at the time. Even the IBM PC had a similar manual, although they fudged things a bit to make it hard to create your own machine from those docs.

I’ll fast-forward through my stumbling around trying to learn to use it, let alone understand it.

The Apple ][ line had the keyboard integrated into the case. This keyboard was wired directly to the main board, and the firmware was responsible for detecting a key press, and copying the key code into a buffer. A modern computer would simply trigger an interrupt on each key (in fact on both key press and key release events). The hardware then runs the keyboard drive to service this interrupt and handle the key.

But the Apple //e did not use an interrupt for this. Instead, there was a routine in the firmware (“Monitor ROM”), which would check to see if a key was pressed, and move it to the input buffer. And here’s where these two designs match: the firmware simply called the keyboard routine from everywhere. Since the electronics were so much faster than the human typing, this worked pretty well. You could miss a key occasionally, it didn’t happen often enough to notice.

This journey has uncovered things I never expected. EDSAC was the second general-purpose computer ever built (ENIAC was the first), was designed using Von Neumann’s architecture, and started the journey to the computers we know today.

And yet my little Apple //e was teaching me some of this history without me even knowing it. Good machine. Have some extra electrons as a treat. You deserve it.