In simplest terms, a processor is a digital circuit (i.e., ARM, RISC-V, x86) that performs operations and computations on data, step-by-step, according to a set of step-by-step instructions called executable code.

Machine code is loaded into the processor instruction memory. An -bit processor has -bit wide registers, with possible memory addresses, and a data word size of bits. What this means is that: a 32-bit processor has addresses that are 4 bytes wide (each byte is 8 bits).

Internal hardware

Processors have registers inside for temporary storage. All computations are done on the register. Processors rely on several circuits to handle instructions and computations:

  • Registers: the number of bits supported by the register determines the bits of the processor.
    • Program counter: stores the address of the next instruction to be executed.
    • Condition code registers (Z, N): Z checks if the operation that just happened was 0 or 1. Z = 1 if the result is 0, Z = 0 otherwise. N checks if the result is negative. N = 1 if result is negative, N = 0 if result is positive. These are connected to the ALUs.
    • Instruction register: saves the output of the memory for an instruction read.
    • Memory data register (MDR): saves the output of the memory for a data read.
  • Register files: circuit block that implements the processor’s registers, and allows the rest of the circuit to interface with the data.
  • Datapath: defines what types of computations are possible.
  • Control path: determines what computations to do, and how to do them.
  • Multiplexers: used to handle selections.
  • ALUs: to handle bitwise and arithmetic computations.
  • Memory: for longer-term storage.

This is not an exhaustive list. Many other circuits may be necessarily included for other functions. For instance, immediate instructions go through a zero extension and is passed into a multiplexer, then the ALU.

Modern processors are inherently parallelised and can execute more instructions in less clock cycles or more instructions simultaneously.

Instructions

A register called a program counter (PC) stores the address of the next instruction to be executed. Successive addresses will be executed in order of increasing addresses, called straight-line sequencing. Executing an instruction takes two main phases. The first is instruction fetch, which fetches the instruction from memory and places it in the instruction register (IR). Next is instruction execute.

The processor’s control unit takes a specific sequence of steps. The idea is that data is pulled from memory into registers, computations happen on register data, and results are stored back into memory.1 It follows this sequence of steps:2

  1. Fetch an instruction from the program counter.
  2. Decode the instruction.
  3. Locate/fetch the operands used by the instruction.
  4. Calculate/execute the operation with the ALU.
  5. Store the results (in a register or memory).
  6. Update the program counter (increment or replace with branch value) and go back to step 1.
    1. This update step can be optimised to take place in the same step as step 1/2.

This sequence is usually implemented as a finite state machine, The machine tunnel visions in that it only really has one task it has to do. There’s no distinction between the instruction and data: just in when it’s accessed by the CPU.

Types

Footnotes

  1. See this page for an example in RISC.

  2. From Logic and Computer Design Fundamentals, by Mano/Kime, pp 463.