Section 7: Verilog Memory Arrays
In this discussion section, you will use what you have learned in the previous discussion sections to implement a simple register file memory array at the register-transfer level (RTL). In the past discussion sections, we have focused on how to use Verilog to model combinational and sequential logic at both the gate-level and RTL. In this discussion section, we will only be using RTL. Remember from previous discussion sections that it is critical that students always know what is the hardware they are modeling; students should understand what their RTL would likely turn into at the gate-level.
1. Logging Into ecelinux with VS Code
We have drastically simplified the process of logging into ecelinux
with VS Code using the workstations. Find a free workstation and log into
the workstation using your NetID and standard NetID password. Then
complete the following steps:
- Open the ECE 2300 folder on the desktop to locate two shortcuts
- ECE 2300 Handouts: opens the handouts page
- ECE 2300 VS Code: starts VS Code (enter server number and password)
That is it! Our custom ECE 2300 VS Code script will take care of:
- installing Remote SSH, Verilog HDL, Surfer extensions
- configuring SSH for accessing
ecelinuxwithout extra prompts - starting VS Code connected to
ecelinuxwithout extra prompts - opening the file explorer in your
${HOME}/ece2300directory - installing the Verilog HDL extension on the server
- opening a terminal
There is no need to fork the repo for today's discussion section. Simply clone the repo as follows.
% source setup-ece2300.sh
% mkdir -p ${HOME}/ece2300
% cd ${HOME}/ece2300
% git clone git@github.com:cornell-ece2300/ece2300-sec07-verilog-mem sec07
% cd sec07
% tree
The repo includes the following files:
Makefile.in: Makefile for the build systemconfigure: Configure script for the build systemconfigure.ac: Used to generate the configure scriptscripts: Scripts used by the build systemece2300: ECE 2300 unit testing library and miscellaneous macrosmem/mem.mk: Tells build system about files in this subprojectmem/Mux4_4b_RTL.v: 4-to-1 4-bit mux in RTLmem/Decoder_RTL.v: 2-to-4 binary decoder in RTLmem/Register_RTL.v: 4-bit register with enable in RTLmem/Regfile1r1w_4x4b_struct_RTL.v: Register file using structural RTLmem/Regfile1r1w_4x4b_flat_RTL.v: Register file using flat RTLmem/test: Directory with unit tests for each hardware module
Go ahead and create a build directory, run configure to generate a Makefile, and run the tests.
To make it easier to cut-and-paste commands from this handout onto the
command line, you can tell Bash to ignore the % character using the
following command:
Now you can cut-and-paste a sequence of commands from this tutorial
document and Bash will not get confused by the % character which begins
each line.
Throughout this handout you will see discussion check-off tasks. The TAs will not be assessing your understanding. Instead, students should show their work to another student and then together they will perform a self and peer assessment of each discussion check-off task. The student peer will initial the check-off. As always, the assesssment should based on the demonstrated understanding using our five-point scale as follows:
-
5 (Mastery): Student mastered the check-off without any help and feels very confident in their understanding; student could teach other students about the corresponding concepts
-
4 (Accomplished): Student accomplished the check-off with maybe a little help and feels good about their understanding, but could probably use a little more time to really master their understanding; student is probably not quite ready to teach other students about the corresponding concepts
-
3 (Progressing): Student completed the check-off but needed significant help; student is not quite confident in their understanding and needs more time to really improve their understanding of the corresponding concepts
-
2 (Beginning): Student started but did not finish the check-off
The goal is not for one student to judge another student, but for the two students to agree on the demonstrated level of understanding. There is nothing wrong with agreeing on a 4 or 3. This can help a student crystallize where they should focus their time to improve the understanding!
Near the end of the discussion section, the student should raise their hand and show their overall progress to a TA who will initial and collect the check-off sheet.
Discussion section check-off sheets are not graded!
Unlike the lab check-off sheets, the discussion check-off sheets are not graded. They will not impact your grade in the course in any way. The discussion check-off sheets provide formative self and peer assessment. They enable students to gauge their progress in mastering the concepts presented in the discussion section, and enable the instructors to get an overall feel for how the class is doing. Please make sure your self and peer assessments are honest and accurate!
Discussion Check-Off Task 1: Verify Initial Release
We always start by running make check to get a high-level view of
what is and is not working. So go ahead and do make check again and
look closely at what tests are passing and what tests are failing.
Show a peer student the result of make check. Work together to
conduct a self and peer assessment and have the peer student initial
the check-off.
2. Memory Arrays
A memory array is a two-dimensional array of sequential logic gates (also called "bit cells"). The following diagram illustrates the high-level idea for a memory array.

In this discussion section, we will be building a register file, a
specific kind of memory array where D flip-flops are used as the
sequental logic gates. You will start by implementing a 4-to-1 4-bit mux,
2-to-4 decoder, and 4-bit register. You will then implement a 4-word
4-bit register file memory array in two ways: (1) structurally by
composing the mux, register, and decoder; and (2) flat using a single
always_ff block and assign statements.
3. 4-to-1 RTL Multiplexor
We have provided you the interface for the mux in Mux4_4b_RTL.v.
Use what you have learned about RTL modeling to create a Verilog hardware
design that implements a 4-to-1 4-bit mux. You should have a single
always_comb block with a case statement. We provide you all of the
tests you need. You can run the test simulator for the mux as follows.
Discussion Check-Off Task 2: Verify 4-to-1 RTL Multiplexor
Show a peer student your implementation for the 4-to-1 RTL
multiplexor. Explain to your peer how your implementation avoids
X-optimism (i.e., ensures that if sel is X then the output should
be X). Then show the peer student your implementation passing all
of the tests.
4. 2-to-4 RTL Decoder
We will now implement a 2-to-4 binary decoder using RTL modeling. Recall that a decoder takes as input a binary number and produces a one-hot encoding of that binary number. If the input is 0, then bit 0 should be 1 and the remaining bits should be 0. If the input is 1, then bit 1 should be 1 and the remaining bits should be 0.
We have provided you the interface for the decoder in Decoder_2b_RTL.v.
Use what you have learned to create a Verilog hardware design that
implements a 2-to-4 decoder. You should have a single always_comb block
with a case statement. We provide you all of the tests you need. You
can run the test simulator for the decoder as follows.
Discussion Check-Off Task 3: Verify 2-to-4 RTL Decoder
Show a peer student your implementation for the 2-to-4 RTL decoder. Then show the peer student your implementation passing all of the tests.
5. 4-bit RTL Register
We will now implement a 4-bit register with enable (but no reset!) using
RTL modeling. We have provided you the interface for the register in
Register_4b_RTL.v.
Use what you have learned to create a Verilog hardware design that
implements a 4-bit register. You should have a single always_ff block
with an if/else conditional operation to handle the enable signals. You
will need to correctly handle explicit X-propagation to avoid X-optimism.
We provide you all of the tests you need. You can run the test simulator
for the register as follows.
Discussion Check-Off Task 4: Verify 4-bit RTL Register
Show a peer student your implementation for the 4-bit RTL register.
Explain to your peer how your implementation avoids X-optimism (i.e.,
ensures that if en is X then the output should be X). Then show
the peer student your implementation passing all of the tests.
6. Structural Register File
A memory array is a two-dimensional array of sequential logic gates (also called "bit cells"). A register file is a specific kind of memory array where D flip-flops are used as the sequental logic gates. We can implement a register file structurally using the mux, decoder, and register developed earlier in this discussion section.

This register file has four "words" and each word is 4-bits. The register file has one write port and one read port (i.e., we can do a 4-bit write and a 4-bit read at the same time). The read port is combinational; if we set the read address then the read data comes back that same cycle (i.e., combinationally).
We have provided you the interface for the register file in
Regfile1r1w_4x4b_struct_RTL.v:
Notice there is no reset signal. Register files often include many bit cells and the hardware required to reset every single bit cell can be significant; so register files usually do not include a reset signal.
The following construct creates an array of multi-bit signals:
This creates an array of four signals, each signal is four-bits. This can be a useful way to create an array of multi-bit signals for the output of each register.
Use what you have learned to create a Verilog hardware design that implements a 4-word 4-bit register file. We provide you all of the tests you need. You can run the test simulator for the register file as follows.
% cd ${HOME}/ece2300/sec07/build
% make Regfile1r1w_4x4b_struct_RTL-test
% ./Regfile1r1w_4x4b_struct_RTL-test
Discussion Check-Off Task 5: Verify Structural Register File
Show a peer student your implementation for the structural register file. Then show the peer student your implementation passing all of the tests.
7. Flat Register File
We can also implement a register file flat using a single always_ff
block for the write ports and an assign statement for the read port. This
register file has the exact same interface as the structural version
implemented in the previous section.
We will use an array of signals to act as the state.
You can read and write four-bit signals from this array by simply indexing into it. So the following will write the binary value 0011 into the second signal in this array.
Implement the flat register file using a single always_ff block and a
single assign statement. We provide you all of the tests you need. You
can run the test simulator for the register file as follows.
% cd ${HOME}/ece2300/sec07/build
% make Regfile1r1w_4x4b_flat_RTL-test
% ./Regfile1r1w_4x4b_flat_RTL-test
Discussion Check-Off Task 6: Verify Flat Register File
Show a peer student your implementation for the flat register file.
Explain to your peer how your implementation avoids X-optimism (i.e.,
ensures that if wen is X then the output should be X). Then show
the peer student your implementation passing all of the tests.
8. Clean Build
As a final step, do a clean build to verify everything is working correctly.