VL66. 超前进位加法器
描述
题目描述:
求两个四位的数据编写一个四位的超前进位加法器,建议使用子模块
波形示意图:
输入描述
A B 输入值输出描述
OUT 加法结果Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06
`timescale 1ns/1ns module huawei8//四位超前进位加法器 ( input wire [3:0]A, input wire [3:0]B, output wire [4:0]OUT ); //*************code***********// wire [3:0]F,G,P; wire [4:1]C; Add1 Add1_u0 ( .a(A[0]), .b(B[0]), .C_in(1'b0), .f(F[0]), .g(G[0]), .p(P[0]) ); Add1 Add1_u1 ( .a(A[1]), .b(B[1]), .C_in(C[1]), .f(F[1]), .g(G[1]), .p(P[1]) ); Add1 Add1_u2 ( .a(A[2]), .b(B[2]), .C_in(C[2]), .f(F[2]), .g(G[2]), .p(P[2]) ); Add1 Add1_u3 ( .a(A[3]), .b(B[3]), .C_in(C[3]), .f(F[3]), .g(G[3]), .p(P[3]) ); CLA_4 CLA_4_u0( .P(P), .G(G), .C_in(1'b0), //第一级没有进位信号 .Ci(C), .Gm(), .Pm() ); assign OUT = {C[4],F}; //*************code***********// endmodule //////////////下面是两个子模块//////// module Add1 ( input a, input b, input C_in, output f, output g, output p ); assign f=a^b^C_in; //S assign g=a&b; //生成信号 assign p=a|b; //传播信号 endmodule module CLA_4( input [3:0]P, input [3:0]G, input C_in, output [4:1]Ci, output Gm, output Pm ); assign Ci[1] = G[0] | (P[0]&C_in); assign Ci[2] = G[1] | (P[1]&Ci[1]); assign Ci[3] = G[2] | (P[2]&Ci[2]); assign Ci[4] = G[3] | (P[3]&Ci[3]); assign Gm=G[3]|P[3] & G[2]|P[3] & P[2] & G[1]|P[3] & P[2] & P[1] & G[0]; assign Pm=P[3]&P[2]&P[1]&P[0]; endmodule
Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06
`timescale 1ns/1ns module huawei8//四位超前进位加法器 ( input wire [3:0]A, input wire [3:0]B, output wire [4:0]OUT ); //*************code***********// wire [4:0] C; wire [3:0] Ci; assign C = {Ci,1'b0}; wire [3:0] S,G,P; genvar i; generate for(i=0;i<=3;i=i+1) begin: carry Add1 u_Add1(.a(A[i]),.b(B[i]),.C_in(C[i]),.f(S[i]),.g(G[i]),.p(P[i])); end endgenerate CLA_4 u_CLA_4( .P(P), .G(G), .C_in(1'b0), .Ci(Ci), .Gm(), .Pm() ); assign OUT = {Ci[3],S}; //*************code***********// endmodule //////////////下面是两个子模块//////// module Add1 ( input a, input b, input C_in, output f, output g, output p ); assign p = a | b; assign g = a & b; assign f = a ^ b ^ C_in; endmodule module CLA_4( input [3:0]P, input [3:0]G, input C_in, output [4:1]Ci, output Gm, output Pm ); wire [4:0] C; assign C = {Ci,C_in}; genvar i; generate for(i=0;i<=3;i=i+1) begin: CLA assign Ci[i+1] = G[i] | (P[i] & C[i]); end endgenerate assign Gm = 1'b0; assign Pm = 1'b0; endmodule
Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-05
`timescale 1ns/1ns module huawei8//四位超前进位加法器 ( input wire [3:0]A, input wire [3:0]B, output wire [4:0]OUT ); wire [3:0]P1; wire [3:0]G1; wire [4:1]C; wire [3:0]F; Add1 s0 ( .a(A[0]), .b(B[0]), .C_in(1'b0), . f(F[0]), . g(G1[0]), . p(P1[0]) ); Add1 s1 ( .a(A[1]), .b(B[1]), .C_in(C[1]), . f(F[1]), . g(G1[1]), . p(P1[1]) ); Add1 s2 ( .a(A[2]), .b(B[2]), .C_in(C[2]), . f(F[2]), . g(G1[2]), . p(P1[2]) ); Add1 s3 ( .a(A[3]), .b(B[3]), .C_in(C[3]), . f(F[3]), . g(G1[3]), . p(P1[3]) ); CLA_4 S4( .P(P1), .G(G1), .C_in(1'b0), . Ci(C), . Gm(), . Pm() ); assign OUT={C[4],F}; endmodule //一位加法器 module Add1 ( input a, input b, input C_in, output f, output g, output p ); assign g=a&b; assign p=a|b; assign f=a^b^C_in; endmodule //4位CLA部件 module CLA_4( input [3:0]P, input [3:0]G, input C_in, output [4:1]Ci, output Gm, output Pm ); assign Ci[1]=G[0]|P[0]&C_in; assign Ci[2]=G[1]|P[1]&G[0]|P[1]&P[0]&C_in; assign Ci[3]=G[2]|P[2]&G[1]|P[2]&P[1]&G[0]|P[2]&P[1]&P[0]&C_in; assign Ci[4]=G[3]|P[3]&G[2]|P[3]&P[2]&G[1]|P[3]&P[1]&P[2]&G[0]|P[3]&P[2]&P[1]&P[0]&C_in; endmodule
Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-05
`timescale 1ns/1ns module huawei8//四位超前进位加法器 ( input wire [3:0]A, input wire [3:0]B, output wire [4:0]OUT ); //*************code***********// wire [3:0] jw; assign OUT[0] = A[0] ^ B[0] ; assign jw[0] = A[0] & B[0] ; assign OUT[1] = A[1] ^ B[1] ^ jw[0]; assign jw[1] = (A[1] & B[1]) | (A[1] & jw[0]) | (B[1] & jw[0]); assign OUT[2] = A[2] ^ B[2] ^ jw[1]; assign jw[2] = (A[2] & B[2]) | (A[2] & jw[1]) | (B[2] & jw[1]); assign OUT[3] = A[3] ^ B[3] ^ jw[2]; assign jw[3] = (A[3] & B[3]) | (A[3] & jw[2]) | (B[3] & jw[2]); assign OUT[4] = jw[3]; //assign CO = jw[3]; //*************code***********// endmodule /* //////////////下面是两个子模块//////// module Add1 ( input a, input b, input C_in, output f, output g, output p ); endmodule module CLA_4( input [3:0]P, input [3:0]G, input C_in, output [4:1]Ci, output Gm, output Pm ); endmodule*/
Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-05
`timescale 1ns/1ns module huawei8//四位超前进位加法器 ( input wire [3:0]A, input wire [3:0]B, output wire [4:0]OUT ); wire [3:0] p; wire [3:0] g; wire [4:1] ci; //*************code***********// assign OUT[4] = ci[4]; Add1 u1( .a(A[0]), .b(B[0]), .C_in(1'b0), .f(OUT[0]), .g(g[0]), .p(p[0]) ); Add1 u2( .a(A[1]), .b(B[1]), .C_in(ci[1]), .f(OUT[1]), .g(g[1]), .p(p[1]) ); Add1 u3( .a(A[2]), .b(B[2]), .C_in(ci[2]), .f(OUT[2]), .g(g[2]), .p(p[2]) ); Add1 u4( .a(A[3]), .b(B[3]), .C_in(ci[3]), .f(OUT[3]), .g(g[3]), .p(p[3]) ); CLA_4 u_CLA_4( .P(p), .G(g), .C_in(1'b0), .Ci(ci[4:1]), .Gm(), .Pm() ); //*************code***********// endmodule //////////////下面是两个子模块//////// module Add1 ( input a, input b, input C_in, output f, output g, output p ); assign p = a&b; assign g = a|b; assign f = a^b^C_in; endmodule module CLA_4( input [3:0]P, input [3:0]G, input C_in, output [4:1]Ci, output Gm, output Pm ); assign Ci[1] = P[0]|G[0]&C_in; assign Ci[2] = P[1]|G[1]&P[0]|G[1]&G[0]&C_in; assign Ci[3] = P[2]|G[2]&P[1]|G[2]&G[1]&P[0]|G[1]&G[1]&G[0]&C_in; assign Ci[4] = P[3]|G[3]&P[2]|G[3]&G[2]&P[1]|G[3]&G[2]&G[1]&P[0]|G[3]&G[2]&G[1]&G[0]&C_in; assign Gm = 0; assign Pm = 0; endmodule