Advertisement
Shamks412

Untitled

Sep 20th, 2024
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SystemVerilog 1.74 KB | Source Code | 0 0
  1. // Top Test Bench
  2.  
  3. module tb;
  4.   // Interface instantiation
  5.   div_if #(32) div_intf();
  6.  
  7.   // DUT instantiation
  8.   div #(.DATA_WIDTH(32)) div_inst (
  9.     .clk(div_intf.clk),
  10.     .rst_n(div_intf.rst_n),
  11.     .dividend(div_intf.dividend),
  12.     .divisor(div_intf.divisor),
  13.     .signed_ope(div_intf.signed_ope),
  14.     .start(div_intf.start),
  15.     .flush(div_intf.flush),
  16.     .quotient(div_intf.quotient),
  17.     .remainder(div_intf.remainder),
  18.     .ready(div_intf.ready)
  19.   );
  20.  
  21.   // Clock generation
  22.   initial begin
  23.     div_intf.clk = 0;
  24.     forever #5 div_intf.clk = ~div_intf.clk;
  25.   end
  26.  
  27.   // Reset task
  28.   task reset();
  29.     div_intf.rst_n = 0;
  30.     div_intf.start = 0;
  31.     div_intf.flush = 0;
  32.     @(posedge div_intf.clk);
  33.     div_intf.rst_n = 1;
  34.   endtask
  35.  
  36.   // Monitor task to print signals every clock cycle
  37.   task monitor_signals();
  38.     $display("Time: %0t | clk: %b | rst_n: %b | start: %b | ready: %b | flush: %b | signed_ope: %b", $time, div_intf.clk, div_intf.rst_n, div_intf.start, div_intf.ready, div_intf.flush, div_intf.signed_ope);
  39.     $display("           | dividend: %0d | divisor: %0d | quotient: %0d | remainder: %0d", $signed(div_intf.dividend), $signed(div_intf.divisor), $signed(div_intf.quotient), $signed(div_intf.remainder));
  40.   endtask
  41.  
  42.   // Run the environment and monitor signals
  43.   initial begin
  44.     div_env env = new(div_intf);
  45.  
  46.     // Apply reset
  47.     reset();
  48.  
  49.     // Monitor and display signals during execution
  50.     fork
  51.       forever begin
  52.         @(posedge div_intf.clk);
  53.         monitor_signals();
  54.       end
  55.       env.run();  // Run the test environment
  56.     join_none
  57.  
  58.     #100;
  59.     $finish;
  60.   end
  61.  
  62.   // Dump waveforms
  63.   initial begin
  64.     $dumpfile("wave.vcd");
  65.     $dumpvars(0, tb);
  66.   end
  67. endmodule
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement