Building Memory With Logic Gates

Zaid Humayun
The Startup
Published in
12 min readDec 14, 2018

--

Introduction

In a previous post, I discussed how computers built initially did math using logic gates. I also went over how you could replicate this with code in JavaScript.

I am going to attempt to do something much more ambitious in this post. I am going to attempt to replicate RAM in a similar fashion.

Holding State

In the previous post, we discussed binary numbers and how the presence or absence of electricity in a circuit can be modeled as a 0 or a 1 respectively.

However, a fundamental problem with electrical circuits is that they are transient. They can’t hold state of their own. For example, from one second to the next, a wire has no idea whether electricity passed through it in the second prior.

Let’s fix that problem with some logic gates. I’ll show you three different images showing different variations of the same circuit.

Source: CODE by Charles Petzold

The two logic gates being used in the above set of images are NOR gates. Here is the truth table for a NOR gate.

Let’s look at image one first. The NOR gate on the left has an output of 1 because both its inputs are 0 initially.

If you close the gate on top, the output of the NOR gate on the right becomes 1 because both its inputs are now…

--

--