Xor demo example doesn't work in simulator

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

Xor demo example doesn't work in simulator

joe_jordan
0) System
Windows 10
Java 8
Hardware Simulator 2.5

1) Open Hardware Simulator

(navigate to tools folder, double click the batch file)

2) hit Load Chip

select Xor file I typed in from the video using Notepad++, in projects/01. Saved as ANSI not UTF8 (although the two should be the same?)

(file loads correctly I think, I see the HDL and can click to show the Internal Parts etc.)

3) change Input Pins value

Eval button stays disabled
Output pins don't grey out to show they are out of date.

4) run test script for Xor

Fails because every output value of my chip is 0.

---

If I load the Xor in projects/demo, all is well and it works fine.

My HDL:

// 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=w1);
    And (a=nota, b=b, out=w2);
    Or (a=w1, b=w2, out=out);
}
Reply | Threaded
Open this post in threaded view
|

Re: Xor demo example doesn't work in simulator

cadet1620
Administrator
The problem is that all of the HDL files in projec/01 have no implementation so their outputs are stuck at 0. When you run your Xor in projects/01, all its sub-parts always output 0, so the Xor always outputs 0.

When you run your Xor in projects/demo, it is the only HDL file in that directory so the Simulator uses its built-in versions of the other parts and everything works as expected.

You need to build and test the parts in project/01 in the order listed in the video/book:
Not, And, Or, Xor, etc.

You can only use Nand to build Not. Then use Nand and Not to build And, Then use a combination of Nand, Not and And to make Or, etc.

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

Re: Xor demo example doesn't work in simulator

joe_jordan
...Thank you.

It would help if I actually watched the intro to project 01, rather than jumping in and trying to play along with the hardware sim video in the wrong folder!

I hadn't realised that the hardware simulator would work like Python (grabbing stuff if it's in the same dir in preference to the standard library). Shame the HDL doesn't use import to make it obvious when you're using another file.

I'll try not to jump ahead in future :)