mathhdlalunand2tetris

Chapter 2 ALU.hdl not working on final line


When I run ALU-nostat.tst, the code executes perfectly. However, when I run ALU.tst, the code stops on line 1. If I then click the forward arrow again and allow it to test out the following test cases, it seems to work. I compared the output file generated with the compare file and I think that everything matches. The error seems to be before the cases are tested out because the output file is empty (only with the input and output column headers) before I click the forward arrow again.

set x %B0000000000000000,  // x = 0

^ is the line where the test script stops. It is strange because it does not stop here:

set x %B0000000000000000,

on the no-stat script.

In case it helps, the code is below.

` PARTS:

Mux16(a=x[0..15],b[0..15]=false,sel=zx,out=x1);
Not16(in=x1,out=maybex);
Mux16(a=x1,b=maybex,sel=nx,out=x2);

Mux16(a=y[0..15],b[0..15]=false,sel=zy,out=y1);
Not16(in=y1,out=maybey);
Mux16(a=y1,b=maybey,sel=ny,out=y2);

And16(a=x2,b=y2,out=output1);//I dont know what is wrong here
Add16(a=x2,b=y2,out=output2);
Mux16(a=output1,b=output2,sel=f,out=output3);

Not16(in=output3,out=almost);

Mux16(a=output3,b=almost,sel=no,out=out);

Mux16(a=output3,b=almost,sel=no,out[15]=pt2);
Mux16(a=output3,b=almost,sel=no,out=pt3);


And(a=pt2,b=true,out=ngtest);
Add16(a=pt3,b[0..15]=true,out[15]=pinname);
Mux(a=pinname,b=false,sel=ngtest,out=zr);
And(a=pt2,b=true,out=ng);`

Even after commenting out all of the new lines for the zr and ng output pins, it is still giving me a comparison failure on line 1.

It is not a problem with ALU.tst as I re-downloaded it and it still does not work. I do not understand what the error is.

Many thanks!!!!


Solution

  • This is just a wild guess, but I noticed that the set y line in alu.tst ends in a ; while the one in alu-nostat.tst ends in a ,

    Same goes for the other set y later in the file.

    I would change those ;'s to ,'s and see if it fixes the issue.

    If it doesn't, it may be that your ALU isn't generating the zr and ng values correctly so it's really failing on the first eval but for some reason you're getting a misleading error message pointing you to the wrong line. I would suggest you single-step through the tests and manually check to the ALU is responding correctly.

    Good luck!