Remember me?
Hey Y’all! This is a translation of my blog post originally written in Portuguese. If you want to read that version, click here.
Hello everyone, this is the third article in the series about computers, and also the last one with this header here, because from here on it’s recommended that you have already read the two previous articles:
In the previous articles, we saw how logic gates can be used to make comparisons and also calculate arithmetic operations, but we haven’t yet seen how the computer can store information over time.
Another thing we’ll do here is categorize each type of chip: the ones shown previously are combinational, which means they don’t need anything beyond signals at their inputs to be able to compute a result, but there are also sequential ones. The difference between them is that sequential depends not only on the input signals, but also on the previously processed value.
A very practical way to use logic gates to store information is using a chip called flip-flop, which is represented below. It contains 2 inputs: the top one set
and the bottom one reset
(you can click on the circuit below to interact with them).
set
trail, you’ll see there are two logic gates in the path, an OR
and an AND
. One of the OR
gate inputs is connected to the result of the AND
at the end of the chip. This combination makes it so that when we have 0 and are given a value 1, the OR
gate will result in 1, and the AND
will also.However, when we remove the signal from set
, the value that was previously placed is persisted because now the OR
is maintaining the state that keeps the AND
also in the previous state. Problem solved, right? No! Notice that our circuit is now locked, as there’s no way to get out of this state unless the AND
gets another value, and that’s what the reset
gate is for: it’s connected to a NOT
, meaning while it’s off (0), its result will be 1 (on), and vice versa.
An evolution we can make to the flip-flop is to transform it into a Register. In the register, we can choose whether it’s time or not to read our signal and store it, and subsequently rewrite it, all at our leisure. There are many ways to achieve this chip, so I’ll use the implementation demonstrated by Sebastian Lague.
In it, we just need to add 3 more logic gates and that’s it!
If we break it down a bit, what happens is the following: the upper input, which we’ll now calldata
, will only be saved in the flip-flop when the lower input, which also changed names, now called enabled
. So instead of using two inputs, one to save and another to erase, this combination of AND
s and NOT
chooses which operation will be performed.- If
data
= 1 andenabled
= 1, then it’s the same as turning on theset
input of the flip-flop. - If
data
= 0 andenabled
= 1, then it’s the same as turning on thereset
input of the flip-flop. Notice thatenabled
always needs to be activated so that it can save the signal that was placed indata
.
Another thing we can do is take inspiration from the previous article, where at the end we learned that if we combine several Adders, we can do calculations with multiple digits. In memory it’s the same way: combining several registers, you can provide an input for each data
and share the enabled
signal, and thus you can save the values of an entire binary number.
For now, we say goodbye here, see you next time 😄
References