This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > FPGA Technical Tutorials > Design Recipes for FPGAs Using Verilog and VHDL > Multiplication > Simple Multiplication using Verilog

TABLE OF CONTENTS

Xilinx FPGA FPGA Forum

Simple Multiplication using Verilog

FONT SIZE : AAA

We can use the same simple approach in Verilog as we have just seen in VHDL, where the use of the basic unsigned types and a multiplication can be defined in the code directly, and then the synthesis software will take care of the translation into a physical multiplier. 

In the multiplier model in Verilog, we can use a simple assignment as shown in the code snippet following, where the always statement is used to check for changes in a or b before assigning the output q to the product. This requires the definition of the output as a register (but we could also use the approach of defining the output as a wire and using the assign statement instead). 

1 always @ (a or b)

2 begin

3 q <= a ∗ b;

4 end

The complete multiplier model is given in the following listing:

1 module signmult (

2 q, / Multiplication Output

3 a, / Number a

4 b / Number b

5

6 );

7

8 input [3:0] a; / 4 bit input

9 input [3:0] b; / 4 bit input

10 output [7:0] q; / 8 bit output

11 reg [7:0] q;

12

13 always @ (a or b)

14 begin

15 q <= a ∗ b;

16 end

17

18 endmodule



Figure 26.2 Unsigned multiplication of Verilog.

In order to test the model we can create a very simple test bench that defines the two variables (a and b), and after initializing them to zero, sets them to 6 and 4, respectively. The resulting simulation results are shown in Figure 26.2, which shows the output start at 0 (0 × 0), remain at 0 (0 × 4) and then finally change to 24 (6 × 4). 

1 module signmult_tb();

2

3 reg [3:0] a,b;

4 wire [7:0] q;

5

6 signmult m1(q,a,b);

7

8 initial

9 begin

10

11 a = 4’b0000;

12 b = 4’b0000;

13 # 10 a = 4’b0110;

14 # 10 b = 4’b0100;

15

16 $display("a=%d b=%d q=%d\n", a, b, q);

17 end

18

19 endmodule

  • XCV300-5BG432I

    Manufacturer:Xilinx

  • FPGA Virtex Family 322.97K Gates 6912 Cells 294MHz 0.22um Technology 2.5V 432-Pin BGA
  • Product Categories: Semiconducteurs &amp; Actifs

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2V2000-6FGG676C

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 820MHz 0.15um Technology 1.5V 676-Pin FBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS:

  • XCS30XL-4TQ144Q

    Manufacturer:Xilinx

  • Xilinx TQFP144
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: -

  • XC3090A-6PC84C

    Manufacturer:Xilinx

  • FPGA XC3000 Family 6K Gates 320 Cells 135MHz 5V 84-Pin PLCC
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2V250-4CS144I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 250K Gates 3456 Cells 650MHz 0.15um Technology 1.5V 144-Pin CSBGA
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

Need Help?

Support

If you have any questions about the product and related issues, Please contact us.