Sunday, April 13, 2025

Entry 27: Program counter and memory system

Testing the program counter and the memory system

We designed the program counter in entry 26. Let's hook it up to the address bus and to the memory system to make sure that these two component can interact. This is what I want to test:

  1. Incrementing the program counter (PC)
  2. Sending the the value of the PC to the Memory Address Register (MAR) over the address bus
  3. Updating the PC by sending a new address from RAM to the PC over the data bus.

I also add a new OUT register The purpose of this register is to display the result of whatever operation the computer has performed. I will hook it up like this:

I will use the following four control pins on the PC:

  • Count (Count = 1 will increase count when Clock goes high): COUNT
  • Write (Write = 1 enables W and puts count on address bus): PCW
  • Load (Load = 1 sets the count to the value on the data bus D): PCL

I will also use the Load control pin on the OUT register: OUTL. The memory system was designed in entry 21:

I will use the two S-pins of the two MUX's, AS and DS, to set if we are in "programming mode" (programming RAM with the DIP's) or in "computing mode", where RAM takes address and data from the busses, via MAR and MDR. I will also use the following 5 control pins (and names):

  • Load on MAR (Load = 1 loads the address from the address bus, which is then the address seen by RAM if it is in computing mode): MARL.
  • Load on RAM (Load = 1 loads the data on D pins into RAM at address A): RAML.
  • Write on RAM (Write = 1 writes the data at address A to the buses): RAMW.

Try it out on Wokwi: Project "Testing Program counter with memory system". On Wokwi, you can see which chips that are used and the connections that are made.

Step by step instructions to perform the test:

  Testing the Program counter with the memory system
  1. Use the DIP switches to program RAM.
      Put 8 at address 1 and 15 at address 8.
  2. Increase the count in the program counter (PC) (making it equal to 1)
  3. Move the content of PC to MAR so that address is 1 in RAM
  4. Move the content of RAM at address 1 (the number 8) to the PC
  5. Move the content of PC to MAR so that address is 8 in RAM
  6. Move the content of RAM at address 8 (the number 15) to the OUT register


  Step by step:
    Set DIP 1 to ON on the address DIP's (left)
    Set DIP 1 to ON on the data DIP's (right)
    This takes us into "programming mode" where the DIPs determine address and data  
    Program: 8 at address 1, 15 at address 8:
      Set address DIPs to 0001
      Set data DIPS to 1000 (decimal 8)
      Click RAML
      Similarly for address 8 (address: 1000, data: 1111)
    Click Print. Observe RAM and that correct data has been programmed.
    Return to "compute mode" by setting both DIP 1's to OFF
    Increment PC
      Click and hold COUNT (press 4 on keyboard)
      Click Clock to latch
      Click Print. Observe Q = 1 in program counter.
    Move the content of PC to MAR
      Click and hold PCW, MARL (press 3 and 5 on keyboard)
      Click Clock to latch
      Click Print. Observe MAR Q = 1, RAM Address = 1 and RAMQ = 8
    Move the content of RAM at address 1 to the PC
      Click and hold RAMW, PCW (press 2 and 7 on keyboard)
      Click Clock to latch
      Click Print. Observe PC Q = 8
    Move the content of PC to MAR
      Click and hold PCW, MARL (press 3 and 5 on keyboard)
      Click Clock to latch
      Click Print. Observe MAR Q = 8, RAM Address = 8 and RAMQ = 15
    Move the content of RAM at address 8 to the output register
      Click and hold RAMW, OUTL (press 7 and 8 on keyboard)
      Click Clock to latch
    Observe LED bar displays 1111 (15)

Let's move on to programming this stupid thing... in the next entry.