## N位加法器设计 来自[[https://www.fpga4student.com/2017/07/n-bit-adder-design-in-verilog.html|来自FPGA4student]] The next Verilog/ VHDL project is a complete co-processor specially designed for cryptographic applications. The co-processor has standard instructions and dedicated function units specific for security. The co-processor is implemented mainly in VHDL, but the N-bit Adder is designed in Verilog. The Verilog code for the N-bit Adder will be instantiated later in a VHDL design. In next posts, implementations of major modules in the co-processor will be presented. The complete co-processor design and implementation will be presented after every part of the co-processor is posted. This post presents Verilog code for N-bit Adder designed for the co-processor. The Verilog code for N-bit Adder is done by using Structural Modeling. {{ :nbitadder1.png |}} As shown in the above picture, the N-bit Adder is simply implemented by connecting 1 Half Adder and N-1 Full Adder in series. The Verilog code for N-bit Adder is designed so that the N value can be initialized independently for each instantiation. To do it, the Verilog code for N-bit Adder uses Generate Statement in Verilog to create a chain of full adders for implementing the N-bit Adder. Verilog code for N-bit Adder using Structural Modeling: // fpga4student.com: FPGA projects, Verilog projects, VHDL projects // Verilog project: Verilog code for N-bit Adder // Top Level Verilog code for N-bit Adder using Structural Modeling module N_bit_adder(input1,input2,answer); parameter N=32; input [N-1:0] input1,input2; output [N-1:0] answer; wire carry_out; wire [N-1:0] carry; genvar i; generate for(i=0;i TestBench // fpga4student.com: FPGA projects, Verilog projects, VHDL projects // Verilog project: Verilog code for N-bit Adder // Testbench Verilog code for N-bit Adder module tb_N_bit_adder; // Inputs reg [31:0] input1; reg [31:0] input2; // Outputs wire [31:0] answer; // Instantiate the Unit Under Test (UUT) N_bit_adder uut ( .input1(input1), .input2(input2), .answer(answer) ); initial begin // Initialize Inputs input1 = 1209; input2 = 4565; #100; // Add stimulus here end endmodule