8bit Multiplier Verilog Code Github 95%
: High — this is the most common "learning multiplier" on repositories. Look for tags like sequential , FSM , shift-add . Verilog Implementation #4: Booth-Encoded Multiplier (Signed) Booth multiplication reduces the number of partial products by encoding overlapping groups of bits. For an 8-bit multiplier, radix-4 (modified Booth) reduces 8 partial products to 4 or 5.
: Many repositories include this as a trivial example, but serious learners avoid it because it hides the multiplication logic. Verilog Implementation #2: Gate-Level Array Multiplier This mimics the "shift-and-add" algorithm with explicit partial product generation. 8bit multiplier verilog code github
module tb_multiplier(); reg [7:0] a, b; wire [15:0] product; integer errors, i, j; mult_8bit_comb uut (a, b, product); : High — this is the most common
module array_multiplier_8bit ( input [7:0] A, B, output [15:0] P ); wire [7:0] pp0, pp1, pp2, pp3, pp4, pp5, pp6, pp7; wire [15:0] sum_stage0, sum_stage1, sum_stage2, sum_stage3; // Generate partial products (AND gates) assign pp0 = 8A[0] & B; assign pp1 = 8A[1] & B; assign pp2 = 8A[2] & B; assign pp3 = 8A[3] & B; assign pp4 = 8A[4] & B; assign pp5 = 8A[5] & B; assign pp6 = 8A[6] & B; assign pp7 = 8A[7] & B; For an 8-bit multiplier, radix-4 (modified Booth) reduces
module multiplier #(parameter WIDTH = 8) ( input [WIDTH-1:0] a, b, output [2*WIDTH-1:0] product ); assign product = a * b; endmodule For signed, use signed keyword:
A7 A6 A5 A4 A3 A2 A1 A0 (8 bits) × B7 B6 B5 B4 B3 B2 B1 B0 (8 bits) --------------------------- A×B0 (shifted 0) → 8 bits A×B1 (shifted 1) → 9 bits (with overflow) A×B2 (shifted 2) → 10 bits ... A×B7 (shifted 7) → 15 bits --------------------------- Sum of all → 16-bit product The challenge: summing all partial products efficiently. The simplest approach — rely on modern synthesis tools to infer a multiplier.
module sequential_multiplier_8bit ( input clk, rst, start, input [7:0] a, b, output reg [15:0] product, output reg done ); reg [2:0] count; reg [7:0] multiplicand, multiplier; reg [15:0] acc; always @(posedge clk or posedge rst) begin if (rst) begin count <= 0; done <= 0; product <= 0; acc <= 0; end else if (start) begin count <= 0; multiplicand <= a; multiplier <= b; acc <= 0; done <= 0; end else if (!done && count < 8) begin if (multiplier[0]) acc <= acc + 8'b0, multiplicand; multiplicand <= multiplicand << 1; multiplier <= multiplier >> 1; count <= count + 1; end else if (count == 8 && !done) begin product <= acc; done <= 1; end end endmodule