Foundations
From Source to Silicon
How the program you write becomes something a machine can run — interpreting, compiling, and assembling — and why that one choice is the difference between a game that keeps up and one that can't. The last foundation before you meet a machine, shown running in Sinclair BASIC.
What this is
General Programming taught that a program is instructions in order. Numbers & Bits taught that everything those instructions touch is a number. This is the hinge between the two of them and the machine itself — and it turns on a fact nobody tells you at the start: the instructions you write are not the instructions the machine runs. Something has to stand in the middle and translate.
That translator can work in one of two ways, and the difference between them is the most useful practical fact in this whole curriculum. It can translate as it goes — read your line, work out what it means, do it, and then do all of that again the next time it meets the same line. Or it can translate once, ahead of time — turn your whole program into the machine’s own numbers before a single thing happens, and then get out of the way. The first is how BASIC works. The second is how the games in a machine’s own language are built. One is patient with you; the other is fast. You are about to spend a long time choosing the second, and this is where you learn what that choice actually is.
Each idea appears twice, as before: once as the plain shape of it (the idea, with no language in the way), and once in real Sinclair BASIC — where, for once, you don’t just read the idea, you time it. A loop that does almost nothing, slow anyway, because every time round it the machine is translating your line afresh.
Who it’s for
Anyone standing at the top of the stairs down to assembly, wondering why they should bother climbing down. If you’ve met General Programming and Numbers & Bits, this is the step that tells you what’s at the bottom and why it’s worth the trip. The BASIC tracks can skip it — but any BASIC programmer who has ever thought why is this so slow will find the answer here, and it isn’t the answer they expect.
What it is not
This is not how to write assembly — not one real instruction for one real machine. That’s Meet the Machine, told concretely, in your machine’s own mnemonics, once you’ve picked one. Here we stay a level up: what kind of thing an interpreter is, what kind of thing an assembler is, and why the very same idea — add one, a thousand times — can be instant or sluggish depending only on when the translating happens. The concepts are true of every machine ever made; the mnemonics belong to each. We do the concepts here, once, so that when you meet the mnemonics they land on ground already prepared.
The shape
- What “run” means — your program is text; the processor only ever eats numbers. Something stands between them. Meet the middleman, and the one question that decides everything: when does the translating happen?
- Translating as you go — the interpreter: read a line, puzzle out its meaning, do it — and pay that same price again every single time round the loop.
- The price, on the clock — time a loop that does almost nothing. It’s slow anyway. Now you can see the translation tax a game would pay on every frame.
- Translating once — the compiler: turn the whole program into the machine’s numbers before it runs, pay the price a single time, and run at full speed ever after.
- One name, one number — the assembler: the thinnest translation there is, a readable name for each of the machine’s own instructions. This is the door into Meet the Machine.
- The same thousand, three ways — one idea, interpreted, compiled and assembled, and the gulf between them: the reason an enemy can chase you sixty times a second in assembly and stutter in BASIC.
- What speed costs you — going down to the metal buys speed and sells comfort: no safety net, more to say, and a program that runs on one machine only. What you’re agreeing to when you say yes to the machine.
By the end you’ll know exactly what happens to a line of code in the gap between your typing it and the machine obeying it — and why the road down to assembly is a road toward speed and away from comfort. Next stop: Meet the Machine — told in your chosen machine’s own language, where the translating stops being an idea and the machine’s own numbers become yours to write.