2 bit multiplier?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

2 bit multiplier?

MrPostnikov
This post was updated on .
I am not sure if anyone every tired this, but after solving for the ALU part, wanted to add more to the chip.
I wanted to add a multiplication capabilities.

This is the implement I tired:

 CHIP Mul2bit {
    IN  a[2], b[2];
    OUT out[4];

    PARTS:
    // First row of AND gates
    And(a=a[0], b=b[0], out=c0);
    And(a=a[0], b=b[1], out=w1);

    // Second row of AND gates
    And(a=a[1], b=b[0], out=w2);
    And(a=a[1], b=b[1], out=w3);

    // First half adder
    HalfAdder(a=w1, b=w2, sum=c1, carry=carry1);

    // Second half adder
    HalfAdder(a=w3, b=carry1, sum=c2, carry=c3);

}

I also tried this as well:

CHIP Mul2bit{
    IN a[2], b[2];
    OUT out;

    PARTS:
   
    And(a=a[0], b=b[1], out=w1);
    And(a=a[0], b=b[0], out=c0);
   
    And(a=a[1], b=b[0], out=w2);
    And(a=a[1], b=b[1], out=w3);
    And(a=w1, b=w2, out=w4);
    And(a=w4, b=w3, out=c3);
   
       
    Xor(a=w1, b=w2, out=c1);
    Xor(a=w4, b=w3, out=c2);
}

However, the problem I was having is that I needed to make a .tst and the .cmp files. I don't understand the .cmp, I am not sure what exactly it does. I also don't quite understand how the .tst file should be written with what syntax. Has anyone tired to make a custom chip? If you did make a custom chip did you have to write your own .tst file and .cmp file?

Some other questions I have is that, I was planning on building it up to 4bit multiplier, that said, would I need to implement it into the ALU and all of its .tst file and .cmp? Meaning would I need to update the truth table in .cmp file?

NOTE I CHANGED THE QUESTIONS A BIT TO MAKE IT MORE CLEAR WHAT I AM ASKING!
Reply | Threaded
Open this post in threaded view
|

Re: 2 bit multiplier?

WBahn
Administrator
The .tst file is a script file that makes the simulator take certain actions. The script language is pretty rudimentary. Since it is not intended that students write their own test scripts, it isn't very well documented. But if you examine the existing test scripts, starting with the simple ones from early chapters, it's not too hard to figure out.

The test script produces an output file and then has it compared to the .cmp file.

The easiest way to generate the .cmp file is simply to run the test script on a known good design and then change the name of the output file to .cmp.

Of course, if you don't have a known good design, this isn't easy.

But you can also write the .cmp file manually (or you could write a program to do it) based on what inputs the test script is providing and what the outputs should be for those inputs.

I don't have time right now to go any deeper, but perhaps in a day or two after I get some other things done.
Reply | Threaded
Open this post in threaded view
|

Re: 2 bit multiplier?

MrPostnikov
Thank you for the reply. I did see that in the .cmp files everything seems to be in a truth table format.
I also had the same idea of simply copying output of the file and then pasting it into the .cmp. However, this assumes as you pointed out that my design is accurate. As the HDL program will not know the difference. However, this brings back to the question, how do you make a .tst script based on HDL file? I was in the hope that there was a tool in hdl that runs through the file and generates the .tst for it. That way even if it runs without errors, I can see the output and know if the truth table seems accurate. I can do this by hand but it would save time by simply having the program doing for me. I know in general what the output should look like but I maybe doing something wrong in the HDL. Like connecting pins improperly.

I was hoping someone would take a look at my previous question HDL codes and tell me if I am doing something wrong?