logo资料库

四位超前进位加法器.doc

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
一、 实验课题: 四位超前进位加法器 二、Verilog 程序: 2.1 主程序 module add_4(a,b,c_in,c_out,sum); input [3:0] a,b; input c_in; output [3:0] sum; output c_out; wire [2:0] c; wire [3:0] p; wire [3:0] g; wire [9:0] k; xor(p[0],a[0],b[0]); xor(p[1],a[1],b[1]); xor(p[2],a[2],b[2]); xor(p[3],a[3],b[3]); and(g[0],a[0],b[0]); and(g[1],a[1],b[1]); and(g[2],a[2],b[2]); and(g[3],a[3],b[3]); - 1 -
and(k[0],p[0],c_in); or(c[0],k[0],g[0]); and(k[1],p[1],g[0]); and(k[2],k[1],c_in); or(c[1],g[1],k[1],k[2]); and(k[3],p[2],g[1]); and(k[4],k[3],g[0]); and(k[5],k[4],c_in); or(c[2],g[2],k[3],k[4],k[5]); and(k[6],p[3],g[2]); and(k[7],k[6],g[1]); and(k[8],k[7],g[0]); and(k[9],k[8],c_in); or(c_out,g[3],k[6],k[7],k[8],k[9]); xor(sum[0],p[0],c_in); xor(sum[1],p[1],c[0]); xor(sum[2],p[2],c[1]); xor(sum[3],p[3],c[2]); endmodule 2.2 激励 module adder_th; reg [3:0] a,b; reg c_in; wire [3:0] sum; - 2 -
wire c_out; add_4 f0(.a(a),.b(b),.c_in(c_in),.sum(sum),.c_out(c_out)); always #5 c_in=~c_in; integer i,j; initial begin a=4'b0; b=4'b0; c_in=1'b0; i=0; j=0; end initial begin for(i=0;i<16;i=i+1) for(j=0;j<16;j=j+1) begin end #5 a=i;b=j; end initial begin $monitor($time,"a=%d,b=%d,c_in=%b _ _ _ sum=%d,c_out=%b",a,b,c_in,sum,c_out); - 3 -
end endmodule 三、实验波形图截图: 四、波形分析及实验心得: 4.1 波形分析 当 a=0 时,对应的 b 从 0 到 15; 当 a=1 时,对应的 b 从 0 到 15; …… 当 a=15 时,对应的 b 从 0 到 15; 给进位端 c_in 接一时钟; 由波形可知,sum=a+b+c_in; 进位则 c_out=1; - 4 -
结果与已知关系式一样,说明波形正确。 4.2 实验心得 - 5 -
分享到:
收藏