Help with 16 Bit Program Counter

In summary, the conversation is about someone having difficulty with a project to build a 16-bit program counter while reading "The Elements of Computing Systems" for pleasure. They provide a HDL file and a table of inputs and outputs at different time sequences. They eventually figured out the issue and thanked anyone who was looking for their help.
  • #1
cu44
2
0
Hi all,

First a little background. I am reading "The Elements of Computing Systems"
and one project was to build a 16 bit program counter but having a tough time.
I am reading for pleasure not for any course. The following pc hdl file gives me the proper output (listed below pc file) up to time 3+ the gets off track and can not seem to figure it out. Any help/guidance would be greatly appreciated.
Thanks, Paul

// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/03/1/PC.hdl

/**
* 16-bit counter with load and reset controls.
*
* If reset(t-1) then out(t) = 0
* else if load(t-1) then out(t) = in(t-1)
* else if inc(t-1) then out(t) = out(t-1) + 1 (integer addition)
* else out(t) = out(t-1)
*/

CHIP PC {

IN in[16], load, inc, reset;
OUT out[16];

PARTS:


Mux16(a=regOut1, b=false, sel=reset, out=rOut);
Mux16(a=rOut, b=in, sel=load, out=regOut);
Register(in=regOut, load=load, out=regOut1);
Inc16(in=iOut1 , out=iOut);
Register(in=iOut, load=inc, out=iOut1);
Mux16(a=regOut, b=iOut1, sel=inc, out=rOut2);
Mux16(a=regOut1, b=iOut1, sel=inc, out=out1);
Mux16(a=out1, b=regOut1, sel=load, out=out);

}

INPUTS AND OUTPUTS AT EACH TIME SEQUENCE

| time | in |reset|load | inc | out |
| 0+ | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1+ | 0 | 0 | 0 | 1 | 0 |
| 2 | 0 | 0 | 0 | 1 | 1 |
| 2+ | -32123 | 0 | 0 | 1 | 1 |
| 3 | -32123 | 0 | 0 | 1 | 2 |
| 3+ | -32123 | 0 | 1 | 1 | 2 |
| 4 | -32123 | 0 | 1 | 1 | -32123 |
| 4+ | -32123 | 0 | 0 | 1 | -32123 |
| 5 | -32123 | 0 | 0 | 1 | -32122 |
| 5+ | -32123 | 0 | 0 | 1 | -32122 |
| 6 | -32123 | 0 | 0 | 1 | -32121 |
| 6+ | 12345 | 0 | 1 | 0 | -32121 |
| 7 | 12345 | 0 | 1 | 0 | 12345 |
| 7+ | 12345 | 1 | 1 | 0 | 12345 |
| 8 | 12345 | 1 | 1 | 0 | 0 |
| 8+ | 12345 | 0 | 1 | 1 | 0 |
| 9 | 12345 | 0 | 1 | 1 | 12345 |
| 9+ | 12345 | 1 | 1 | 1 | 12345 |
| 10 | 12345 | 1 | 1 | 1 | 0 |
| 10+ | 12345 | 0 | 0 | 1 | 0 |
| 11 | 12345 | 0 | 0 | 1 | 1 |
| 11+ | 12345 | 1 | 0 | 1 | 1 |
| 12 | 12345 | 1 | 0 | 1 | 0 |
| 12+ | 0 | 0 | 1 | 1 | 0 |
| 13 | 0 | 0 | 1 | 1 | 0 |
| 13+ | 0 | 0 | 0 | 1 | 0 |
| 14 | 0 | 0 | 0 | 1 | 1 |
| 14+ | 22222 | 1 | 0 | 0 | 1 |
| 15 | 22222 | 1 | 0 | 0 | 0 |
 
Physics news on Phys.org
  • #2
Never mind I figured it out. thanks for looking.
 
  • #3


Hi Paul,

It seems like you have made a lot of progress in building your 16-bit program counter. However, I can see that there are some issues with the output after time 3+. It would be helpful if you could provide more information about what you have tried and what specific issues you are encountering.

One thing that stands out to me is that you are using integer addition in your code. While this may work for some inputs, it may not be the most efficient or accurate way to increment the program counter. I would suggest looking into using binary addition instead.

Additionally, you may want to double check your Mux16 and Register components to make sure they are functioning correctly. It is possible that there may be a mistake in your code that is causing the output to become off track after time 3+.

I would also recommend breaking down your code into smaller parts and testing each component individually. This can help you identify any errors and make troubleshooting easier.

I hope this helps and good luck with your project!
 

Related to Help with 16 Bit Program Counter

1. What is a 16 bit program counter?

A 16 bit program counter is a register in a computer's central processing unit (CPU) that stores the memory address of the next instruction to be executed. It is used to keep track of the current position in a program's sequence of instructions.

2. How does a 16 bit program counter work?

When a program is running, the 16 bit program counter is incremented after each instruction is executed, pointing to the next instruction in memory. It allows the CPU to fetch and execute instructions in sequence, enabling the program to run.

3. What is the significance of a 16 bit program counter?

A 16 bit program counter allows a computer to access and execute instructions from a large range of memory addresses. With a 16 bit program counter, a computer can address up to 65,536 memory locations, allowing for more complex and larger programs to be executed.

4. How does a 16 bit program counter differ from an 8 bit program counter?

A 16 bit program counter can store and access twice as many memory addresses as an 8 bit program counter. This means that a 16 bit program counter can handle larger and more complex programs, while an 8 bit program counter is limited in its ability to address memory.

5. Can the 16 bit program counter be modified or reset?

Yes, the 16 bit program counter can be modified or reset by the computer's operating system or by the program being executed. This allows for branching and looping in programs, where the program counter is directed to different memory addresses based on certain conditions or instructions.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
13K
Back
Top