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

超前进位加法器

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

`timescale 1ns/1ns

module huawei8//四位超前进位加法器
(
	input wire [3:0]A,
	input wire [3:0]B,
	output wire [4:0]OUT
);

//*************code***********//
wire [3:0] P;
wire [3:0] G;
wire [3:0] F;
wire [4:1] C;
CLA_4 cla(.P(P),.G(G),.C_in(0),.Ci(C),.Gm(),.Pm());
Add1 a0(.a(A[0]),.b(B[0]),.C_in(0),.f(F[0]),.g(G[0]),.p(P[0]));
Add1 a1(.a(A[1]),.b(B[1]),.C_in(C[1]),.f(F[1]),.g(G[1]),.p(P[1]));
Add1 a2(.a(A[2]),.b(B[2]),.C_in(C[2]),.f(F[2]),.g(G[2]),.p(P[2]));
Add1 a3(.a(A[3]),.b(B[3]),.C_in(C[3]),.f(F[3]),.g(G[3]),.p(P[3]));

assign OUT={C[4],F};


//*************code***********//
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]=P[0]|G[0]&C_in;
	assign Ci[2]=P[1]|G[1]&Ci[1];
	assign Ci[3]=P[2]|G[2]&Ci[2];
	assign Ci[4]=P[3]|G[3]&Ci[3];
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务