Advertisement
Harmony5757

TB Shift-Add Multiplier

Jun 14th, 2025
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SystemVerilog 1.46 KB | Source Code | 0 0
  1. //====================================
  2. //Shift-Add Multiplier TestBench
  3. //====================================
  4.  
  5. `timescale 1ns / 1ps
  6.  
  7. module TB_Shift_Add_Mplier(
  8.  
  9.     );
  10.     logic clk, srst, Mul_Start, Done;
  11.     logic [1:0] Mplier, Mcand;
  12.     logic [3:0] Product;
  13.     ShiftAdd_Mplier dut(
  14.                                         .clk(clk),
  15.                                         .srst(srst),
  16.                                         .Mul_Start(Mul_Start),
  17.                                         .Done(Done),
  18.                                         .Mplier(Mplier),
  19.                                         .Mcand(Mcand),
  20.                                         .Product(Product)
  21.                                         );
  22.     initial begin
  23.         clk = 0;
  24.         forever #5 clk = !clk;
  25.     end
  26.    
  27.     initial begin
  28.         srst = 1;
  29.         repeat(2) @(posedge clk);
  30.         srst = 0;
  31.     end
  32.    
  33.     int expProduct = 0;
  34.     initial begin
  35.         repeat(2) @(posedge clk);
  36.         repeat(8) begin
  37.             Mplier = $urandom();
  38.             Mcand = $urandom();
  39.             expProduct = Mplier*Mcand;
  40.             Mul_Start = 1;
  41.             repeat(2) @(posedge clk);
  42.             Mul_Start = 0;
  43.             repeat(10) @(posedge clk);
  44.             assert(Product == expProduct) else
  45.             $error("Product (%0d) not as expected (%0d)", Product, expProduct);
  46.             @(posedge clk);
  47.         end
  48.         $finish();
  49.     end
  50. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement