Skip to content

Put It on the Clock

What speed buys you, and why the gap is a number you should measure for yourself rather than a claim you take from a page.

Unit 4 was the bill. Three things you give up, none of them small. This is the other side of it, and then the reason it is worth paying.

Speed

The translating that sat inside the loop in Unit 2, happening on every one of a thousand passes, is gone. What is left is the machine running as fast as it can run, and on a small machine that is the difference between a game that keeps up with the screen and one that does not.

That is the whole reason this module exists, so it goes first.

The whole table

An interpreter offers you what its designers thought to offer. If they did not give you a word for something, you cannot ask for it.

Assembly offers you the table. All of it. Everything the machine can do has a name and a number in there, and every one of them is yours to write. Some of the most surprising things ever done on these machines were done by asking for something no language had a word for.

Nothing on trust

When you have written the numbers yourself, there is no layer underneath that you have to take somebody’s word for. You know what the machine is running, because you wrote it.

That is a kind of understanding that is hard to get any other way, and it is the reason this shelf has kept saying there is nothing else in there.

Put it on the clock

Everything in this module has been counted rather than timed. A trace table can show you that the interpreter worked the same line out a thousand times, and you can check that on paper. What it cannot show you is how long a thousand of those took, because there is no clock in pseudocode.

On a real machine there is. Every one of these computers keeps a count of how many times it has drawn the screen, and that count is a clock you can read.

So the first thing worth doing when you meet a machine is this. Write the loop from Unit 2 in its BASIC. Read the clock, run the loop, read the clock again. Then write the same loop in its assembly and do the same. Two numbers.

The gap between them is not a claim anyone needs to make to you. It is a number, it is yours, and it is larger than you think.

When it’s wrong, see why

  • The two numbers are closer than you expected. Check what is in the loop. A loop that waits for something, or draws something, spends its time on that rather than on translating, and the gap shrinks. Keep the loop as empty as Unit 2’s.
  • You cannot find the clock. Every machine in this curriculum has one. Its briefing says where it lives and how to read it.
  • You took the number from a page instead of measuring it. Then you have a claim, not a fact. The whole point of this unit is that you do not have to.

What you’ve learnt

  • Speed is what you buy, and on a small machine it is the difference between keeping up and not.
  • Assembly offers the whole table, not the words somebody chose for you.
  • Written in numbers, a program has nothing underneath to take on trust.
  • Pseudocode can count the cost. Only a real machine can time it, and you should.

Where this leaves you

You know what happens to a line of code between your typing it and the machine obeying it, and why the road down to assembly is a road towards speed and away from comfort. You have built a translator, so you know there is nothing mysterious in one.

Two places from here. Meet the Machine is your machine’s briefing: where the byte you have been reading all this time lives, and where the clock is. Meet Assembly has the real table, with real names and real numbers. Take the loop with you.