assign product = a * b; endmodule
Best for low-area designs where speed is not critical. The multiplication takes 8 clock cycles.
Extremely low area (one adder plus registers). Cons: Requires 8 clock cycles to produce a result.
Booth's algorithm reduces the number of partial products (ideal for signed multiplication), while a Wallace Tree reduces the partial products in a tree structure using carry-save adders. Pros: Extremely fast; logarithmic ( ) delay instead of linear (
initial begin // Initialize Inputs A = 0; B = 0;
// Outputs wire [15:0] Product;
https://github.com/theashix/8-bit_multiplier
// Module: multiplier_8bit_array.v // Description: Structural 8-bit unsigned array multiplier. module multiplier_8bit_array ( input wire [7:0] a, input wire [7:0] b, output wire [15:0] product ); wire [7:0] p_prod [7:0]; // Array for partial products // Generate partial products using bitwise AND genvar i; generate for (i = 0; i < 8; i = i + 1) begin: gen_partial_products assign p_prod[i] = a & 8b[i]; end endgenerate // Accumulation logic vectors wire [7:0] sum0, sum1, sum2, sum3, sum4, sum5; wire [7:0] carry0, carry1, carry2, carry3, carry4, carry5; // Manual ripple-carry or structural addition layers // Stage 1 assign product[0] = p_prod[0][0]; assign carry0[0], sum0[0] = p_prod[0][1] + p_prod[1][0]; assign carry0[1], sum0[1] = p_prod[0][2] + p_prod[1][1]; assign carry0[2], sum0[2] = p_prod[0][3] + p_prod[1][2]; assign carry0[3], sum0[3] = p_prod[0][4] + p_prod[1][3]; assign carry0[4], sum0[4] = p_prod[0][5] + p_prod[1][4]; assign carry0[5], sum0[5] = p_prod[0][6] + p_prod[1][5]; assign carry0[6], sum0[6] = p_prod[0][7] + p_prod[1][6]; assign carry0[7], sum0[7] = 1'b0 + p_prod[1][7]; // Subsequent stages follow a cascading addition pattern... // Note: For a production GitHub repository, it is best practice to instantiate // full adder primitives inside a generate loop to handle the 8x8 matrix cleanly. // Fallback simple behavioral representation of the array logic for brevity: assign product = p_prod[0] + (p_prod[1] << 1) + (p_prod[2] << 2) + (p_prod[3] << 3) + (p_prod[4] << 4) + (p_prod[5] << 5) + (p_prod[6] << 6) + (p_prod[7] << 7); endmodule Use code with caution. 3. Testbench and Verification
module tb_multiplier(); reg [7:0] a, b; wire [15:0] product; integer errors, i, j; mult_8bit_comb uut (a, b, product);
// Wait 100 ns for global reset to finish #100;
initial begin errors = 0; for (i = 0; i < 256; i = i + 1) begin for (j = 0; j < 256; j = j + 1) begin a = i; b = j; #10; if (product !== i*j) begin $display("Error: %d * %d = %d, but got %d", i, j, i*j, product); errors = errors + 1; end end end $display("Simulation done. Errors: %d", errors); $finish; end
Comprehensive Guide to 8-Bit Multipliers in Verilog: Architecture, Code, and GitHub Best Practices
Booth's algorithm reduces the number of partial products by encoding signed multipliers. radix-4 Booth multipliers cut the number of partial products in half (from 8 to 4 for an 8-bit multiplier), significantly speeding up addition stages at the cost of more complex control logic. Wallace Tree Multiplier
├── .github/ │ └── workflows/ # Optional: Continuous Integration (e.g., Icarus Verilog linting) ├── rtl/ # Register Transfer Level (Source Code) │ ├── multiplier_8bit_behavioral.v │ └── multiplier_8bit_array.v ├── sim/ # Simulation and Verification files │ └── tb_multiplier_8bit.v ├── docs/ # Waveform screenshots and architecture block diagrams ├── LICENSE # MIT or Apache 2.0 open-source license ├── README.md # The homepage of your project └── run_sim.sh # Automation script for ModelSim/Icarus Verilog Use code with caution. Writing a Great README.md Your README.md should include:
To make your GitHub project professional and reliable, you must include a self-checking testbench. This testbench applies stimulus and automatically checks the output against an expected golden value. Use code with caution. 4. Structuring Your GitHub Repository