[From the last episode: We put the various pieces of a memory together to show the whole thing.]
Before we finally turn our memory discussion into an AIA broad term for technology that acts more human-like than a typical machine, especially when it comes to "thinking." Machine learning is one approach to AI. discussion, let’s take on one annoying little detail that I’ve referred to a few times, but have kept putting off.
Just a Bit!
Remember that thing about selecting a word lineA line in a memory that selects which word (and its associated bit cells) will be selected for reading or writing, based on the memory address. The word lines and bit lines are orthogonal to each other, making an array of the bit cells that connect them. to give a byteA byte is 8 bits. (or more) of output at the same time? So, how do you get to a specific bit instead of a bunch of bitsThe smallest unit of information. It is a shortened form of "binary digit." Since it's binary, it can have only two values -- typically 0 and 1.?
Well, first of all, you probably don’t need to. ProcessorsA computer chip that does computing work for a computer. It may do general work (like in your home computer) or it may do specialized work (like some of the processors in your smartphone). and softwareIn this context, "software" refers to functions in an IoT device that are implemented by running instructions through some kind of processor. It's distinct from "hardware," where functions are built into a silicon chip or some other component. assume that, when you get data from memory, you’ll get at least a byte – probably more. And processors are designed to work on at least a byte at a time (for large processors, it’s 32 or even 64 bits at a time).
For simplicity and continuity, let’s assume you get a byte. If you want to look at a specific bit, there are ways to do that in the processor using “masking” techniques that effectively block out all the bits except the one you want.
Let’s Be Logical About This…
Let’s say that you have retrieved a byte from memory, and the byte is 10110001. What if you want to look at just the fourth bit from the right (which is 0)? You use a logical operation.
There are several logical operations, but we’ll focus on the AND function. And we’ll assume for our discussion that a 1 means TRUE and a 0 means FALSE. If you take two inputs and AND them together, then you get a TRUE or 1 result only if both inputs are 1. In other words, the output is TRUE only if input 1 AND input 2 are TRUE. If one of them is FALSE (or 0 in our case), then the result will be FALSE (or 0).
So:
- 0 AND 0 is 0
- 0 AND 1 is 0
- 1 AND 0 is 0
- 1 AND 1 is 1
We can create a mask for our byte and then AND the mask and the byte together to isolate the bit we want. That mask will look like this: 00001000. In other words, we put a 1 in the position of the bit we want to see. All of the other bits are set to 0.
Detecting a 0 Bit
Now we AND the two bytes together, meaning that we AND each of the corresponding bits in the byte we’re looking at and the mask:
In other words, in each bit position, there’s a 0 either in the byte we’re testing or in the mask, and anything ANDed with 0 gives 0. Seem like a waste? Nope! It tells us that the bit we’re interested in had value 0 – which is correct.
Detecting a 1 Bit
What if want the 5th bit from the right, which has the value 1? Then we use a different mask: 00010000, again, with the 1 in the position of the bit we want to see. Now we do the same thing:
Here we get a non-zero result because, in the 5th position, we were ANDing 1 and 1, which gives 1. So that way we can see that the bit we’re interested in has value 1. (For folks with logic in their background, this will be obvious. But it might not be for you. You may want to reread this a couple times for it to click.)
We use the name “mask” because all of the 0s naturally turn the result for that bit into a 0 result – masking those bits out. We only get to see the value of the bit that’s 1 in the mask. And yes, you can mask to see more than just one bit also. If you want to see both the 4th and 5th bits from the right, you’d mask with 00011000.
Muxing It Up
There’s a siliconAn element (number 14 in the periodic table) that can be a semiconductor, making it the material of preference for circuits and micro-mechanical devices. circuit way to do this if you want, and we need to look at a new component for that. It’s a little bit like a decoder, although not quite. It’s called a multiplexer, or a mux for short. That’s a fancy word for something that, given a choice of a bunch of things, selects only one of them.
Here’s a super simple example of a 2-to-1 mux (or a 2:1 mux). It has two inputs and one output, and then there’s a select signal. Assuming everything is binaryA base-2 counting system (rather than the base-10 system we usually use). Digits can be 0 or 1. here, then if the select signal is 0, the output will reflect whatever is on In1. If the select signal is 1, then the output will reflect whatever is on In2. It doesn’t change whatever is on In1 or In2; it simply decides which one to pass to the output. The one that’s not selected is blocked. (Hint: it does this internally using AND logic!)
How is this different from a decoder? With a decoder, we have a bunch of outputs, and we’re selecting one of those outputs to go high. Here, we’re presented with a choice of inputs, and we’re selecting one of them to pass through to a single output.
It’s simple for a 2:1 mux, but we can also do any number of inputs. But, for more inputs, we need more select signals, since a single select signal lets us select only between two inputs. If we want to select one of four inputs, then we need two bits of selection. And if we want to select one of eight inputs, then we need three bits. A table for that last one would look like this:
We can draw the mux as follows:
What if We Do this In the Memory Itself?
So, if we wanted to create a memory that would give us just one bit instead of a byte, then we can add this mux to the output. Remember the 3 addressWhen referring to memory, a binary number that shows where, within some memory block, the data you want is located. If you want to read or change that data, you have to give the address so that the right data is read or changed. bits we discarded before? Well, here they are: they’re the 3 select bits on the mux!
Most memories don’t work this way, but a mux is a common logic component, so it’s a useful thing to know about, and this is a way both to see it in action and to explain what happened with those 3 address bits.
Leave a Reply