Hardware simulator comparison failure when everything is correct

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

Hardware simulator comparison failure when everything is correct

erlendkrool
Hello.

I wanted to test the Hardware Simulator when the video in Chapter 1 encouraged me to do it, so I wrote the HDL chip PART code for the Xor chip, I wrote it myself first (which was the exact same as the video shows), but I get error at line 3 and 4. Then I copied the example code from the tutorial PDF (the Xor chip), pasted it in the hdl text file, loaded it inside the hardware simulator again, but same issue. I get 0 on all evaluation tests, even if the chip loaded is the written code from the tutorial itself. Strange.

Here is the chip parts code I use in the Xor file:

// 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/Xor.hdl

/**
 * Exclusive-or gate:
 * out = not (a == b)
 */

CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    Not (in=a, out=nota);
    Not (in=b, out=notb);
    And (a=a, b=notb, out=x);     (this is line 3 comparison error)
    And (a=nota, b=b, out=y);     (this is line 4 comparison error)
    Or (a=x, b=y, out=out);
}


I have also tried this:

CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    Not (in=a, out=nota);
    Not (in=b, out=notb);
    And (a=a, b=notb, out=aAndnotb);
    And (a=nota, b=b, out=notaAndb);
    Or (a=aAndnotb, b=notaAndb, out=out);
}


Why don't I get output 1 on line 3 and 4? I get output 0 on all evaluations. Its like the simulator doesn't work on my Windows 10 machine. Thanks in advance for any answers :) Cheers from Norway.
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

WBahn
Administrator
This post was updated on .
What error do you get at line 3 and line 4?

What does the error statement actually say?

Have you implemented the Not, the And, and the Or chips already?

If you haven't implemented all three, then the simulator can't simulate them when trying to evaluate an Xor chip that uses them.
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

erlendkrool

This is the error I get. I am starting on project 01 soon now, have I missed something maybe? :)
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

WBahn
Administrator
Have you implemented the other three gates that you are using?
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

erlendkrool
EDIT; No I have not written the HDL PARTS code on the other gates I'm using, must I do this first maybe? I edited the Xor.hdl text file only, and then loaded it up in HS :)


I have not yet started on project 01, so I am starting with that soon and I am going to read more before writing all my HDL chip codes in the project 01 folder. I may miss something haha.

So I don't understand what you mean by implemented chips, you mean as writing the HDL code in the text file (the PARTS code) for the other gates, or do I need to implement the other gates another way (which I will learn soon maybe)? I just did the same thing as he did in the video, he has not showed me any other way to implement anything other than the HDL PARTS code itself in the Xor.hdl text file.
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

WBahn
Administrator
Imagine you are making a car (the Xor) by assembling an engine (the And), a transmission (the Or) and the differential (the Not). But, because you haven't built the engine, the transmission, or the differential yet what you are actually putting together is an engine block that doesn't have any crankshaft or pistons or anything else in it, a transmission that doesn't have any gears in it, and a differential that doesn't have any parts inside it. Do you expect this to then work? Of course not.

If you haven't built the Not gate, then how can any other part that uses a Not gate possibly work?

The Xor example is provided so that you can see what needs to go into an HDL file in order to build a new chip by connecting other chips. But it won't actually work until you've actually built the chips that it uses.

So start project 01 and build and test a Not gate. Then work your way up.
Reply | Threaded
Open this post in threaded view
|

Re: Hardware simulator comparison failure when everything is correct

erlendkrool
Thanks for the reply and information :) I will continue watching videos and reading the "must read" sections before starting on project 01.

Cheers