题解 | #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] G,P,C,andPC;
genvar i;
generate
for(i=0;i<4;i=i+1) begin:initi_proc
and and1(G[i],A_in[i],B_in[i]);
xor xor1(P[i],A_in[i],B_in[i]);
xor xor2(S[i],P[i],(i==0)?C_1:C[i-1]);
and and2(andPC[i],P[i],(i==0)?C_1:C[i-1]);
or or1(C[i],G[i],andPC[i]);
end
endgenerate
assign CO = C[3];
endmodule
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] G,P,C,andPC;
genvar i;
generate
for(i=0;i<4;i=i+1) begin:initi_proc
and and1(G[i],A_in[i],B_in[i]);
xor xor1(P[i],A_in[i],B_in[i]);
xor xor2(S[i],P[i],(i==0)?C_1:C[i-1]);
and and2(andPC[i],P[i],(i==0)?C_1:C[i-1]);
or or1(C[i],G[i],andPC[i]);
end
endgenerate
assign CO = C[3];
endmodule