题解 | #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 [4:0] g_and0;
	wire [4:0] p_xor0;
	wire [4:0] c_buf;
	wire [15:0] buff;
	wire [4:0] s_xor1;
    genvar i;
	generate 
		for(i=0; i<4; i = i+1) begin
			and and0(g_and0[i], A_in[i], B_in[i]);
			xor xor0(p_xor0[i], A_in[i], B_in[i]);
		end
	endgenerate

	assign c_buf[0] = C_1;
	generate
		for(i=1; i<5; i=i+1) begin
			and and1(buff[i], p_xor0[i-1], c_buf[i-1]);
			or or0(c_buf[i], g_and0[i-1], buff[i]);
			xor xor1(s_xor1[i-1], p_xor0[i-1], c_buf[i-1]);	
		end
	endgenerate

	assign CO = c_buf[4];
	assign S = s_xor1[3:0];
	

endmodule

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
ResourceUtilization:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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