题解 | 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
);
//4bit超前进位加法器
wire G_0,G_1,G_2,G_3 ;  
wire P_0,P_1,P_2,P_3 ; 
wire CO_0,CO_1,CO_2,CO_3 ;
// S = A^B^Ci CO = AB + (A^B)Ci
// Gi = Ai&Bi  Pi = Ai^Bi
assign G_0 = A_in[0] & B_in[0];
assign G_1 = A_in[1] & B_in[1];
assign G_2 = A_in[2] & B_in[2];
assign G_3 = A_in[3] & B_in[3];

assign P_0 = A_in[0] ^ B_in[0];
assign P_1 = A_in[1] ^ B_in[1];
assign P_2 = A_in[2] ^ B_in[2];
assign P_3 = A_in[3] ^ B_in[3];

assign CO_0 = G_0 | (P_0 & C_1);
assign CO_1 = G_1 | (P_1 & (CO_0));
assign CO_2 = G_2 | (P_2 & (CO_1));
assign CO_3 = G_3 | (P_3 & (CO_2));

assign S[0] = P_0 ^ C_1;
assign S[1] = P_1 ^ CO_0;
assign S[2] = P_2 ^ CO_1;
assign S[3] = P_3 ^ CO_2;

assign CO = CO_3;
endmodule

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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