4bit超前进位加法器的逻辑表达式如下:
中间变量
和:,进位:
请用Verilog语言采用门级描述方式,实现此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 , P , C , PC; and and0 (G[0],A_in[0],B_in[0]), and1 (G[1],A_in[1],B_in[1]), and2 (G[2],A_in[2],B_in[2]), and3 (G[3],A_in[3],B_in[3]); xor xor0 (P[0],A_in[0],B_in[0]), xor1 (P[1],A_in[1],B_in[1]), xor2 (P[2],A_in[2],B_in[2]), xor3 (P[3],A_in[3],B_in[3]); and and4 (PC[0],P[0],C_1), and5 (PC[1],P[1],C[0]), and6 (PC[2],P[2],C[1]), and7 (PC[3],P[3],C[2]); or or0 (C[0],G[0],PC[0]), or0 (C[1],G[1],PC[1]), or0 (C[2],G[2],PC[2]), or0 (CO,G[3],PC[3]); xor xor4 (S[0],P[0],C_1), xor5 (S[1],P[1],C[0]), xor6 (S[2],P[2],C[1]), xor7 (S[3],P[3],C[2]); endmodule题目要求用门级电路,起码给出了式子而且不太复杂,比上一题人性化多了
`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 P0,P1,P2,P3; wire G0,G1,G2,G3; wire C0,C1,C2,C3; wire P0C_1,P1G0,P1P0C_1,P2G1,P2P1G0,P2P1P0C_1,P3G2,P3P2G1,P3P2P1G0,P3P2P1P0C_1; xor xor0(P0,A_in[0],B_in[0]), xor1(P1,A_in[1],B_in[1]), xor2(P2,A_in[2],B_in[2]), xor3(P3,A_in[3],B_in[3]), xor4(S[0],P0,C_1), xor5(S[1],P1,C0), xor6(S[2],P2,C1), xor7(S[3],P3,C2); and and0(G0,A_in[0],B_in[0]), and1(G1,A_in[1],B_in[1]), and2(G2,A_in[2],B_in[2]), and3(G3,A_in[3],B_in[3]), and4(P0C_1,P0,C_1), and5(P1G0,P1,G0), and6(P1P0C_1,P1,P0,C_1), and7(P2G1,P2,G1), and8(P2P1G0,P2,P1,G0), and9(P2P1P0C_1,P2,P1,P0,C_1), and10(P3G2,P3,G2), and11(P3P2G1,P3,P2,G1), and12(P3P2P1G0,P3,P2,P1,G0), and13(P3P2P1P0C_1,P3,P2,P1,P0,C_1); or or0(C0,G0,P0C_1), or1(C1,G1,P1G0,P1P0C_1), or2(C2,G2,P2G1,P2P1G0,P2P1P0C_1), or3(C3,G3,P3G2,P3P2G1,P3P2P1G0,P3P2P1P0C_1); assign CO = C3; endmodule
`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; wire [2:0]C; assign G = A_in & B_in; assign P = A_in ^ B_in; assign S = P ^ {C,C_1}; assign {CO,C} = G | (P & {C,C_1}); endmodule
module lca_4( input wire [3:0] A_in, input wire [3:0] B_in, input wire C_1, output wire CO, output wire [3:0] S ); and ad0(G0, A_in[0], B_in[0]), ad1(G1, A_in[1], B_in[1]), ad2(G2, A_in[2], B_in[2]), ad3(G3, A_in[3], B_in[3]); xor xr0(P0, A_in[0], B_in[0]), xr1(P1, A_in[1], B_in[1]), xr2(P2, A_in[2], B_in[2]), xr3(P3, A_in[3], B_in[3]); and ad4(PC0, P0, C_1), ad5(PC1, P1, C0), ad6(PC2, P2, C1), ad7(PC3, P3, C2); or or0(C0, PC0, G0), or1(C1, PC1, G1), or2(C2, PC2, G2), or3(CO, PC3, G3); xor xr4(S[0], P0, C_1), xr5(S[1], P1, C0), xr6(S[2], P2, C1), xr7(S[3], P3, C2); endmodule
`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 ); // 法一:超前进位 // 第1级:异或门 wire q0,q1,q2,q3; xor my_xor0(q0,A_in[0],B_in[0]); xor my_xor1(q1,A_in[1],B_in[1]); xor my_xor2(q2,A_in[2],B_in[2]); xor my_xor3(q3,A_in[3],B_in[3]); // 第2级:与门 wire a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13; and my_and0(a0,A_in[0],B_in[0]); and my_and1(a1,C_1,q0); and my_and2(a2,A_in[1],B_in[1]); and my_and3(a3,A_in[0],B_in[0],q1); and my_and4(a4,C_1,q0,q1); and my_and5(a5,A_in[2],B_in[2]); and my_and6(a6,A_in[1],B_in[1],q2); and my_and7(a7,A_in[0],B_in[0],q1,q2); and my_and8(a8,C_1,q0,q1,q2); and my_and9 (a9, A_in[3],B_in[3]); and my_and10(a10,A_in[2],B_in[2],q3); and my_and11(a11,A_in[1],B_in[1],q2,q3); and my_and12(a12,A_in[0],B_in[0],q1,q2,q3); and my_and13(a13,C_1,q0,q1,q2,q3); // 第3级:或门 —— 得到Cout wire C0,C1,C2; or my_or0 (C0,a0,a1); or my_or1 (C1,a2,a3,a4); or my_or2 (C2,a5,a6,a7,a8); or my_or3 (CO,a9,a10,a11,a12,a13); // 第4级:异或门 —— 得到S[3:0] xor my_xor4(S[0],q0,C_1); xor my_xor5(S[1],q1,C0); xor my_xor6(S[2],q2,C1); xor my_xor7(S[3],q3,C2); // // 法二:行波进位 // wire C_2,C_3,C_4; // lca_1 my_lca1(A_in[0],B_in[0],C_1,C_2,S[0]); // lca_1 my_lca2(A_in[1],B_in[1],C_2,C_3,S[1]); // lca_1 my_lca3(A_in[2],B_in[2],C_3,C_4,S[2]); // lca_1 my_lca4(A_in[3],B_in[3],C_4,CO ,S[3]); // endmodule // module lca_1( // input A_in , // input B_in , // input C_1 , // output wire CO , // output wire S // ); // wire G,P,Q; // xor my_xor1(P,A_in,B_in); // xor my_xor2(S,P,C_1); // and my_and1(G,A_in,B_in); // and my_and2(Q,P,C_1); // or my_or1(CO,G,Q); endmodule
`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 [2:0]C; assign G = A_in & B_in; assign P = A_in ^ B_in; assign S = P ^ {C,C_1}; assign {CO,C} = G | (P&{C,C_1}); endmodule
直接把公式翻译就可以了
`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 [4-1: 0] g; wire [4-1: 0] p; wire [4-1:-1] c; wire [4-1: 0] s; assign g = A_in & B_in; assign p = A_in ^ B_in; assign c[-1] = C_1; assign c[3:0] = g | p & c[2:-1]; assign s = p ^ c[2:-1]; // Output Logic assign CO = c[3]; assign S = s; endmodule
`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 [4:0] G,P,C; genvar i; assign C[0]=C_1; assign CO=C[3]; for(i=0;i<4;i=i+1)begin:mk assign G[i]=A_in[i]&B_in[i]; assign P[i]=A_in[i]^B_in[i]; assign S[i]=P[i]^C[i]; assign C[i+1]=G[i]|P[i]&C[i]; end 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] tmpg; wire [3:0] tmpp; wire [3:0] tmpc; assign tmpg=A_in & B_in; assign tmpp=A_in ^ B_in; assign tmpc[3:0]=tmpg | ( tmpp & {tmpc[2:0],C_1}); assign S=(tmpp ^ {tmpc[2:0],C_1}); assign CO=tmpc[3]; endmodule
`timescale 1ns/1ns module lca_4( input [3:0] A_in , input [3:0] B_in , input C_0 , output wire CO , output wire [3:0] S ); wire [4:0] g,p,c; assign g=A_in&B_in; assign p=A_in|B_in; assign c[0]=C_0; assign c[1] = g[0]|(p[0]&c[0]); assign c[2] = g[1]|(p[1]&(g[0]|(p[0]&c[0]))); assign c[3] = g[2]|(p[2]&( g[1]|(p[1]&(g[0]|(p[0]&c[0]))))); assign c[4] = g[3]|(p[3]&(g[2]|(p[2]&( g[1]|(p[1]&(g[0]|(p[0]&c[0]))))))); assign C0 = c[4]; assign S = g^p^c[3:0]; endmodule