And gate implement

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

And gate implement

Ben
Hi TA:
I think Nand gate compose Or gate & Not Gate
Nand(a,b)=~a + ~b ,therefore  And=Not(Nand(a,b))=~(~a + ~b)
but I implement using the thinking ,but I always get message from HW simulator a is not pin in Not

my source code is as below:
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.hdl

/**
 * And gate: 
 * out = 1 if (a == 1 and b == 1)
 *       0 otherwise
 */

CHIP And {
    IN a, b;
    OUT out;

    PARTS:
Not(a=a, out=nota);
Not(b=b ,out=notb);
Or(a=nota,b=notb,out=aorb);
Not(a=aorb,out=nota);
}

please give me some hints ,thanks 
Reply | Threaded
Open this post in threaded view
|

Re: And gate implement

cadet1620
Administrator
Ben wrote
I think Nand gate compose Or gate & Not Gate
Nand(a,b)=~a + ~b ,therefore  And=Not(Nand(a,b))=~(~a + ~b)
but I implement using the thinking ,but I always get message from HW
simulator a is not pin in Not
This is correct algebra, and this particular relationship is one of De Morgan's Laws.

Read the Hardware Construction Survival Kit if you have not done so yet.

When you start out the course, the only Chip that is available to use is Nand. There are no other chips available until you make and test them.

The first chip you need to make and test is the Not chip. You can only use Nand chips in your Not.hdl.
Next make and test your And chip. You can use Nand and Not parts in your And.
Next make and test your Or chip. You can use Nand, Not and And parts in your Or. (Hint: There is a version of De Morgan's law for Nor(a,b) that will help you make And.)

Continue making your chips in the order they are described in the book: Not, And, Or, Xor, Mux, DMux, etc.

As you will see when you make your Not.hdl, the IN and OUT pins for Not are 'in' and 'out'. That's why the simulator is complaining about
    Not(a=a, out=nota);
It would need to be
    Not(<b>in</b>=a, out=nota);

--Mark
Ben
Reply | Threaded
Open this post in threaded view
|

Re: And gate implement

Ben
This post was updated on .
In reply to this post by Ben
Hi TA :
I finished the And as below ,but I failed to load And.cmp to Hardware Simulator


 * And gate:
 * out = 1 if (a == 1 and b == 1)
 *       0 otherwise
 */

CHIP And {
    IN a, b;
    OUT out;

    PARTS:
[Edited to remove working source code. --Admin]
}

Error message is as below
A command can not  begin with '|'

May my "And"  effect by the error message? I had verified manually,the out is correct!
So,Can  I still submit the And.hdl to web?

thanks
                                                                                                            Ben
Reply | Threaded
Open this post in threaded view
|

Re: And gate implement

cadet1620
Administrator
You need to load And.tst into the Hardware Simulator.  Use the File>Load Script command or the  button. Then hit the run button to run the test.

--Mark
Ben
Reply | Threaded
Open this post in threaded view
|

Re: And gate implement

Ben
Thanks Mark,Sorry I asked a stupid question :(