Verilog数字系统设计——带进位的8位加法器

Verilog数字系统设计——带进位的8位加法器

题目

  1. 试分别使用门级原语和always 语句设计带进位的8位加法器,要求编制测试模块对实现的逻辑功能进行完整的测试;
  2. 使用门级原语设计时注意先在草稿上做出该加法器的门级设计;
  3. 如有余力可以进一步使用门级原语设计出带超前进位链的8位加法器(期末有加分);
  4. 实验提交Verilog设计文件(.v文件)和仿真波形截图,文件打包,压缩包以自己的学号+姓名命名。

代码

下面展示一些 内联代码片

module eight_add_2(sum,cout,cin,a,b);
	parameter size=7;
	input [size:0]a,b;
	output [size:0]sum;
	input cin;
	output cout;
	wire [0:6] Ctemp;
onebit_fulladd1
	add0(sum[0],Ctemp[0],a[0],b[0],cin),
	add1(sum[1],Ctemp[1],a[1],b[1],Ctemp[0]),
	add2(sum[2],Ctemp[2],a[2],b[2],Ctemp[1]),
	add3(sum[3],Ctemp[3],a[3],b[3],Ctemp[2]),
	add4(sum[4],Ctemp[4],a[4],b[4],Ctemp[3]),
	add5(sum[5],Ctemp[5],a[5],b[5],Ctemp[4]),
	add6(sum[6],Ctemp[6],a[6],b[6],Ctemp[5]),
	add7(sum[7],cout,a[7],b[7],Ctemp[6]);
endmodule



module onebit_fulladd1(Sum,Cout,A,B,CI);
	input A,B,CI;
	output Sum,Cout;
	wire Sum_temp,C_1,C_2,C_3;
	xor  XOR1(Sum_temp,A,B);
	xor  XOR2(Sum,Sum_temp,CI);
	and AND3(C_3,A,B);
	and AND2(C_2,B,CI);
	and AND1(C_1,A,CI);
	or OR1(Cout,C_1,C_2,C_3);
Endmodule

在这里插入图片描述
下面展示一些 内联代码片

Always:
module onebit_fulladd(sum,cout,a,b,cin);
        input  a,b;
	output reg sum;
	input cin;
	output reg cout;
	always @(a or b or cin)
	begin
		sum = a ^ b ^ cin;
         	cout = (a & b) | (b & cin) | (a & cin);
	end
endmodule
module eight_add_3(sum,cout,cin,a,b);
	parameter size=7;
	input [size:0]a,b;
	output [size:0]sum;
	input cin;
	output cout;
	wire [0:6] Ctemp;
onebit_fulladd
	add0(sum[0],Ctemp[0],a[0],b[0],cin),
	add1(sum[1],Ctemp[1],a[1],b[1],Ctemp[0]),
	add2(sum[2],Ctemp[2],a[2],b[2],Ctemp[1]),
	add3(sum[3],Ctemp[3],a[3],b[3],Ctemp[2]),
	add4(sum[4],Ctemp[4],a[4],b[4],Ctemp[3]),
	add5(sum[5],Ctemp[5],a[5],b[5],Ctemp[4]),
	add6(sum[6],Ctemp[6],a[6],b[6],Ctemp[5]),
	add7(sum[7],cout,a[7],b[7],Ctemp[6]);
Endmodule

在这里插入图片描述
下面展示一些 内联代码片

超前进位:
module eight_ahead_adder(sum,cout,cin,A,B);
	parameter size=7;
	input [size:0]A,B;
	input cin;
	output [size:0]sum;
	output cout;
	and and0(G0,A[0],B[0]);
	and and1(G1,A[1],B[1]);
	and and2(G2,A[2],B[2]);
	and and3(G3,A[3],B[3]);
	and and4(G4,A[4],B[4]);
	and and5(G5,A[5],B[5]);
	and and6(G6,A[6],B[6]);
	and and7(G7,A[7],B[7]);

 	xor xor0(P0,A[0],B[0]);
    xor xor1(P1,A[1],B[1]);
	xor xor2(P2,A[2],B[2]);
	xor xor3(P3,A[3],B[3]);
	xor xor4(P4,A[4],B[4]);
 	xor xor5(P5,A[5],B[5]);
	xor xor6(P6,A[6],B[6]);
 	xor xor7(P7,A[7],B[7]);

	and and_p0c0(p0c0,cin,P0);
	or or_0(c1,G0,p0c0);

	and and_p1c1(p1c1,c1,P1);
	or or_1(c2,G1,p1c1);

	and and_p2c2(p2c2,c2,P2);
	or or_2(c3,G2,p2c2);

	and and_p3c3(p3c3,c3,P3);
	or or_3(c4,G3,p3c3);

	and and_p4c4(p4c4,c4,P4);
	or or_4(c5,G4,p4c4);

	and and_p5c5(p5c5,c5,P5);
	or or_5(c6,G5,p5c5);

	and and_p6c6(p6c6,c6,P6);
	or or_6(c7,G6,p6c6);

        and and_p7c7(p7c7,c7,P7);
	or or_7(cout,G7,p7c7);
	
	xor xors0(sum[0],P0,cin);
	xor xors1(sum[1],P1,c1);
	xor xors2(sum[2],P2,c2);
	xor xors3(sum[3],P3,c3);
	xor xors4(sum[4],P4,c4);
	xor xors5(sum[5],P5,c5);
	xor xors6(sum[6],P6,c6);
	xor xors7(sum[7],P7,c7); 
endmodule

在这里插入图片描述
下面展示一些 内联代码片

测试文件:
module eight_add_test;
  reg  [7:0] a_t;
  reg  [7:0] b_t;
  reg  ci_t;
  wire [7:0] co_t;
  wire [7:0] sum_t;
  eight_add_2 		eight_add_2(.sum(sum_t1),.cout(co_t1),.cin(ci_t),.a(a_t),.b(b_t));
  eight_add_3		eight_add_3(.sum(sum_t2),.cout(co_t2),.cin(ci_t),.a(a_t),.b(b_t));
  eight_ahead_adder     eight_ahead_adder(.sum(sum_t3),.cout(co_t3),.cin(ci_t),.A(a_t),.B(b_t));

  initial 
    begin
 
         a_t=8'b00000000;
         b_t=8'b00000000;
         ci_t=1'b0;         
    
         #20 
         a_t=8'b00001001;
         b_t=8'b00000001;
         ci_t=1'b0;

         #20 
         a_t=8'b11000000;
         b_t=8'b00001111;
         ci_t=1'b0;

         #20
         a_t=8'b11000111;
         b_t=8'b00101111;
         ci_t=1'b0;
      
    end  
endmodule

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值