2021-08-11

八位加法器

verilog

module adder_1(

	input a,
	input b,
	input ci,
	output y,
	output co
	);
	 //--statements--//
	 
	 //--data fiow--//
	 //assign y = ((~a)&(~b)&ci) | ((~a)&b&(~ci)) | (a&(~b)&(~ci)) | (a&b&ci);
	 //assign co = ((~a)&b&ci) | (a&(~b)&ci) | (a&b&(~ci)) | (a&b&ci);  
	
	//wire s1,t1,t2,t3;
	
	//assign s1=a^b;
	//assign y=ci^s1;
	
	//assign t1=a&b;
	//assign t2=b&ci;
	//assign t3=a&ci;
	//assign co=t1|t2|t3;
	
	
	//--structrization--//
	//xor x1(s1,a,b);
	//xor x2(y,s1,ci);
	//and A1(t3,a,b);
	//and A2(t2,b,ci);
	//and A3(T1,A,CI);
	
	//or O1(co,ti,t2,t3);
	
	
	//--behavior--//
	reg y,co;
	reg t1,t2,t3;
	
	always @(a or b or ci)
	begin
		y =(a^b)^ci;
		
		t1=a&b;
		t2=a&ci;
		t3=b&ci;
		
		co=t1|(t2|t3);
	end
		
module adder_4(
    
	input [3:0] a,
	input [3:0] b,
	input ci,
	output [3:0]y,
	output co
	);
	
	wire c,d,e;
	
	adder_1 adder_1_inst_0(

	.a    (a[0]),
	.b    (b[0]),
	.ci   (ci)  ,
	.y    (y[0]),
	.co   (c)   
	);

	adder_1 adder_1_inst_2(

	.a    (a[1]),
	.b    (b[1]),
	.ci   (c),
	.y    (y[1]),
	.co   (d)
	);
	
	adder_1 adder_1_inst_3(

	.a    (a[2]),
	.b    (b[2]),
	.ci   (d),
	.y    (y[2]),
	.co   (e) 
	);
	
	adder_1 adder_1_inst_4(

	.a    (a[3]),
	.b    (b[3]),
	.ci   (e),
	.y    (y[3]),
	.co   (co)
	);
endmodule

module adder_8(

   
	input [7:0] a,
	input [7:0] b,
	input ci,
	output [7:0] y,
	output co
	);
	wire e;

	adder_4 adder_4_inst_low(
    
	.a     (a[3:0]) ,
	.b     (b[3:0]) ,
	.ci    (ci) ,
	.y     (y[3:0]) ,
	.co    (e)
	);
	
	adder_4 adder_4_inst_high(
    
	.a     (a[7:4])  ,
	.b     (b[7:4])   ,
	.ci    (e)       ,
	.y     (y[7:4])  ,
	.co    (co)
	);
endmodule
module adder_8_tb;

	// Inputs
	reg [7:0] a;
	reg [7:0] b;
	reg ci;

	// Outputs
	wire [7:0] y;
	wire co;

	// Instantiate the Unit Under Test (UUT)
	adder_8 adder_8_inst(
		.a(a), 
		.b(b), 
		.ci(ci), 
		.y(y), 
		.co(co)
	);

	initial begin
		// Initialize Inputs
		repeat(100) begin
		a = {$random}%256;
		b = {$random}%256;
		ci = 0;

		// Wait 100 ns for global reset to finish
		#100;
       end 
		// Add stimulus here
	end
	
      
endmodule

vhdl

not

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值