Logic Gates to Computer Memory

Kamil Budagov
6 min readJan 15, 2023

--

Introduction

Computer memory is used for storing information in the form of bits. Text, images, and sounds are all stored in memory as a series of zeros and ones. In this story, I explain how memory is made from simple logic gates and how read and write operations are performed in memory.

Flip-Flop

In the following diagram, a flip-flop is described, which is a simple device for storing one bit of information.

Figure 1: Flip-Flop

As shown in the truth table, when s is set to 1, the output will repeat the input. On the other hand, when s is set to 0, the output will stay the same, disregarding the input. Therefore, we can use the flip-flop as a memory for storing 1-bit information.

Figure 2: Truth table

With knowledge of its internal structure, we can demonstrate flip-flop as follows:

Register

Since we have a device called a flip-flop for storing 1 bit of information, we can use 8 of them for storing 1 byte of information, which can represent one symbol of text or one pixel of an image. In Figure 3, we have illustrated how 1 byte of information can be stored with 8 flip-flops.

Figure 3

According to the truth table, when s is set to 1, the outputs will repeat inputs, but outputs will not be affected by inputs when s is 0. So by setting s to zero, we can use this system as a memory holding 1 byte of information. and by setting s to 1, we can change the content of this information by updating outputs for each flip-flop. In short, we can show Figure 3 as follows:

A circuit in Figure 4 is used to enable inputs to update outputs.

Figure 4

Since we use AND gates, all outputs become zero when the enable bit (e) is zero. By setting e to 1, we can update the byte with the input values. In short, we will show Figure 4 as follows:

Finally, we can create a register by combining the last two elements. The register is known as the main memory element. In Figure 5, the register is illustrated

Figure 5

In this configuration, by setting s to 1, we actually update the content of the information in the byte (B), while by activating the enable bit, we can transfer this information to the bus for updating the content of other registers on the same bus. In compact form, we will show the register in Figure 5 as follows:

To summarize, the s bit in the register is used for updating the content of the byte, while the e bit is used to transfer this content to the bus. We can make further simplifications by showing the register as follows, keeping in mind that there are 8 lines in the bus:

Now let us consider how we can share information in one register with another register through the bus. In the following diagram, the bus is assumed to contain 8 lines.

Assume we want to share the content of the R1 register only with the R3. First, the data in R1 should be transferred to the bus before it is received by R3. In the first step, all registers' set bits are set to zero, indicating that registers retain their contents regardless of the data on the bus. The content of the R1 register is then transferred to the bus by setting an enable bit to 1 and immediately to 0. Finally, the set bit of the R3 register is set to 1 and immediately to 0, copying the data on the bus. In this way, communication between registers is performed.

Multiplexer

A multiplexer is a device that is used for specifying certain registers in memory where read or write operations are going to be performed. In Figure 6, internal structure of simple multiplexer is illustrated

Figure 6: 2x4 Multiplexer

With a 2x4 multiplexer, we can specify four different registers, while with a 3x8 multiplexer, it is possible to specify eight different registers.

3x8 Multiplexer

Similarly, we can specify 16 (2⁴) different registers with 4 bits.

Memory

By connecting the simple elements, namely registers and multiplexers, with conductors, we can create memory. In Figure 7, basic memory is illustrated

Figure 7

As shown in Figure 7, our memory is made up of 16x16 = 256 cells, each with 1 register containing 1 byte of data. The first four bits of the shown register specify a certain column, while the last four bits specify a desired row. In this way, any cell in the memory can be specified.

In the following diagram, connections between the grid and one of the 256 registers are shown. With the help of multiplexers, we first specify a certain register by making the red (column) and gray (row) lines active (set to 1). As a result, the orange line becomes active, so setting and enabling bits in register (R) will copy the values from the common s and e lines. After specifying, if we want to write data to register R from the bus, s line becomes 1 and e line becomes 0. For another operation, which is to read data from the register, we set s equal to zero and e equal to one. In this way, the data inside the register is transferred to the bus, where it can be sent somewhere else.

Register to Memory connection

Additional

Figure 8 depicts 256x256 = 6,5536 or 64 kB of memory, which operates on the same principle as previously discussed.

Figure 8

Conclusion

In this story, we witnessed the power of a simple logic gate. Logic gates are also used for building the Arithmetic Logic Unit and Central Processing Unit, which are other parts of the computer. In modern computers, hundreds of millions of logic gates are used. In order to understand the other parts of computer namely CPU and ALU in a digestible way, I recommend the book in the reference.

Reference

But How Do It Know? — The Basic Principles of Computers for Everyone

By J. Clark Scott.

--

--