This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:cs:chapter_3_8 [2025/01/06 16:25] – ktokarz | en:multiasm:cs:chapter_3_8 [2025/12/05 09:59] (current) – [Instruction Execution Process] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Instruction Execution Process ====== | ===== Instruction Execution Process ====== | ||
| - | As we already mentioned, instructions are executed by the processor in a few steps. You can find in the literature descriptions that there are three, four, or five stages of instruction execution. Everything depends on the level of detail one considers. The three stages | + | As we already mentioned, instructions are executed by the processor in a few steps. You can find in the literature descriptions that there are three, four, or five stages of instruction execution. Everything depends on the level of detail one considers. The three-stage |
| - | It is worth remembering that even a simple fetch step can be divided into a set of smaller actions which must be performed by the processor. The real execution of instructions depends on the processor' | + | It is worth remembering that even a simple fetch step can be divided into a set of smaller actions which must be performed by the processor. The real execution of instructions depends on the processor' |
| - Fetching the instruction: | - Fetching the instruction: | ||
| - | * The processor addresses the instruction by sending the content of the IP register | + | * The processor addresses the instruction by sending the content of the IP register |
| - | * The processor reads the code of the instruction from program memory | + | * The processor reads the code of the instruction from program memory |
| * The processor stores the code of the instruction in the instruction register. | * The processor stores the code of the instruction in the instruction register. | ||
| * The processor prepares the IP (possibly increments) to point to the next instruction in a stream. | * The processor prepares the IP (possibly increments) to point to the next instruction in a stream. | ||
| - Instruction decoding: | - Instruction decoding: | ||
| - | | + | |
| - | * More complex instructions are processed in some steps by microcodes. | + | * More complex instructions are processed in some steps by microcodes. |
| - | * Results are provided to the execution unit. | + | * Results are provided to the execution unit. |
| + | - Data reading (if the instruction requires reading the data): | ||
| + | * The processor calculates the address of the data in the data memory. | ||
| + | * The processor sends this address by address bus to the memory. | ||
| + | * The processor reads the data from memory and stores it in the accumulator or general-purpose register. | ||
| - Instruction execution: | - Instruction execution: | ||
| - | | + | |
| - | * In modern processors there are more execution units, they can execute | + | * In modern processors, there are more execution units, |
| - | * Some instructions require reading the data so the data fetch step can be present here: | + | |
| - | - Data reading: | + | |
| - | * The processor calculates the address of the data in the data memory. | + | |
| - | * The processor sends this address by address bus to the memory. | + | |
| - | * The processor reads the data from memory and stores it in the accumulator or general-purpose register. | + | |
| - Writing back the result: | - Writing back the result: | ||
| - | | + | |
| - | As you can see from this description execution | + | ===== Instruction encoding ===== |
| + | From the perspective | ||
| + | A fixed number of bits makes the construction of the instruction decoder simpler because the choice of some specific behaviour or function of the execution unit is encoded with the bits, which are always at the same position in the instruction. On the opposite side, if the designer plans to expand the instruction set with new instructions in the future, there must be some spare bits in the instruction word reserved for future use. It makes the code of the program larger than required. Fixed lengths of instructions are often implemented in RISC machines. For example, in the ARM architecture, | ||
| - | Instruction encoding | + | A variable number of bits makes the instruction decoder more complex. Based on the content of the first part of the instruction (usually a byte), it must be able to decide what is the length of the whole instruction. In such an approach, instructions can be as short as one byte or much longer. An example of a processor with variable instruction length is the 8086 and all further processors from the x86 and x64 families. Here, the instructions, |
| - | constant | + | |
| + | <note info> | ||
| + | Although in the computer world information is very often encoded in bytes or multiples of bytes, there are processors with instructions encoded in other numbers of bits. Examples include PIC microcontrollers with an instruction length of 13 or 14 bits.</ | ||