How a Programming Language Becomes Voltages in a CPU
If you know basic electrical engineering — wires, voltage levels (0V / 3.3V), logic gates, multiplexers, and clocked flip-flops — there is zero magic in how computers run code. Follow one live program all the way from readable source code down to control wires and full adders.
The Compiler: Translating Human Structure into Flat CPU Steps
A CPU only understands tiny one-step operations on a few fast registers (R0–R7). A compiler reads your structured code in three mechanical passes: Lexing (chopping text into tokens), Parsing (building an Abstract Syntax Tree), and Code Generation (walking the tree to emit assembly).
a, b, c as human nicknames for specific hardware register banks (groups of D-flip-flops labeled R1, R2, R3). The compiler assigns each variable a register and flattens nested expressions or if/while blocks into sequential instructions.
The Assembler: Packing Text into 16 Parallel Wires
Here is the key bridge: the CPU never reads text like ADD R3, R1, R2. The assembler simply converts each mnemonic into a fixed 16-bit binary number. Inside the chip, those 16 bits are literally 16 parallel copper traces carrying 0V (0) or 3.3V (1).
15..12 are always the opcode, those 4 physical wires can be soldered straight into the Control Unit's logic decoder. Bits 11..9 go straight to the Register File's write-address decoder. Click any bit below to flip its voltage!
| Opcode | Mnemonic | Format | Hardware Action |
|---|
How the CPU "Knows" What to Do: Clock, Decoder & Datapath
A CPU doesn't "understand" instructions — it is a clocked finite state machine. On each instruction cycle, the opcode wires set up multiplexers (MUXes) and ALU select lines, combinational logic computes the answer, and the next rising clock edge latches the result into flip-flops.
Down to the Silicon: How Logic Gates Actually Add Numbers
When the Control Unit sets ALUOp = ADD, the ALU doesn't "know" arithmetic — it routes your two numbers into a chain of Full Adders built from XOR, AND, and OR gates. Toggle the bits below (or pull live values from the CPU above) to watch voltages and carry bits ripple across the hardware.
How a Gate Is Just Two MOSFET Switches
Every XOR, AND, OR, and Flip-Flop above is built from tiny complementary MOSFETs (PMOS + NMOS). Click the input button to apply 0V or 3.3V to the gates and watch which transistor conducts.
The Complete EE ↔ Software Translation Table
Keep this mental map whenever you look at code or a microcontroller datasheet — every software abstraction maps directly to a physical circuit.