Lab 5: Memory Component

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 dynaic 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 two 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
  • MDR - a 8/16 bit data variable
  • READ - a Boolean indicating a red if true, else a write
  • WRITE - boolean indication a write operation

Note that you should not be able to set both READ and WRITE at the same time.

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_MDR - read the value in the MDR register

You will need another method, our old friend tick.

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
  • call tick
  • retrieve the indicated memory item and store itin the MDR register

The process for writing goes like this:

  • Set the MADDR register value
  • Set the MDR register with the value to write
  • Set the WRITE signal
  • 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.