题解 | #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 ); reg [3:0] G, P, C; reg [3:0] Si; integer i; always @(*) begin // 初始化 G = 4'b0; P = 4'b0; Si = 4'b0; C = 4'b0; // 计算第一个位 G[0] = A_in[0] & B_in[0]; P[0] = A_in[0] ^ B_in[0]; Si[0] = P[0] ^ C_1; C[0] = G[0] | (P[0] & C_1); // 计算其他位 for (i = 1; i < 4; i = i + 1) begin G[i] = A_in[i] & B_in[i]; P[i] = A_in[i] ^ B_in[i]; Si[i] = P[i] ^ C[i-1]; C[i] = G[i] | (P[i] & C[i-1]); end end assign S = Si; assign CO = C[3]; endmodule