TipsThe Computer CPU – Jumps

20 April, 20196 min

Finally just to show you that everything you could possibly want can be easily included in this simple processor architecture consider how you might implement a “jump to xxxx” instruction.

Normally the next instruction to be executed is in the next sequential memory location but a jump makes the instruction at xxxx the next one.

How can this be achieved? Easy!

Just make the PC register correspond to register address 00 (rather than general purpose register D as suggested earlier). Now consider what  “load PC from address aaaa” does. It loads the PC register with the value stored in “aaaa” and so makes this the next instruction.

Not quite what was required but it isn’t difficult see how it can be modified to make it work exactly as specified.

But this brings us to the interesting topic of addressing modes and that’s another story.

To make a computer capable of doing everything you need a computer to do you also need to add to jumps a conditional jump. A basic jump instruction is used for form loops – sections of code that repeat. Conditional jumps are used to implement conditionals which we know better as if statements.

Extending our design to this is very easy. You need another register, the condition code register, and now when a register is loaded you provide the logic to set bits in the condition code register. If the register is zero then you set the zero bit, if negative the negative bit and if positive the postitive bit.

You now modify the jump instruction to include logic that can test the condition bits. So now you have conditional jump instructions like jmpeq for jump if equal to zero, jmpn for jump if negative and so on.

You should be able to see how to implement this – the condition bits simply enable or disable the loading of the PC register.

With conditional jumps our computer can now do everything – it is Turing Complete.

Beyond Fetch-Execute

If you know about modern processors you might be raising objections that this is not how they work. This is partly true. The first computers worked exactly as described but over time the fetch-execute cycle has been tweaked to make the machine work faster.

In particular the fetch cycle, decoding and execution cycle are generally stretched out so that on a clock pulse an instruction is fetched while earlier instructions are decoded, and executed at the same time.

This is generally called a pipeline and it is use by most modern machines but it is just a development on fetch-execute.

Modern processors are so developed that you might have trouble seeing the simplicity of how they work but at the bottom it is still a fetch execute cycle that is responsible for computation.

Copy link