Lab 3: Memory Component


This project is part of the simulator project, meaning it is a group project.

We will need a memory component for the simulator. Actually, we will need three different memory components in the machine: the instruction memory, which is 16-bits wide, and two 8-bit memory components, one holding program data, and the other for those internal registers. This situation is an ideal case for buiding a C++ Template class, but we will not do that here. Instead, you will build two classes, one called Mem8, and one called Mem16

Dynamic Arrays

We will build these using dynamic memory. The constructor for this class need to get a parameter indicating how many memory slots we need to build. Properly, you need a Destructor to free up the allocated memory.

Look up the C++ new operator for help in setting up this array. Use the uint8_t or uint16_t data types for the memory slots. When an object is created from this class, the amount of memory requested will be allocated at runtime. You will store the address of the block of memory you get in a pointer attribute.

Class Attributes

Set up this class with private attributes, which will be registers in the memory component. (These are not the same as the system registers. Those will be modeled using one of these memory objects.)


  • MADDR - a 8/16_bit address variable
  • Din - a 8/16 bit input data register (pins)
  • Dout - a 8/16 bit output data register (pins)
  • READ - a Boolean indicating a read if true, else a write
  • size - an integer indicating how many slots we need
  • MEM - an array of size unsigned data elements

For this exercise, the inputs and outputs are simple class attributes that you can manipulate.

Set up the class with mutator methods that can set all of these variables

Use this naming scheme:

  • set_MADDR - records a value in the MADDR register.
  • get_Data - read the value in the Dout register
  • set_Din - set input data value in the Din register
  • set_READ - set read/write boolean

You will need another method, our old friend tick.

  • tick - complete the internal operations.

Memory Component Operation

This component will respond to memory requests issued by the controller. To test the component, you need to exercise both read and write operations.

The process for reading goes like this:

  • set the MADDR register value
  • set the READ signal TO TRUE
  • call tick
  • retrieve the indicated memory item and store it in the Dout register

The process for writing goes like this:

  • Set the MADDR register value
  • Set the Din register with the value to write
  • Set the READ signal TO FALSE
  • call tick
  • store the data item in the indicated memory slot

Testing The Memory Component

Set up a test program that exercises the memory module. Ideally, you should initialize the memory with random data in the constructor, but that is not essential. If you wish, you can set the memory slots to some known value when it is constructed.

Be sure to test your component for proper operation using addresses that may be outside of the memory area limits. In this case, the required number of bits will be used, not the full address value. For example, if only 256 slots are available, that is the low 8 bits of the address only.

We will modify these memory classes slightly when we integrate them into our simulator.