Jump to content

[Software] This is how your CPU executes the instructions given to it by the software.


Recommended Posts

Posted

CPU.jpg

What a CPU does is execute the instructions of a program located in a memory. But did you know that they all follow the same general rules? They all follow the same instruction cycle, which is divided into three distinct stages called Fetch, Decode, and Execute, which are translated as fetch, decode, and execute. We explain how these stages work and how they are organized.

In order to simplify and make the concepts explained in this article more understandable, we have decided to describe an extremely simple processor for these times, so in this article you will see an explanation of what instruction cycles are in a general way that can be apply from the first 8-bit processors to the most complex ones that exist today.

The processors are not different from a certain point of view to a combustion engine, which always carry out a continuous process of fuel explosion in different stages, whether they are 2-stroke or 4-stroke. The reason for this is that the processors work in three different stages in their simplest version, which are the following:

Fetch or Capture: In which the instruction is captured from RAM memory and copied into the processor.
Decode or Decoding: In which the previously captured instruction is decoded and sent to the execution units.
Execute or Execution: Where the instruction is resolved and the result written in the internal registers of the processor or in a memory address of RAM.
These three stages are fulfilled in every processor, there is a fourth stage which is Write-Back which is when the execution units write the result, but normally this is counted within the execution stage of the instruction cycle.

The first stage of the instruction cycle is responsible for capturing the instructions that are in the RAM memory assigned to the processor through a series of units and registers that are the following:

Program Counter or Program Counter: Which points to the next memory line where the next processor instruction is located. Its value is incremented by 1 each time a complete instruction cycle is completed or when a jump instruction changes the value of the program counter.
Memory Address Register or memory address register: The MAR copies the contents of the PC and sends it to RAM through the address pins of the CPU, which are wired with the address pins of the RAM itself.
Memory Data Register or memory data register: In the event that the CPU has to perform a memory reading, what the MDR does is copy the content of that memory address to an internal register of the CPU, which is a temporary step register before its contents are copied to the Instruction Register. The MDR, contrary to the MAR, is connected to the data pins of the RAM and not to the address pins, and in the case of a write instruction, the content of what is to be written in the RAM is also written in the MDR
Instruction Register or Instruction Register: The final part of the capture or fetch stage is the writing of the instruction in the instruction register, from which the processor control unit will copy its content for the second stage of the instruction cycle.
These 4 sub-stages occur in all processors regardless of their utility, architecture and binary compatibility or what we call ISA

 

https://hardzone.es/tutoriales/rendimiento/ciclo-instruccion-cpu/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.