jump

We saw how a program counter (PC) keeps track of what instruction is currently being executed.

Usually the PC increments itself after each instruction. To enable complex programs, we need an instruction that can set the PC directly.

loops

Currently, all our programs walk through a set number of instructions and then finish. What if we want some kind of loop where we can repeat the same instructions?

We’d need some kind of JUMP instruction:

0 INC // increment the accumulator
1 JMP 00 // jump back to the first instruction

This program will endlessly increment the accumulator, effectively functioning as a timer that tracks how many steps the program’s been running for.

implementation

To perform a JUMP, we need to set the PC directly. When the processor is ready for the next instruction, it’ll read the PC and go to the instruction we choose.

Recall our PC is just a register:

00/0000/00
loading…

dynamic register

So we can write to it like any register. In fact, this is no different to the SAVE instruction we created for our calculator.

This brings us to a powerful concept in computing: interfaces. An interface is just a way for you to interact with something, while hiding the details underneath the interface.

Think of sitting in the driver’s seat of a car. Every car has a steering wheel, accelerator, brake pedal, and so on. This is the car’s interface. You don’t need to know anything about what’s under the hood — it could be a petrol engine, diesel, electric, whatever. All you need to know is how to control the interface. This is incredibly useful: if you know how to drive one car, you can pretty much drive any car.

definition

An interface is the “control panel” that a device exposes to the world, letting people (or other devices) interact with it.

How does this apply here? Compare our save register and program counter. They both have the same interface: you can read from each of them, write to each of them, and the operations are the same. This means any devices we design to interact with the save register could also be used with the program counter. It allows us to reuse solutions.

More importantly, smart interface design lets us make changes to one part of a system without having to redesign everything else. For example, suppose we have a 4-bit register, and we decide to upgrade it to 8 bits. Extending the register’s loop of paths paths doesn’t alter the interface. Any of our devices that knew how to use the 4 bit register automatically know how to use the 8 bit register — the underlying changes are invisible to them.

building the JUMP

coming soon
We’re still working on this part of the tutorial — come back later!

next

We can implement JUMP just by writing to a register, and use that to implement a looping program. But as we’ll see in the next tutorial, JUMP is much more powerful than this — we can use it to create branching programs.

continue