How does a CPU work?
CPU’s work on the principles of digital logic which can be implemented on a silicon wafer by the construction of a large number of binary switches (transistors or gates). These gates can be combined into circuits which have specific functions – for example a circuit to add two numbers together and include the carry from the previous operation can be implemented like this:
Simple circuits like this can be combined with others to perform multiplication (which is fundamentally a bunch of addition operations). Another key element of a CPU involves storing information. This is done using embedded memories or registers which are usually addressable by row and column:
By providing an address to this memory, the value stored at that location can be retrieved. Again these are constructed of a number of transistors which can be toggled either on or off to denote a value of 1 or 0.
Synchronizing this all is a system which is called the clock. Clocking provides a mechanism by which operations across the entire chip can be done at the same time so when you are comparing the results from two circuits which are working on a similar operation (adding two numbers for example), the results are from that operation, rather than one circuit getting ahead of the other and not comparing against the correct value.
Clocks are also used to control the input and output of the CPU so it can talk to external devices. They are built of both analog and digital devices. At the core of most clocks is a Phase Locked Loop circuit (PLL) and a means for distributing the clock pulses across the chip – sometimes using repeaters or splitters to tune the clocks appropriately to account for the time it takes for signals to travel across the chip.
Around the outside of a CPU we can usually find the I/O ring which receives analog signals from the outside world and controls communication with other devices. Examples of this would be a memory interfaces or general purpose IO.
Together these elements allow the CPU to receive instructions from software, read values, perform operations and output results to the rest of the system. To facilitate this there is also microcode within the CPU which controls how it behaves and operates. This microcode allows the soft implementation of instructions – abstracting the instructions from the need to specify the specific circuit operations to perform the instruction. This same process of abstraction is continued again and again though OS and software so that the person using a computer can click on a location on a screen and retrieve information from halfway around the world without knowing anything about what a transistor is.