top of page

3-bit Multiplier Verilog Code -

module multiplier_3bit_structural ( input [2:0] a, input [2:0] b, output [5:0] product ); wire [2:0] pp0, pp1, pp2; // partial products wire c1, c2, c3, c4, c5, c6; wire s1, s2, s3, s4;

initial begin $monitor("a=%d (%b) b=%d (%b) product=%d (%b)", a, a, b, b, product, product); for (int i = 0; i < 8; i++) begin for (int j = 0; j < 8; j++) begin a = i; b = j; #10; end end $finish; end endmodule a=0 (000) b=0 (000) product=0 (000000) a=1 (001) b=2 (010) product=2 (000010) a=3 (011) b=3 (011) product=9 (001001) a=5 (101) b=6 (110) product=30 (011110) a=7 (111) b=7 (111) product=49 (110001) Key Points | Feature | Behavioral | Structural | |---------|-----------|-------------| | Code size | Small | Large | | Readability | High | Low | | Synthesis | Good (modern tools) | Explicit control | | Area/speed | Tool-optimized | Manual tuning |

// Half adder for LSB assign product[0] = pp0[0]; 3-bit multiplier verilog code

module multiplier_3bit_behavioral ( input [2:0] a, // 3-bit multiplicand input [2:0] b, // 3-bit multiplier output [5:0] product // 6-bit product ); assign product = a * b; endmodule 2. Structural Style (using full adders and half adders) This implements the array multiplier architecture.

module full_adder ( input a, b, cin, output sum, cout ); assign sum = a ^ b ^ cin; assign cout = (a & b) | (b & cin) | (a & cin); endmodule `timescale 1ns/1ps module tb_multiplier_3bit; reg [2:0] a, b; wire [5:0] product; // Generate partial products (AND gates) assign pp0

// Helper modules module half_adder ( input a, b, output sum, carry ); assign sum = a ^ b; assign carry = a & b; endmodule

// Final stage assign product[5] = c5 | c6; // final carry out assign product[4] = (c5 ^ c6); // optional, adjust based on actual addition endmodule a[1] & b[0]

for most FPGA/ASIC designs unless you need explicit gate-level control for teaching or low-level optimization.

// Generate partial products (AND gates) assign pp0 = a[2] & b[0], a[1] & b[0], a[0] & b[0]; assign pp1 = a[2] & b[1], a[1] & b[1], a[0] & b[1]; assign pp2 = a[2] & b[2], a[1] & b[2], a[0] & b[2];

half_adder ha2 ( .a(pp2[0]), .b(1'b0), .sum(s2), .carry(c3) );

bottom of page