ALU using mux4way16

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

ALU using mux4way16

Nandieswar
I tried ALU using mux4way16


CHIP ALU {
    IN  
        x[16], y[16],  // 16-bit inputs        
        zx, // zero the x input?
        nx, // negate the x input?
        zy, // zero the y input?
        ny, // negate the y input?
        f,  // compute out = x + y (if 1) or x & y (if 0)
        no; // negate the out output?

    OUT
        out[16], // 16-bit output
        zr, // 1 if (out == 0), 0 otherwise
        ng; // 1 if (out < 0),  0 otherwise

    PARTS:
   // Put you code here:
Not16(in=x,out=notx);
Mux4Way16(a=x,b=false,c=notx,d=true,sel[0]=zx,sel[1]=nx,out=x1);
Not16(in=y,out=noty);
Mux4Way16(a=y,b=false,c=noty,d=true,sel[0]=zy,sel[1]=ny,out=y1);
Add16(a=x1,b=y1,out=temp1);
And16(a=x1,b=y1,out=temp2);
Mux16(a=temp1,b=temp2,sel=f,out=out1);
Not16(in=out1,out=notout1);
Mux16(a=out1,b=notout1,sel=no,out=out,out[15]=ng,out[0..7]=t1,out[8..15]=t2);
Or8Way(in=t1,out=k1);
Or8Way(in=t2,out=k2);
Or(a=k1,b=k2,out=k3);
Not(in=k3,out=zr);
}


when I am loading script and try to run it it throws me error as comparison failure at line 3
can i know my error
Reply | Threaded
Open this post in threaded view
|

Re: ALU using mux4way16

WBahn
Administrator
This post was updated on .
You already posted this in response to someone else's thread, but it's best to start your own. So I'm going to delete your post in the other thread. If I don't, you will get some responses in one and some in the other and chaos will ensue.

The point of the course is for YOU to learn by solving it -- struggling with figuring out why something isn't working is a big part of learning the concepts involved.

Look at what Line 3 is in the comparison file and in your output file.

Where are they different?

Then walk through the logic for the inputs associated with that line and see why your logic is producing the output that it is and figure out where it is going wrong.

Pay particular attention to whether the ALU control signals really are selecting the signals you want them to select -- that's probably the single biggest mistake people make. Most of them are pretty obvious because the name of the signal tells you what that signal means when it is HI. But there is one signal that is not nearly so obvious, so don't fall in the trap of thinking that you know what it means -- look at the specifications for each control signal to be sure.

Reply | Threaded
Open this post in threaded view
|

Re: ALU using mux4way16

Nandieswar
Ya tried my level best but I can't find any mistake in it
So I posted doubt

On Wed, 16 Dec 2020, 11:38 a.m. WBahn [via Nand2Tetris Questions and Answers Forum], <[hidden email]> wrote:
You already posted this in response to someone else's thread, but it's best to start your own. So I'm going to delete your post in the other thread. If I don't, you will get some responses in one and some in the other and chaos will ensue.

The point of the course is for YOU to learn by solving it -- struggling with figuring out why something isn't working is a big part of learning the concepts involved.

Look at what Line 3 is in the comparison file and in your output file.

Where are they different?

Then walk through the logic for the inputs associated with that line and see why your logic is producing the output that it is and figure out where it is going wrong.


If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/ALU-using-mux4way16-tp4035333p4035335.html
To unsubscribe from ALU using mux4way16, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: ALU using mux4way16

WBahn
Administrator
This post was updated on .
Nandieswar wrote
Ya tried my level best but I can't find any mistake in it
So I posted doubt
Knowing that you have a comparison mismatch on Line 3 doesn't do me a lot of good in trying to help you.

I can look at Line 3 in the comparison file, but the only conclusion that will lead to is, "Yep, it's correct."

The error is in YOUR output file for that line and I have no idea what that output is. I'm not a mind reader.

I also can't decode "tried my level best" into something of the form, "These are the steps I took...." so that I can even begin to tell you whether what you tried was reasonable, just missing a little something, or if it was totally off in left field.

So show what Line 3 in the compare file is and what it is in your output. Then show a walkthrough using your logic to see what your logic produces. You will either do that right, or you won't. But it will give us a common point of reference from which to either proceed or to step back and fix what is wrong up to that point.