Tuesday, March 13, 2012

Add/subtract UPDATE added over flow detection

Added an xor to my adder and then added code to the subtractor


//Created By Jeremy King for the hack computer
//The method of creating it cam 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], OvF;

    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
//This xor take a single bit input and a 16bit input
XOr16(a=sub,b=b,out=bout);
//This adder has a third single bit input to start the carry
//Also it now has over flow detection
    revAdd16(a=a,outc=bout,sub=sub,out=out,OvF=OvF);
}

No comments:

Post a Comment

Search Engine Submission - AddMe