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

Jumps

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

knowcover

Contents

  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. XOR - The Magic Swap
  16. Programmer's Introduction to XML
  17. From Data To Objects*
  18. Stacks And Trees
  19. The LIFO Stack - A Gentle Guide
  20. Data Structures - Trees
  21. Inside Random Numbers
  22. The Monte Carlo Method
  23. Cache Memory And The Caching Principle
  24. Data Compression The Dictionary Way
  25. Dates Are Difficult
  26. Magic of Merging
  27. Power of Operators
  28. The Heart Of A Compiler
  29. The Fundamentals of Pointers
  30. Public Key Encryption
  31. Quick Median
  32. Functional And Dysfunctional Programming*

* Recently revised

Python

 



 

Comments




or email your comment to: comments@i-programmer.info

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, FacebookGoogle+ or Linkedin.

Banner


The Monte Carlo Method

Monte Carlo methods are powerful ways of getting answers using random numbers to problems that really don't seem to have anything much to do with randomness. For example, you can find Pi and multiply  [ ... ]



What's In A DOS

Now that Microsoft has open sourced MS-DOS it's a good time to look at filing systems, blocks and the FAT and how they are used. Let's explore the basics of a DOS - Disk Operating System.


Other Articles

<ASIN:1584504951>

<ASIN:0201000237>

<ASIN:0596526865>

<ASIN:0123744938>

<ASIN:1844254402>

<ASIN:0789736136>

<ASIN:0130620130>

 

 



Last Updated ( Thursday, 10 January 2019 )