This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:cs:chapter_3_4 [2025/01/04 11:48] – ktokarz | en:multiasm:cs:chapter_3_4 [2025/12/02 11:05] (current) – [Execution unit] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ======Components of Processor: Registers, ALU, Bus Control, Instruction Decoder ====== | ======Components of Processor: Registers, ALU, Bus Control, Instruction Decoder ====== | ||
| - | From our perspective, | + | From our perspective, |
| <figure procblock> | <figure procblock> | ||
| Line 8: | Line 8: | ||
| </ | </ | ||
| - | + | ===== Control unit ===== | |
| + | The function of the control unit, also known as the instruction processor, is to fetch, decode and execute instructions. It also generates signals to the execution unit if the instruction being executed requires so. It is a synchronous and sequential unit. Synchronous means that it changes state synchronously with the clock signal. Sequential means that the next state depends on the states at the inputs and the current internal state. As inputs, we can consider not only physical signals from other units of the computer but also the code of the instruction. To ensure that the computer behaves the same every time it is powered on, the execution unit is set to the known state at the beginning of operation by the RESET signal. | ||
| + | A typical control unit contains some essential elements: | ||
| + | * Instruction register (IR). | ||
| + | * Instruction decoder. | ||
| + | * Program counter (PC)/ | ||
| + | * Stack pointer (SP). | ||
| + | * Bus interface unit. | ||
| + | * Interrupt controller. | ||
| + | Elements of the control unit are shown in Fig {{ref> | ||
| + | |||
| + | <figure controlunit> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The control unit executes instructions in a few steps: | ||
| + | * Generates the address of the instruction. | ||
| + | * Fetches instruction code from memory. | ||
| + | * Decodes instructions. | ||
| + | * Generates signals to the execution unit or executes instructions internally. | ||
| + | |||
| + | In detail, the process looks as follows: | ||
| + | - The control unit takes the address of the instruction to be executed from a special register known as the Instruction Pointer or Program Counter and sends it to the memory via the address bus. It also generates signals on the control bus to synchronise memory with the processor. | ||
| + | - Memory takes the code of instruction from the provided address and sends it to the processor using a data bus. | ||
| + | - The processor stores the instruction code in the instruction register and, based on the bit pattern, interprets what to do next. | ||
| + | - If the instruction requires the execution unit operation, the control unit generates signals to control it. In cooperation with the execution unit, it can also read data from or write data to the memory. | ||
| + | |||
| + | The control unit works according to the clock signal generator cycles known as main clock cycles. With every clock cycle, some internal operations are performed. One such operation is reading or writing the memory, which sometimes requires more than a single clock cycle. Single memory access is known as a machine cycle. As instruction execution sometimes requires more than one memory access and other actions, the execution of the whole instruction is named an instruction cycle. Summarising, | ||
| + | |||
| + | The control unit also accepts input signals from peripherals, | ||
| + | < | ||
| + | Although the stack pointer is not implemented in all modern processors, every processor has some mechanism for storing the returning address. | ||
| + | </ | ||
| + | ===== Execution unit ===== | ||
| + | |||
| + | An execution unit, also known as the data processor, executes instructions. Typically, it is composed of a few essential elements: | ||
| + | * Arithmetic logic unit (ALU). | ||
| + | * Accumulator and set of registers, | ||
| + | * Flags register, | ||
| + | * Temporal register. | ||
| + | |||
| + | The arithmetic logic unit (ALU) is the element that performs logical and arithmetical calculations. It uses data coming from registers, the accumulator or from memory. Data coming from memory for arithmetic and logic instructions is stored in the temporal register. The result of calculations is stored back in the accumulator, | ||
| + | Besides the result, ALU also returns some additional information about the calculations. It modifies the bits in the flag register, which comprises flags that are modified according to the results from arithmetic and logical operations. For example, if the result of the addition operation is too large to be stored in the resulting argument, the carry flag is set to indicate such a situation. | ||
| + | |||
| + | Typically, the flags register includes: | ||
| + | * Carry flag, set in case a carry or borrow occurs. | ||
| + | * Sign flag, indicating whether the result is negative. | ||
| + | * Zero flag, set in case the result is zero. | ||
| + | * Auxiliary Carry flag used in BCD operations. | ||
| + | * Parity flag, which indicates whether the result has an even number of ones. | ||
| + | |||
| + | The flags are used as conditions for decision-making instructions (like //if// statements in some high-level languages). | ||
| + | The flags register can also implement some control flags to enable/ | ||
| + | |||
| + | ===== Registers ===== | ||
| + | |||
| + | Registers are memory elements which are placed logically and physically very close to the arithmetic logic unit. It makes them the fastest memory in the whole computer. They are sometimes called scratch registers, and the set of registers is called the register file. | ||
| + | |||
| + | As we mentioned in the chapter about CISC and RISC processors, in CISC processors, registers are specialised, | ||
| + | |||
| + | <figure CISCexeunit> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | A typical RISC execution unit does not have a specialised accumulator register. It implements the set of scratch registers as shown in Fig {{ref> | ||
| + | |||
| + | <figure RISCexeunit> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||