题解 | #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  [3:0] p;
wire  [3:0] g;
wire  [3:0] c;

genvar i;
generate 
	for (i=0;i<4;i=i+1) begin:pg_4
	pg_gen pg(
		.a(A_in[i]),
		.b(B_in[i]),
		.p(p[i]),
		.g(g[i])
	);
	end
endgenerate

assign c[0] = g[0] | p[0]&C_1;
assign c[1] = g[1] | p[1]&c[0];
assign c[2] = g[2] | p[2]&c[1];
assign c[3] = g[3] | p[3]&c[2];
assign S[0] = p[0]^C_1;
assign S[1] = p[1]^c[0];
assign S[2] = p[2]^c[1];
assign S[3] = p[3]^c[2];
assign CO = c[3];

endmodule

module pg_gen(
	input  a,
	input  b,
	output p,
	output g
);

assign  g =a&b;
assign  p =a^b;

endmodule

#verilog刷题记录#
全部评论

相关推荐

阿里巴巴各部门年终奖开奖了,有人拿到了220w
真烦好烦真烦:拿命换钱呢,公司给你220万,肯定是因为你对公司的贡献大于220万,想想要多厉害多累才能达到
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务