【【有符号数乘有符号数乘法器 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 
相关推荐
Aaron158817 小时前
无人机反制中AOA+TDOA联合定位技术与雷达探测定位技术的应用对比分析
arm开发·嵌入式硬件·fpga开发·硬件工程·无人机·信息与通信·信号处理
暴风雨中的白杨1 天前
fpga复位电平与资源消耗对比测试
fpga开发
ALINX技术博客1 天前
【黑金云课堂】FPGA技术教程Linux开发:NVMe/Qt/OpenCV人脸检测
linux·qt·fpga开发
第二层皮-合肥1 天前
【数据采集专栏】触发模式的设计
fpga开发
第二层皮-合肥1 天前
【数据采集专栏】通道触发设计要点
fpga开发
高速上的乌龟1 天前
Lattice LFCPNX-100 HSB+Fpga开发详解:2.4 Hololink I2C外设控制深度全解析
fpga开发
Kent Gu1 天前
MCU & FPGA调试
单片机·嵌入式硬件·fpga开发
浩子智控1 天前
EtherCAT技术概述
嵌入式硬件·fpga开发·硬件工程·信号处理
我爱C编程1 天前
【仿真测试】基于FPGA的8ASK扩频通信链路实现,包含帧同步,定时点,扩频伪码同步,信道,误码统计
fpga开发·帧同步·定时点·扩频通信·8ask·扩频伪码
德思特1 天前
软件定义GNSS模拟器技术原理与优势深度解析
fpga开发