A few years into coding I had a friend ask me "How do computers actually work?" and when I began to answer, I started to realize that I actually had no idea. No amount of Python or Java could ever prepare you to answer that question. For a high level programmer, a computer is effectively a black box that you communicate with. About a year later, after some systems level programming and a digital logic course, I think I'm ready to (vaguely) answer that question. It's worth noting that this isn't a question that can be truly answered in 10 minutes or in one article alone, but I will try to cover all of the main bases. If you are interested in diving deeper, I highly recommend Crash Course Computer Science . All images in this article are self made, so feel free to use them in your own projects.
Transistors are the fundamental building block of all circuits, and therefore computers. It helps to think of them like a light switch. Instead of physically flipping a switch on or off, you can apply a current to flip the switch on.
Aligning transistors in a certain way allow you to create logic gates.
AND logic gates takes 2 inputs, and only outputs a current if both inputs have a current.
| A (input1) | B (input2) | F (output) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR logic gates take 2 inputs and outputs a current if at least 1 of the inputs has a current.
| A | B | F |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NOT logic gates negate a single input. Below is the transistor cirucit and table for the gate
| A | F |
|---|---|
| 0 | 1 |
| 1 | 0 |
There are a few more basic logic gates, but with just these 3 logic gates, we can model any circuit. The process of designing a circuit is out of the scope of this article, but if you're curious you can look into POS and SOP
To keep it short, multiplexers are like circuit-level if (or more accurately switch/case) statements. They have select line(s), input lines, and a singular output. A simple 2 to 1 multiplexer takes 2 input circuits and 1 select line. If the select line is zero, the output F is the result of the first input circuit. If the select line is one, the output will be the result of the second input circuit.
| A | B | S0 | F |
|---|---|---|---|
| 0 | 0 | 0 (and gate) | 0 |
| 0 | 0 | 1 (or gate) | 0 |
| 0 | 1 | 0 (and gate) | 0 |
| 0 | 1 | 1 (or gate) | 1 |
| 1 | 0 | 0 (and gate) | 0 |
| 1 | 0 | 1 (or gate) | 1 |
| 1 | 1 | 0 (and gate) | 1 |
| 1 | 1 | 1 (or gate) | 1 |
The Arithmetic Logic Unit is a part of any processor. Its contains lots of sub-circuits that can do basic arithmetic and logical operations. With a multiplexer, we can take 2 inputs and do some operation on them based on the select lines. The following example allows for selection of ADDITION, OR, AND, or XOR between 2 inputs.
Now that we can perform operations on numbers, we need a place to store the data recieved. Using clever circuit design, we can store 1 bit at a time using latches.
This circuit allows for an input to be stored only when the 'Clk E' line is enabled. When the enable is off, the last value set during a clock enable is stored in the latch (Q). If we can store a single bit in one latch, we can line them up in a series called a register and store multiple bits
Now that weve covered the really low level stuff, let's take a step up the abstraction chain. A basic Central Processing Unit contains an ALU, Registers, and a Control Unit. The CPU executes instructions stored in memory. These instructions are what make up all of your applications, including the software you're reading this on. It's worth noting at this point that I am leaving RAM out of this article, but it's a critical part of any modern computer as registers alone dont hold enough data.
The Graphics Processing Unit is very similar to the CPU, with a few optimizations for, you guessed it, graphics. Graphics processing for video games, video rendering, etc., is extremely expensive from a processing standpoint. But there is one unique aspect of it that allows us to compute it extremely fast: parallelization . In addition to an ALU designed specifically for graphics arithmetic, GPUs have many cores because arithmetic to compute 1 pixel can be done separately from another pixel. For example, a GPU with 16 cores can assign pixel colors to 16 different pixels in 1 clock cycle.
There are very noteable components left out of this article. Decoders and encoders, RAM, SSDs and permanent storage, just to name a few. If you would like to gain a more complete understanding of computers, I strongly encourage you to follow the Crash Course Computer Science video series. I will warn you that it may take a few watches to really understand it, but it's the most intuitive way I've seen computers explained.