题解 | #串行进位加法器#
串行进位加法器
https://www.nowcoder.com/practice/83c5850805004b6d8c48742f582f304a
`timescale 1ns/1ns `timescale 1ns/1ns module add_half( input A , input B , output wire S , output wire C ); assign S = A ^ B; assign C = A & B; endmodule /***************************************************************/ module add_full( input A , input B , input Ci , output wire S , output wire Co ); wire S_tmp, C_tmp1,C_tmp2; add_half u_add_half1( .A(A) , .B(B) , .S(S_tmp) , .C(C_tmp1) ); add_half u_add_half2( .A(S_tmp) , .B(Ci) , .S(S) , .C(C_tmp2) ); assign Co = C_tmp1 | C_tmp2; endmodule module add_4( input [3:0] A , input [3:0] B , input Ci , output wire [3:0] S , output wire Co ); wire [4:0] C_tmp; assign C_tmp[0] = Ci; genvar i; generate for(i=0;i<=3;i=i+1) begin: add_serial add_full u_add_full(.A(A[i]), .B(B[i]), .Ci(C_tmp[i]), .S(S[i]), .Co(C_tmp[i+1])); end endgenerate assign Co = C_tmp[4]; endmodule