`timescale 1ns / 10ps ////////////////////////////////////////////////////////////////////////////////// // // Filename: tb_arithmetic.v // // Author: Mike Wirthlin // // Description: Provides a basic testbench for the arithmetic lab. // // Version 1.1 // // Change Log: // v1.1: Modified the arithmetic_top to use "port mapping by name" rather than // port mapping by order. // ////////////////////////////////////////////////////////////////////////////////// module tb_arithmetic(); reg [15:0] sw; wire [8:0] led; integer i,errors; reg signed [31:0] rnd; reg signed [8:0] A,B,result; // Instance the Seven Segment display arithmetic_top dut(.sw(sw), .led(led)); initial begin errors = 0; #20 $display("*** Starting simulation at time %t ***", $time); #20 // Test 256 random cases for(i=1; i < 256; i=i+1) begin rnd = $random; sw[15:0] = rnd[15:0]; A[7:0]=sw[15:8]; A[8]=sw[15]; B[7:0]=sw[7:0]; B[8]=sw[7]; result=A+B; #20 if (result != led) begin $display("Error: A=%b,B=%b and result=%b but expecting %b at time %t", A,B,led,result, $time); errors = errors + 1; end end #20 $display("*** Simulation done with %3d errors at time %t ***", errors, $time); $finish; end // end initial begin endmodule