In the world of digital electronics, memory storage is a fundamental concept that underpins the functionality of computers and other digital systems. At the heart of these systems are logic gates and circuits that work together to store and retrieve data efficiently. Today, we’re going to delve into the design of a logic gates circuit capable of storing 4 bytes of information, essentially creating a Random Access Memory (RAM) of 4 bytes.
The Role of D-Type Flip Flops
Central to our design are D-type flip flops, which are crucial for storing bits of data. A D-type flip flop, or Delay flip flop, is a type of bistable logic gates circuit used to delay the change of state of its output until triggered by a clock signal (connected to the Enabler input of the circuit). This characteristic makes it ideal for memory storage because it can “remember” its input state even after the input has changed, provided that the clock signal has not triggered a new update. In our 4-byte RAM circuit, each bit of data will be stored using these D-type flip flops, ensuring that our memory can retain information reliably.
A D-Type Flip-Flop circuit is built using four NAND logic gates connected as follows:
We represent a D-Type Flip-Flop Circuit as follows. You can change the input values D and E by clicking on the corresponding buttons below to see the impact on the outputs Q and Q.
![]() |
You can also test the behaviour of a D-Type flip-flop circuit using our online simulator:

A D-Type Flip-Flop Circuit is used to store 1 bit of information. It has two input pins (Called D (Data) and E (Enabler) and two output pins (Q and Q = NOT Q).
Understanding MDR and MAR registers
To facilitate the transfer of data between the RAM and the Central Processing Unit (CPU), we will incorporate two essential registers: the Memory Data Register (MDR) and the Memory Address Register (MAR).
-
Memory Data Register (MDR): The MDR is an 8-bit register that temporarily holds the data being transferred between the memory and the CPU. When the CPU needs to read from or write to the memory, the data is first placed in the MDR. This allows the CPU to handle data in manageable chunks, in this case, 8 bits or 1 byte at a time.
-
Memory Address Register (MAR): The MAR is a 2-bit register that specifies the address of the memory location being accessed. Since we are designing a 4-byte RAM, we need 2 bits to address each of the 4 memory locations uniquely (as 22=4). The MAR ensures that data is read from or written to the correct memory address, enabling precise data manipulation.
Our four memory addresses will be 0=00, 1=01, 2=10 and 3=11.
Putting It All Together
By combining D-type flip flops with the MDR and MAR, we can create a functional 4-byte RAM circuit. The D-type flip flops will store the bits of data, while the MDR and MAR will manage the data transfer and addressing, respectively. This setup not only provides a clear example of how memory storage works at a fundamental level but also offers a practical application of logic gates in digital electronics.
Below is our 4-Byte RAM circuit with its 32 D-Type flip-flops to store up to 32 bits of data, its 8-bit MDR and 2-bit MAR as well as a Read/Write input, that is used to decide if the RAM is in read mode or write mode.
How to use this circuit?
- Use the 8 switches on the left to assign a value in the MDR. (e.g. #A4 = 164 = 10100100)
- Use the 2 switches at the top to assign a value in the MAR. (e.g. 10 for memory location 2)
- Turn the R/W switch on to store the MDR value in the RAM at the chosen memory location (e.g. 2)
- Turn the R/W switch off and repeat these 4 steps to store different values in each of the 4 memory locations