逻辑电路简单,容易理解,缺点是位数较多时,计算较慢?所以如何提高计算速度?
练习:以牛客网VL12 4bit超前进位加法器电路为例
`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_i ; wire [ 3:0] P_i ; wire [ 3:0] C_i ; assign G_i = A_in & B_in; assign P_i = A_in ^ B_in; assign C_i[0] = G_i[0] | P_i[0]&C_1; assign C_i[1] = G_i[1] | P_i[1]&G_i[0] | P_i[1]&P_i[0]&C_1; assign C_i[2] = G_i[2] | P_i[2]&G_i[1] | P_i[2]&P_i[1]&G_i[0] | P_i[2]&P_i[1]&P_i[0]&C_1; assign C_i[3] = G_i[3] | P_i[3]&G_i[2] | P_i[3]&P_i[2]&G_i[1] | P_i[3]&P_i[2]&P_i[1]&(G_i[0] | P_i[0]&C_1); assign S[0] = P_i[0] ^ C_1; assign S[1] = P_i[1] ^ C_i[0]; assign S[2] = P_i[2] ^ C_i[1]; assign S[3] = P_i[3] ^ C_i[2]; assign CO = C_i[3]; endmodule