题解 | #4bit超前进位加法器电路#

4bit超前进位加法器电路

https://www.nowcoder.com/practice/4d5b6dc4bb2848039da2ee40f9738363

`timescale 1ns/1ns

module lca_4(
	input		[3:0]       A_in  ,
	input	    [3:0]		B_in  ,
    input                   C_1   ,
 
 	output	 wire			CO    ,
	output   wire [3:0]	    S
);
    wire c1,c2,c3;
	wire cout1, cout2, cout3;
	wire [3:0] g, p;
    
	// 算出 G 和 P
	and a1 (g[0], A_in[0], B_in[0]);
	xor x1 (p[0], A_in[0], B_in[0]);

	and a2 (g[1], A_in[1], B_in[1]);
	xor x2 (p[1], A_in[1], B_in[1]);
	
	and a3 (g[2], A_in[2], B_in[2]);
	xor x3 (p[2], A_in[2], B_in[2]);
	
	and a4 (g[3], A_in[3], B_in[3]);
	xor x4 (p[3], A_in[3], B_in[3]);
	
	// 算出Cout(本级) = G(本级) + P(本级) * Cout(上一级) 
	and a5 (c1, p[0], C_1);
    or  o1 (cout1, g[0], c1);

	and a6 (c2, p[1], cout1);
    or  o2 (cout2, g[1], c2);

	and a7 (c3, p[2], cout2);
    or  o3 (cout3, g[2], c3);

	and a8 (c4, p[3], cout3);
    or  o4 (CO, g[3], c4);

	// 算出S
	xor x5 (S[0], p[0], C_1);
	xor x6 (S[1], p[1], cout1);
	xor x7 (S[2], p[2], cout2);
	xor x8 (S[3], p[3], cout3);

endmodule

全部评论

相关推荐

03-09 20:21
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务