How a CPU Works: Physical Architecture

A CPU can be physically made of individual circuits that can be switched on or off. A combination of these circuits will then create logic that will cause electricity to flow in and bring the CPU into some sort of state that can be interpreted as a result. Having large physical circuits to construct a CPU is not scalable as earlier computers took up the entire space of large rooms — more powerful CPUs would need space that would be impossible to manage. Therefore, transistors are what modern CPUs are now composed of.

A transistor can be thought of as a very tiny switch that will simply turn a circuit on, or off. Therefore, each transistor will represent either a 0 (off) or 1 (on). The combination of the transistors will create logic. Logic is then chained together to make data paths that will allow the CPU to physically take itself into various states.

It is the program that the software engineer write that will utilize the available logic in the CPU to make things happen. However, logic just doesn’t happen. Logic must be paced and is driven by a clock. 1 MHz for example, is a clock frequency a CPU can run at. One million cycles per second.

Generally, a CPU will consist of the following components:

  • An instruction register. (IR)
  • An arithmetic and logic unit. (ALU)
  • A set of “general purpose” registers.
  • A set of “special purpose” registers.
  • Control and timing units.

Control, data and address lines are used to communicate to external devices through a system of lines (wires) called “buses”. In the 6502, the data and control buses are 8 lines — one for each bit, while the address lines consist of 16 lines — 16 bits. This gives the 6502 16-bits of addressable memory, which is 64 KB (2¹⁶ bytes).

It is important to note that it is the control and data lines in the bus that defines the “bit-ness” of a CPU.

General purpose registers are used to store intermediate results within the CPU operations. The 6502 consists of 3 general purpose registers:

  • X (index register)
  • Y (index register)
  • A (accumulator register)

The registers above are all 8 bit registers and thus store one byte of data.

Special purpose registers belonging to the 6502 are:

  • SP (stack pointer register)
  • P (status register)
  • PC (program counter register)

The communication between the general purpose registers are made through the 8 bit data bus, while the stack pointer and program counter are actually 16 bit registers that communicate with memory through the 16 bit address bus. The following block diagram shows how each register makes a link between the various buses to form a communication system: