安德鲁

[笔记].算法 - 乘法器.[Verilog]

0
阅读(5339)

出自Quartus II自带模板。

1. 无符号数乘法器


01 moduleunsigned_multiply
02 #(parameterWIDTH=8)
03 (
04 input[WIDTH-1:0] dataa,
05 input[WIDTH-1:0] datab,
06 output[2*WIDTH-1:0] dataout
07 );
08
09 assigndataout = dataa * datab;
10
11 endmodule

2. 有符号数乘法器


01 modulesigned_multiply
02 #(parameterWIDTH=8)
03 (
04 inputsigned [WIDTH-1:0] dataa,
05 inputsigned [WIDTH-1:0] datab,
06 output[2*WIDTH-1:0] dataout
07 );
08
09 assigndataout = dataa * datab;
10
11 endmodule

3. 带输入输出寄存器的无符号数乘法器


01 moduleunsigned_multiply_with_input_and_output_registers
02 #(parameterWIDTH=8)
03 (
04 inputclk,
05 input[WIDTH-1:0] dataa,
06 input[WIDTH-1:0] datab,
07 outputreg[2*WIDTH-1:0] dataout
08 );
09
10 // Declare input and output registers
11 reg[WIDTH-1:0] dataa_reg;
12 reg[WIDTH-1:0] datab_reg;
13 wire[2*WIDTH-1:0] mult_out;
14
15 // Store the result of the multiply
16 assignmult_out = dataa_reg * datab_reg;
17
18 // Update data
19 always@ (posedgeclk)
20 begin
21 dataa_reg <= dataa;
22 datab_reg <= datab;
23 dataout <= mult_out;
24 end
25
26 endmodule

4. 带输入输出寄存器的有符号数乘法器


01 modulesigned_multiply_with_input_and_output_registers
02 #(parameterWIDTH=8)
03 (
04 inputclk,
05 inputsigned [WIDTH-1:0] dataa,
06 inputsigned [WIDTH-1:0] datab,
07 outputregsigned [2*WIDTH-1:0] dataout
08 );
09
10 // Declare input and output registers
11 regsigned [WIDTH-1:0] dataa_reg;
12 regsigned [WIDTH-1:0] datab_reg;
13 wiresigned [2*WIDTH-1:0] mult_out;
14
15 // Store the result of the multiply
16 assignmult_out = dataa_reg * datab_reg;
17
18 // Update data
19 always@ (posedgeclk)
20 begin
21 dataa_reg <= dataa;
22 datab_reg <= datab;
23 dataout <= mult_out;
24 end
25
26 endmodule

5. 复数乘法器


01 modulemultiplier_for_complex_numbers
02 #(parameterWIDTH=18)
03 (
04 inputclk, ena,
05 inputsigned [WIDTH-1:0] dataa_real, dataa_img,
06 inputsigned [WIDTH-1:0] datab_real, datab_img,
07 outputregsigned [2*WIDTH-1:0] dataout_real, dataout_img
08 );
09
10 always@ (posedgeclk)
11 begin
12 if(ena == 1)
13 begin
14 dataout_real = dataa_real * datab_real - dataa_img * datab_img;
15 dataout_img = dataa_real * datab_img + datab_real * dataa_img;
16 end
17 end
18
19 endmodule
Baidu
map