Inc16 (16 位元的遞增器) :

遞增器功能是+1,這裡可以把Half-Adder的b當成進位位元,

而第一個Half-Adder的輸入b要永遠為1,這樣才能使整個電路+1。

/**
 * 16-bit incrementer:
 * out = in + 1 (arithmetic addition)
 */

CHIP Inc16
 {
    IN in[16];
    OUT out[16];

    PARTS:
    HalfAdder(a=in[0],b=true,sum=out[0],carry=c1);
    HalfAdder(a=in[1],b=c1,sum=out[1],carry=c2);
    HalfAdder(a=in[2],b=c2,sum=out[2],carry=c3);
    HalfAdder(a=in[3],b=c3,sum=out[3],carry=c4);
    HalfAdder(a=in[4],b=c4,sum=out[4],carry=c5);
    HalfAdder(a=in[5],b=c5,sum=out[5],carry=c6);
    HalfAdder(a=in[6],b=c6,sum=out[6],carry=c7);
    HalfAdder(a=in[7],b=c7,sum=out[7],carry=c8);
    HalfAdder(a=in[8],b=c8,sum=out[8],carry=c9);
    HalfAdder(a=in[9],b=c9,sum=out[9],carry=c10);
    HalfAdder(a=in[10],b=c10,sum=out[10],carry=c11);
    HalfAdder(a=in[11],b=c11,sum=out[11],carry=c12);
    HalfAdder(a=in[12],b=c12,sum=out[12],carry=c13);
    HalfAdder(a=in[13],b=c13,sum=out[13],carry=c14);
    HalfAdder(a=in[14],b=c14,sum=out[14],carry=c15);
    HalfAdder(a=in[15],b=c15,sum=out[15]);
}
CHIP Inc16
{  
    IN in[16];  
    OUT out[16];  

    PARTS:  

    Add16(a=in, b[0]=true, b[1..15]=false, out=out);  
}

results matching ""

    No results matching ""