题解 | #超前进位加法器#

超前进位加法器

https://www.nowcoder.com/practice/c4c6afdab9ce45a3a2279a98391686ca

`timescale 1ns/1ns
//g = a&b,p = a^b,ci = gi-1 i ci-1 & pi-1
module huawei8//四位超前进位加法器
(
	input wire [3:0]A,
	input wire [3:0]B,
	output wire [4:0]OUT
);

//*************code***********//
wire [4:1] c_i;
wire[4:0] co;
wire [3:0] sum;
wire [3:0] g;
wire [3:0] p;
assign co = {c_i,1'b0};
genvar i;
generate
	for(i = 0;i<4;i=i+1)
	begin:add_multi
		Add1 add_inst(
			.a(A[i]),
			.b(B[i]),
			.C_in(co[i]),
			.f(sum[i]),
			. g(g[i]),
			. p(p[i])
		);
	end
endgenerate
CLA_4 CLA_4_INST(
		.P       (p),
		.G       (g),
		.C_in    (co[0]),
		.Ci      (c_i),
		. Gm     (),
		. Pm()
	);
//*************code***********//
assign OUT = {c_i[4],sum};
endmodule



//////////////下面是两个子模块////////

module Add1
(
		input a,
		input b,
		input C_in,
		output f,
		output g,
		output p
		);
assign f = a^b^C_in;
assign g = a & b;
assign p = a ^ b;

endmodule






module CLA_4(
		input [3:0]P,
		input [3:0]G,
		input C_in,
		output [4:1]Ci,
		output Gm,
		output Pm
	);
	assign Ci[1] = G[0]|P[0]&C_in;
	assign Ci[2] = G[1]|P[1]&(G[0]|P[0]&C_in);
	assign Ci[3] = G[2]|P[2]&(G[1]|P[1]&(G[0]|P[0]&C_in));
	assign Ci[4] = G[3]|P[3]&(G[2]|P[2]&(G[1]|P[1]&(G[0]|P[0]&C_in)));

endmodule

#超前进位加法器#
全部评论

相关推荐

Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务