Memory

Written politely 2021-07-24.

As we continue on our journey to Building a Modern Computer, we come into the need to remember chip output in time. It is only when we need to recall something that happened in the past from one of our chip’s outputs, or if we want to store it to use later, that we run into the issue of how do we store values. If you are new to the series, you can begin here to get caught up to this week, or if you missed the last post, I have you covered.

3.1 Sequential Logic, or how computers do one thing after another

Up until this point, our chips were given inputs, and we got an output. We didn’t have a sequence of values, just inputs and outputs. Computers work during time do not have a relationship to their past events or future requirements. We want to use the same piece of hardware to perform computations again and again, but not just because we need the value again. We need to remember things. Just as humans do, computers use memory to streamline the process of performing calculations once and recalling them again and again.

The Clock

Computers work at a finite speed, so we need to know how fast our computer can run. We are taking continuous time and will divide it into discrete time. Within each of these divisions of time, nothing will change. The computer does not create outputs instantly, but it takes time for the computations to occur on the input to receive the output. It is recommended that these delays should be larger than the time units for our chips to run their computations to make a system that runs smoothly.

If the time units were shorter than the computational output time of our chips, the result will most likely be incomplete and not accurate. Remember that standardized test that you didn’t have time to finish but didn’t get punished for wrong answers? You just filled in answers to complete the test but didn’t have time to calculate the correct results. That is what happens when our time units in the computer are set shorter than the time it takes for our chips to complete their computations.

Combinatorial Logic vs Sequential Logic

Units 1 & 2 were combinatorial logic units. Sequential logic is the value of the input at a certain point of time. Sequential logic depends on time t. If t is now, the previous unit of time is t - 1 and the next is t + 1. The input a at time t can be found by evaluating the output f(a) at time t, but to keep our logic compartmentalized, the output can be fount at time t + 1. These value can live in state, which could be a single bit according to the time t.

Combination Logic vs Sequential Logic

3.2 Flip Flops

In order for us to get the ability to recall outputs that happen in the past, we can start by talking about Flip Flops. Flip Flops will move a single bit from time t - 1 to time t. This element must remember the bit from time t - 1 at the same time a new output is created at time t. Continuing, a new input is created at time t that will be evaluated by time t + 1. The bit needs to be able to flip (0 -> 1) or (1 -> 0) in order to specify the output t or t - 1, and in the future, t + 1 or t.

The “Clicked Data Flip Flop”

The data bit is flip flopping at every time unit. When we begin with an input bit value of 1 at time 1, for example, the output is not currently known because the output depends on the previous input and the previous input is unknown. The next time 2 we could have an input value of 0 and the output that is the flip flop of the input of the previous time 1, which would be 0 (as the input value at time 1 was 1 and flipping that bit yields 0). And this continues as shown in the chart below.

Time 1 2 3 4 5
Input 1 0 0 1 1
Output 0 1 1 0

Now that we can remember one bit, we can build upon that to do everything else.

One bit data flip flop

1-bit Register

The 1-bit Reigster is a chip to remember the output for 1 time unit. The goal is to remember the input bit “forever” or until it is requested. The chip should remember the output until there is a new input at a different later time and the remembered output can be taken from the chip. For instance, if the time is t, then out(t) = in(t-1). Otherwise, the out(t) = out(t - 1).

Time 1 2 3 4 5
Load 1 0 0 1 1
Input 1 0 0 1 1
Output 1 0 0 1

How do we get the chip to remember the output value until it is changed. One way would be to feed the output back into the input. But that won’t exactly work.

Chip output fed back into itself

Instead, we can use a MUX chip to use the load as the selector, the input as the a input and the output of the MUX run through a DFF fed back into the MUX chip as input b. We keep the input from in and keep it until it is asked for. Once we have 1-bit memory, we can use it to build multi-bit memory.

1-bit register

The image above and a discussion of it can be found here.

3.3 Memory Units

Memory can mean many different things: main memory that exists in the motherboard, such as RAM, or secondary memory such as hard disks and external memory drives.

Register

The most basic memory element is Register. Register has a width specified for the number of bits it uses, such as 8, 16, 32, or 64 bit, etc. and the register’s state is the value which is currently stored inside the register.

How do we read the value of the register? We get the value from out and we hold it there until we want to get it out.

RAM (Random Access Memory)

RAM is a sequence of addressable registers and we access only one register at a time. To access a register, we use the register address in the RAM. The same address value can be used to set and also to get the input value from a specific register in the RAM.

In this course we will build a family of RAM chips. RAM8 with an address width of 3, RAM64 with an address width of 6, RAM512 with an address width of 9, RAM4K with an address width of 12, and RAM16K with an address width of 14. These address widths are the number of bits of Log n, or the number of bits required to make the number in binary. For instance, log 8 = 3 or 23 = 8, log 64 = 6 or 26 = 32.

3.4 Counters

Where counters come to play

The PC, or Program Counter is the final chip we will build in this unit and it has some functions that it can compute using a single bit for each. The PC can Reset the value, or fetch the next instruction. It can also Increment the value, or fetch the next instruction. It can also Goto a register, or fetch the instruction at n. Basically, in the chip if Reset is set to time 1, the counter is reset to 0. If Increment is set to 1, the counter is increased by 1. If load is set to n, the counter returns the value at that register address.

Summary

When we put the knowledge learned in this chapter with the others, we can get some exciting beginning to our modern computer. So far, we have something that starts to resemble what we think of as a modern computer.

Program Counter

The next step is to actually build these projects using in HDL using our hardware simulator. I will see you next week for a review of building these new more advanced chips as we progress together on this journey of building a modern computer.


Lucas McDaniel

Husband, father, teacher, musician, avid gamer, nature enthusiast, and passionate about the human condition.