A transistor is basically a voltage controller switch. Depending on the voltage you apply to its gate terminal, it will either allow or prevent current from flowing between it’s source and drain terminals. This means we can use electrical signals to control the behaviour of other electrical devices. The signal that turns on a device is usually referred to as high or 1, while the signal that turns off a device is low or 0 or ground. Most importantly for our discussion here are logic gates and latch.
A logic gate is a configuration of transistors that performs a logic operation: NOT, AND, OR and XOR. A NOT gate takes a single signal and reverses it, turning a 1 into a 0 and visa versa. AND takes 2 inputs, and if they are both 1, it outputs a 1, otherwise it outputs 0. OR takes 2 inputs and if either of them are 1, it outputs 1, which a XOR (exclusive or) gate only outputs a 1 if only one of it’s 2 inputs is 1. From these, you can build what is referred to a combinatorial logic. Based entirely on the current input, the combination of logic gate will produce a consistent output. These kind of devices include multiplexers, encoders, decoders, and circuits that perform mathematical operations.
A latch is something more complex. The most basic design of a latch is when you feedback the output of a NOT gate into itself. This will result in the output of the NOT gate flipping back and forth between 0 and 1 as quickly as the internal transistors can charge and discharge. The current output of the latch is entirely depend of the previous state of the latch. If we put two NOT gates in sequence, and feedback the output of the second to the input of the first, you get a device that will maintain it’s output value until it is acted on by an external device. This is a fairly basic kind of memory. Add a bit more circuitry to control when and how the stored value gets changed, and you get a register, the most basic kind of memory used in your CPU. There is generally a clock pulse used to synchronize all the devices in a system. Any kind of system that has a feedback loop in it is sequential logic.
Ok, now we have enough knowledge to explain finite state machines. Finite state machines are made of two parts: a memory and the control logic. The memory stores which state you are currently in. The control logic decides which state you should go to next based on the current input and the current state, and also produces the output of the machine. Lets say that we want to design a machine that outputs 1 if the last 2 input are the different. It’s control logic would need to implement the following table:
| State | Input | Output | Next State |
|——-|——–|——–|————|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
As logic functions:
Output = State XOR Input
Next State = Input
Now this is a trivial example but at it’s heart the CPU operates in fundamentally the same way. It has a table like this that describes how each operation it can perform is done, and the outputs are connected to each individual device to enable or disable them as needed. The input that the CPU sees come from instructions in memory and one of the devices that the CPU controls is the “program counter”, which stores the address in memory for the current instruction.
Latest Answers