题解 | #4bit超前进位加法器电路#
4bit超前进位加法器电路
https://www.nowcoder.com/practice/4d5b6dc4bb2848039da2ee40f9738363
先看1bit,1bit搞定了,nbit就串行(省面积)或者并行(省性能)
sum:
若进位为0--> 若AB相同 sum为0;若AB相异,sum为1--> S = C'(A^B)
若进位为1--> 若AB相同 sum为1;若AB相异,sum为0--> S = C (A^B)'
==》 S = C'(A^B) + C (A^B)' = C^(A^B)
CO:
若进位为0--> A,B同时为1才进位 --> CO = C'AB
若进位为1--> A,B只要有1就进位 --> CO = C(A+B)
==》CO = C'AB + C(A+B) = C'AB+CA+CB = C'AB + CAB+CAB'+CAB+CA'B = AB+C(A^B) +CAB = AB + C(A^B)
以下写法为串行;若写作并行,则将C0,C1,C2的表达式直接带入到下一级的运算中。
`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; wire [3:0] p; wire C0,C1,C2; assign g = A_in & B_in; assign p = A_in ^ B_in; assign S[0] = C_1 ^ p[0]; //get s0 assign C0 = g[0] | (p[0] & C_1); //get C_1 for S1 assign S[1] = C0 ^ p[1]; //get s1 assign C1 = g[1] | (p[1] & C0); //get C1 for S2 assign S[2] = C1 ^ p[2]; //get s2 assign C2 = g[2] | (p[2] & C1); //get C2 for S3 assign S[3] = C2 ^ p[3]; //get s3 assign CO = g[3] | (p[3] & C2); //get CO endmodule