Xor not working

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

Xor not working

Anirudh
Hi,

I am using Windows7.  I tried to test my Xor script(below)

// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/01/Xor.hdl

/**
 *  Exclusive-or gate.  out = a xor 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);
}

In the testing process, it runs fine for a=0 and b=0 with out=0. But when a=0 and b=1, the out=0 and it says 'Comparison Failure at line 3. The above code is exactly the same as given in the tutorial pdf. What am I doing wrong here?

Thanks
Anirudh


Reply | Threaded
Open this post in threaded view
|

Re: Xor not working

culchie

I think that what is happening is that the script is not loading the chip file with this code but probably a blank xor.hdl file.
To confirm this run your script. In  the bottom left corner of the hardware simulator is a frame captioned HDL.
Scroll down through this.
If it says '//implementation missing' it means that the xor.hdl file in the same folder as the xor.tst file that you are running in the hardware simulator is not the file that you put your hdl code in.
You need to put your hdl code in this file and then try again.
Reply | Threaded
Open this post in threaded view
|

Re: Xor not working - solved

Anirudh
Hi culchie,

Thanks for your suggestions. The reason why my script did not work was similar to what you suggested. I did modify the Xor.hdl file located in the same directory where Xor.tst and Xor.cmp are located(under the downloaded project01 folder). But, I forgot to modify the Or.hdl that was being used in my Xor.hdl file. That is, the Or.hdl file was incomplete. Once I completed the implementation of all the chips used in the Xor.hdl file, it ran without error. The key is to make sure that all the chips being called are working correctly.

Thanks again. It always helps even if some one suggests something related to the bug if not exactly a solution.

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

Re: Xor not working - solved

culchie
You're welcome
AFAIK another solution is to remove any chips' HDL files, that you haven't implemented, from the folder. If you do this then the simulator uses the inbuilt ones instead.