简体   繁体   中英

Verilog Adder testbench

//In here, `WORD_LEN is 32.

`include "Defines.v"

module Adder (in1, in2, out);
  input [`WORD_LEN-1:0] in1, in2;
  output [`WORD_LEN-1:0] out;

  assign out = in1 + in2;
endmodule

///////////////////////////////////////////////////////////////

`timescale 1ns/1ns

module AdderTest;
  reg in1, in2;
  wire out;
  Adder TestAdder(.in1(in1), .in2(in2), .out(out));

  initial begin
  in1 = 4'b0000; in2 = 4'b0000; #100;
  in1 = 4'b0011; in2 = 4'b1111; #100;
  in1 = 4'b1000; in2 = 4'b1100; #100;
  $stop;
  end


endmodule

When I simulate this, Only in1[0] and in2[0] gets the value. Except for them, they got a blue line. Also, out got a red line. I really don't get what's wrong with this. Please help.

Although you define in1 , in2 , and out as 32-bit ports in your module (as indicated by your comment), the connected signals in your testbench are only 1 bit wide. Therefore, only the first bit of your module's input signals (ie, in1[0] and in2[0] ) are driven.

Try to use the following testbench:

module AdderTest;
  reg  [31:0] in1, in2; // CHANGE
  wire [31:0] out;      // CHANGE
  Adder TestAdder(.in1(in1), .in2(in2), .out(out));

  initial begin
    in1 = 4'b0000; in2 = 4'b0000; #100;
    in1 = 4'b0011; in2 = 4'b1111; #100;
    in1 = 4'b1000; in2 = 4'b1100; #100;
    $stop;
  end
endmodule

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM