Tuesday, March 13, 2012

An adder/ subtractor in hardware


Activity 19 E:
A subtractor. I found a schematic for a subtractor. I am attempting to implement it and then create a test script and compare file for the hardware simulator. Using a 16 bit adder and two other 16 bit logic gates I think I have a hardware subtractor. I have tried two approaches neither  one works. The issue was my full adder had to a few changes now it seems to work great. And since it’s not a project in the book I don’t see an issue of posting the code.

//Created By Jeremy King for the hack computer
//The method of creating it came from
//http://www.play-hookey.com/digital/binary_subtraction.html

/**
 * 16-bit adder/subtractor: a + b = out   if sub == 0
 *                          a - b = out   if sub == 1
 */

CHIP Subtract16 {
    IN a[16], b[16], sub;
    OUT out[16];

    PARTS:
       //does not work
       //Accordding to articals I read it should work
    /*Not16(in=b,out=NotB);
       Inc16(in=NotB,out=outA);
       Mux16(a=b,b=outA,sel=sub,out=outc);
    revAdd16(a=a,outc=outc,sub=sub,out=out); */
      
       //works great
       //This is what creats the subtraction
       XOr16(a=sub,b=b,out=bout);
       //This adder has a third single bit input to start the carry
    revAdd16(a=a,outc=bout,sub=sub,out=out);
}

No comments:

Post a Comment

Search Engine Submission - AddMe