二進位制全加器設計 (verilog)
二進位制全加器設計
一位全加器使用乘積項之和的形式可以表示為:
sum=a·b·c_in+a’·b·c_in’+a’·b’·c_in+a·b’·c_in’
c_out=a·b+b·c_in+a·c_in
其中a,b和c_in為輸入,sum和c_out為輸出,只使用與門,或門,非門實現一個一位全加器,寫出Verilog描述,限制是每個門最多隻能有四個輸入端。編寫激勵模組對其功能進行檢查,並對全部的輸入組合輸入組合進行測試。
module fulladd(a,b,c_in,c_out,sum);
output sum,c_out;
input c_in,a,b;
wire t1,t2,t3;
wire s1,s2,s3,s4;
not (a1,a);
not (b1,b);
not (c_in1,c_in);
and (s1,a,b,c_in);
and (s2,a1,b,c_in);
and (s3,a,b1,c_in);
and (s4,a,b,c_in1);
and (t1,a,b);
and (t2,a,c_in);
and (t3,b,c_in);
or (sum,s1,s2,s3,s4);
or (c_out,t1,t2,t3);
endmodule
module stimulus;
regA,B;
regC_IN;
wireSUM;
wireC_OUT;
fulladd full(A,B,C_IN,C_OUT,SUM);
initial
begin
$monitor($time,"A=%b,B=%b,C_OUT=%b,SUM=%b\n",A,B,C_OUT,SUM);
end
initial
begin
C_IN=1;
#5A=1;B=0;
#5 A=0;B=1;
#5 A=1;B=1;
#5 A=0;B=0;
end
endmodule