Principles Of Execution - The CPU
Written by Harry Fairhead   
Thursday, 10 January 2019
Article Index
Principles Of Execution - The CPU
The Op Code


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.


What Programmers Know



  1. The Computer - What's The Big Idea?*
  2. The Memory Principle - Computer Memory and Pigeonholes*
  3. Principles of Execution - The CPU
  4. The Essence Of Programming
  5. Variables - Scope, Lifetime And More*
  6. Binary Arithmetic
  7. Hexadecimal*
  8. Binary - Negative Numbers
  9. Floating Point Numbers
  10. Inside the Computer - Addressing
  11. The Mod Function
  12. Recursion
  13. The Lost Art Of The Storage Mapping Function *
  14. Hashing - The Greatest Idea In Programming
  15. Advanced Hashing
  16. XOR - The Magic Swap
  17. Programmer's Introduction to XML
  18. From Data To Objects*
  19. What Exactly Is A First Class Function - And Why You Should Care*
  20. Stacks And Trees*
  21. The LIFO Stack - A Gentle Guide*
  22. Data Structures - Trees
  23. Inside Random Numbers
  24. The Monte Carlo Method
  25. Cache Memory And The Caching Principle
  26. Data Compression The Dictionary Way
  27. Dates Are Difficult*
  28. Sequential Storage*
  29. Magic of Merging*
  30. Power of Operators
  31. The Heart Of A Compiler*
  32. The Fundamentals of Pointers
  33. Functional And Dysfunctional Programming*

* Recently revised





or email your comment to:

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.


Dates Are Difficult

Date and times follow their own regularities, and they have nothing at all to do with binary, or even simple decimal, counting. First, clock and watch makers had to find ways of working with hours, mi [ ... ]

Cache Memory And The Caching Principle

The caching principle is very general but it is best known for its use in speeding up the CPU. We take a look a the basics of cache memory, how it works and what governs how big it needs to be to do i [ ... ]

Other Articles










Last Updated ( Thursday, 10 January 2019 )