I’ve wanted to teach this for ages, my time has come!
The first thing to understand is that a transistor is simply a switch operated by electricity. It’s got an input and an output, and there’s a control input that, if it sees voltage, will allow the current to flow to the output. So 2 inputs: signal and control, and 1 output.
Taking a step back, this is a form of the boolean logic for an AND gate. If there’s input voltage but the control is off, there’s nothing on the output. If the control is on but there’s no input voltage, then you’ve successfully sent no voltage to the output. If both the input AND the control are on, then the output is on.
This is an example of boolean AND. There are other “logic gates” for OR (either input makes the output turn on) and other logical operations.
It’s possible to chain these logical operations together to do binary math; for more detail start here: https://en.m.wikipedia.org/wiki/Adder_(electronics). At this moment just trust me that you can create a physical circuit that, given 2 binary numbers, “happens” to produce their binary sum as their output. It’s a hard-wired circuit designed to add by the chip maker.
Next, know that the processor is hard-wired to do this in a loop:
* Load next instruction and arguments into registers (immediately needed working memory)
* Execute the instruction by activating a circuit that performs the operation
* Store the output in a specified register
… over and over again.
So imagine you compile your code and it generates an add instruction. The processor, when it gets there, puts the two input numbers in the right place, “turns on” just the add circuit, and stores what comes up as its output.
Every circuit in the instruction set is built this way (hard wired in the chip) and your program is compiled to this set of instructions that just make a list of instructions to load, execute a physical circuit for the right operation, store.
That’s it, basically! It can get way more complicated but that’s the basics.
Latest Answers