【【有符号数乘有符号数乘法器 verilog+ testbench 代码】】

有符号数乘有符号数乘法器 verilog+ testbench 代码

ssmultiplier.v

c 复制代码
module ssmultiplier #(
    parameter       NUMBER1      = 8                     ,
    parameter       NUMBER2      = 8 
  )(
    input  signed   [NUMBER1-1 : 0]         input1        ,
    input  signed   [NUMBER2-1 : 0]         input2        ,
    input                                   clk          ,
    input                                   rst_n        ,
    input                                   begin_en     ,
    output  reg                             finish_en    ,
    output  reg     [NUMBER1+NUMBER2-2 : 0]       out
  );


  //======================================================================================\
  //                define parameter  and  internal signal                                \
  //======================================================================================\
  reg [NUMBER1+NUMBER2-2 : 0]       out1    ;



  //==========================================================================================\
  //                     next   is  main  code                                                 \\
  //===========================================================================================\\


  always@(posedge clk or negedge rst_n)
  begin
    if(rst_n == 0)
    begin
      out <= 0 ;
    end

    else  if(begin_en && finish_en )
    begin

      out[NUMBER1+NUMBER2-3:0] <= input1[NUMBER1-2:0] * input2[NUMBER2-2 : 0] ;
      out[NUMBER1+NUMBER2-2] <= (~input2[NUMBER2-1]&&input1[NUMBER1-1]) || (input2[NUMBER2-1]&&~input1[NUMBER1-1]) ;

    end
    else
      out <= out ;
  end

  always@(posedge clk or negedge rst_n )
  begin
    if(rst_n == 0)
    begin
      out1 <= 0 ;
    end

    else
      out1 <= out ;
  end

  always@(posedge clk or negedge rst_n)
  begin
    if(rst_n == 0)
    begin
      finish_en <= 1'b1 ;
    end
    else if(out != out1)
    begin
      finish_en <= 1'b1 ;
    end
    else
      finish_en <= 1'b0 ;
  end

endmodule

ssmultiplier_tb.v

c 复制代码
module ssmultiplier_tb #(
    parameter       NUMBER1      =     4                  ,
    parameter       NUMBER2      =      4                  

);

reg  [NUMBER1-1 : 0]                  input1      ;
reg  [NUMBER2-1 : 0]                  input2      ;
reg                                   clk         ;
reg                                   rst_n       ;
reg                                   begin_en    ;
wire                             finish_en        ;
wire [(NUMBER1)+(NUMBER2)-2 : 0]       out              ;


ssmultiplier#(
    .NUMBER1    ( NUMBER1 ),
    .NUMBER2    ( NUMBER2 )
)u_ssmultiplier(
    .input1     ( input1     ),
    .input2     ( input2     ),
    .clk        ( clk        ),
    .rst_n      ( rst_n      ),
    .begin_en   ( begin_en   ),
    .finish_en  ( finish_en  ),
    .out        ( out        )
);




always    #5     clk = ~clk   ;

initial begin 
    clk =  0 ;
    rst_n = 0 ;
    input1 = 2'b00 ;
    input2 = 2'b00 ;
    begin_en = 1 ;

    #20
    rst_n = 1 ;


    input1 = 4'b0001  ; 
    input2 = 4'b1100  ;
   

    #20
    input1 = 4'b1010; 
    input2 = 4'b1111 ;
   



    #20 
    input1 = 4'b0011 ; 
    input2 = 4'b1100 ;
   



#20
    input1 = 4'b1100 ; 
    input2 = 4'b0100 ;
   


end
endmodule 
相关推荐
步达硬件16 小时前
【FPGA】DP、HDMI、USB4、GPMI、eDP、LVDS等音视频协议及性能对比
fpga开发
-木槿昔年-1 天前
【米尔-安路MYD-YM90X创意秀】飞龙派学习和PS串口实践
学习·fpga开发
Aaron15881 天前
基于RFSOC+VU13P+GPU架构在雷达电子战的技术
人工智能·算法·fpga开发·架构·硬件工程·信号处理·基带工程
jifengzhiling2 天前
伺服驱动器中DSP与FPGA高效协同架构解析
fpga开发·foc电机控制
太爱学习了2 天前
FPGA图像处理之:图像畸变矫正原理及matlab与fpga实现
图像处理·matlab·fpga开发
技术性摸鱼2 天前
FPGA选型参数
fpga开发
FPGA_小田老师3 天前
ibert 7 Series GT:IBERT远近端(内外)环回测试
fpga开发·ibert·gt测试·近端pcs环回·近端pma环回·远端pcs环回·远端pma环回
尤老师FPGA3 天前
【无标题】
fpga开发
175063319453 天前
VIVADO VLA VIO 硬件调试 降采样
fpga开发
FPGA小迷弟3 天前
基于FPGA开发高速ADC/DAC芯片笔记
图像处理·fpga开发·数据采集·fpga·adc