4bit full adder for DE2-70 pin assignments
module de2_4bitFA(SW, LEDR, LEDG);//MultiStages
//DE2-70 toggle sw , R-LED ,G-LED
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red LEDs
output [7:0] LEDG; // green LEDs
wire [3:0] a,b,sum;
wire carryout;
wire cin;
assign LEDR = SW; //set toggle SW turn on the Red LED
assign cin = SW[17];
assign a =SW[3:0];
assign b = SW[11:8];
fulladder_1bit s0( .a( a[0] ), .b( b[0]), .cin( cin ), .s( sum[0]), .cout( ripple0 ) );
fulladder_1bit s1( .a( a[1] ), .b( b[1]), .cin( ripple0 ), .s( sum[1]), .cout( ripple1 ) );
fulladder_1bit s2( .a( a[2] ), .b( b[2]), .cin( ripple1 ), .s( sum[2]), .cout( ripple2 ) );
fulladder_1bit s3( .a( a[3] ), .b( b[3]), .cin( ripple2 ), .s( sum[3]), .cout( carryout ) );
assign LEDG[3:0]=sum;
assign LEDG[4]=carryout;
endmodule
S=AB+BCi+CiA , Co=A⊕B⊕Ci
// fulladder_1bit.v
//
//Gate-Level Description of Full Adder
//////////////////////////////////////////////////////////////////////////////////
module fulladder_1bit (
input a,
input b,
input cin,
output s,
output cout );
// wires (from ands to or)
wire w1, w2, w3;
// carry-out circuitry
and( w1, a, b );
and( w2, a, cin );
and( w3, b, cin );
or( cout, w1, w2, w3 );
// sum
xor( s, a, b, cin );
endmodule
沒有留言:
張貼留言