【【有符号数乘有符号数乘法器 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 
相关推荐
坏孩子的诺亚方舟13 天前
FPGA系统架构设计实践15_高云Arora V系列时钟体系
fpga开发·系统架构
FPGA小徐13 天前
入门 CNN 结构全解析|从流程图理论到 FPGA Verilog 硬件实现(含习题带讲解)
fpga开发
FPGA小徐13 天前
FPGA 数字信号处理:并行 FIR 与串行滤波器设计原理、对比与完整 Verilog 实现
fpga开发
Saniffer_SH14 天前
【高清视频】Gen6 服务器还没到,Gen6 SSD 怎么测?Emily 现场演示三种测试环境
人工智能·驱动开发·测试工具·缓存·fpga开发·计算机外设·压力测试
zlinear数据采集卡14 天前
双核架构深度解析:ARM+FPGA如何让数据采集卡实现500Ksps高性能?
arm开发·fpga开发·架构
9527华安14 天前
FPGA实现GTH Transceivers Wizard传输2路视频,基于aurora 8b10b编解码架构,提供4套工程源码和技术支持
fpga开发·gth·aurora 8b10b·transceivers
FPGA小徐15 天前
FPGA 数字信号处理(二):并行 FIR 滤波器的 Verilog 全流程设计与实现
fpga开发
国科安芯15 天前
基于AS32S601ZIT2型抗辐照MCU的商业航天卫星姿态确定与控制系统研究
单片机·嵌入式硬件·安全·fpga开发·架构·risc-v
ALINX技术博客15 天前
【黑金云课堂】FPGA技术教程FPGA基础:I2C 总线通信技术
fpga开发·i2c
Hello-FPGA15 天前
Xilinx KU040 FPGA Camera Link 图像采集
c++·fpga开发