Have you ever wondered how a CPU works exactly?
Are you familiar with Logic Gates (AND, NOR, etc) being built from electrically operated switches like relays or transistors? That these Logic Gates are the building blocks of greater and more complicated elements, like flip-flops, latches, and adders? And are you also familiar with the higher-level view of a CPU being able to accept instructions in machine code or assembler, things like adding two numbers together or storing a value in a certain memory location? Good.
But are you unclear about how those two views are connected? How you get from a flip-flop or an adder to a CPU that “knows” what to do with a certain machine code instruction?
Then you’re exactly at the place I’m in.
Fear not, there is a wonderful and extremely well-written book: Code: the Hidden Language of Computer Hardware and Software by Charles Petzold, that explains the workings of a computer from the ground up without requiring *any* foreknowledge. It starts off nice and slow with the invention of relays (Telegraph!). Computer-savvy readers can skip some chapters, for instance where the author explains the binary system in detail. But at some point, the speed picks up, and you actually follow Petzold step by step in building a functional CPU *from scratch* starting with just relays (or transistors if you will).
The amazing thing is that all the technology required for a working computer was already available in the *19th century*. They could have built a working computer from just relays.
Which is what I’m going to do. But I’ll use *virtual* relays.
I’ll write this in Racket, because that happens to be the language I’m learning right now. The program will be relatively simple: two basic elements: a relay and a connector, and then an ever increasing hierarchy of building blocks, all eventually just comprising relays and connectors. I will follow the path set by Petzold closely.
This will be fun (hopefully!), but I’ll also use it for the following purposes:
- Use the Racket Object Oriented Programming (OOP) functionality
- Use Unit Tests
- Get acquainted to GitHub
Watch this space!