verilog怎么写testbench

1.Verilog键盘扫描程序的testbench怎么写modulemul3_testbench;//定义一个没有输入输出端口的测试平台rega2,a1,a0,b2,b1,b0;//被测模块的input端口,改为对应的reg寄存器做输入信号wirep5,p4,p3,p2,p1,p0;//被测模块的output端口,改为对应的wire型initialbegin//初始化所有输入信号的寄存器值a2=0;a1=0;a0=0;b2=0;b1=0;b0=0;#50//一般延迟较长时间后,应该使复位信号不复位系统正常工作,但你没有复位信号end//初始化模块结束后一般时序电路仿真是产生时钟信号,//这是纯组合逻辑没有时钟信号就省略了//然后就可以根据你所需要验证的功能在此位置编写initial块或always块给reg型//的输入信号赋值的相关逻辑,观察wire型输入信号的值//---------------------------调用被测对象,格式如一般元件调用-------------------mul3DUT(.a2(a2),.a1(a2),.a0(a0),.b2(b2),.b1(b2),.b0(b0),.p5(p5),.p4(p4),.p3(p3),.p2(p2),.p1(p1),.p0(p0));endmodule//最后的提示,你的程序里定义了整数型变量,其实是不好的用法,甚至不能被正确综合,//可以用等值的reg型变量来替代,即使你定义成整数型,实际上也是被综合成reg型的,//另外,一般可综合代码中最好不要用for语句,个人认为你的代码会完全功能不正常的 。
2.Verilog键盘扫描程序的testbench怎么写modulemul3_testbench;//定义一个没有输入输出端口的测试平台rega2,a1,a0,b2,b1,b0;//被测模块的input端口,改为对应的reg寄存器做输入信号wirep5,p4,p3,p2,p1,p0;//被测模块的output端口,改为对应的wire型initialbegin//初始化所有输入信号的寄存器值a2=0;a1=0;a0=0;b2=0;b1=0;b0=0;#50//一般延迟较长时间后,应该使复位信号不复位系统正常工作,但你没有复位信号end//初始化模块结束后一般时序电路仿真是产生时钟信号,//这是纯组合逻辑没有时钟信号就省略了//然后就可以根据你所需要验证的功能在此位置编写initial块或always块给reg型//的输入信号赋值的相关逻辑,观察wire型输入信号的值//---------------------------调用被测对象,格式如一般元件调用-------------------mul3DUT(.a2(a2),.a1(a2),.a0(a0),.b2(b2),.b1(b2),.b0(b0),.p5(p5),.p4(p4),.p3(p3),.p2(p2),.p1(p1),.p0(p0));endmodule//最后的提示,你的程序里定义了整数型变量,其实是不好的用法,甚至不能被正确综合,//可以用等值的reg型变量来替代,即使你定义成整数型,实际上也是被综合成reg型的,//另外,一般可综合代码中最好不要用for语句,个人认为你的代码会完全功能不正常的 。
3.verilog中怎么新建一个testbenchtimescale 1ns/100psmodule testbench;localparam DATA_WIDTH = 32;localparam CLK_100_PERIOD = 5;localparam CLK_200_PERIOD = 2.5;localparam SIM_TIME = 150000;localparam ;localparam ;reg clk_100, clk_200;wire clk;assign clk = clk_100;alwaysbeginclk_100 = 0;forever #CLK_100_PERIOD clk_100 = ~clk_100;endalwaysbeginclk_200 = 0;forever #CLK_200_PERIOD clk_200 = ~clk_200;endreg rstn;integer fp_testin;integer fp_matlab_out;integer fp_sim_out;integer fp_outdiff;reg signed [DATA_WIDTH/2-1:0] matlab_in_re, matlab_in_im;reg signed [DATA_WIDTH/2-1:0] matlab_out_re, matlab_out_im;reg signed [DATA_WIDTH/2-1:0] matlab_diff_re, matlab_diff_im;reg signed [DATA_WIDTH/2-1:0] matlab_diff_re2, matlab_diff_im2;reg signed [DATA_WIDTH/2-1:0] max_diff_re, max_diff_im;initial beginmax_diff_re = 0;max_diff_im = 0;rstn = 0;#500rstn = 1;#SIM_TIMEsim_finish();$stop();endtask sim_finish;beginif(fp_testin!=0)$fclose(fp_testin);if(fp_matlab_out!=0)$fclose(fp_matlab_out);if(fp_sim_out)$fclose(fp_sim_out);if(fp_outdiff!=0)$fclose(fp_outdiff);endendtaskinitialbeginfp_testin = 0;fp_testin= $fopen("txt_file/input_data.txt","r");if(fp_testin==0)begin$display("input_data.txt open failed!");sim_finish();$stop();endelse begin$fscanf(fp_testin, "%d, %d\n",matlab_in_re,matlab_in_im);endfp_matlab_out = 0;fp_matlab_out = $fopen("txt_file/matlab_out.txt","r");if(fp_matlab_out==0)begin$display("fp_matlab_out.txt open failed!");sim_finish();$stop();endelse begin$fscanf(fp_matlab_out,"%d, %d\n",matlab_out_re,matlab_out_im);endfp_sim_out = 0;fp_sim_out = $fopen("txt_file/modelsim_out.txt","w");if(fp_sim_out == 0)begin$display("modelsim_out_re.txt open failed!");sim_finish();$stop();endfp_outdiff = 0;fp_outdiff = $fopen("text_file/outdiff.txt","w");if(fp_outdiff==0)begin$display("outdiff.txt open failed!");sim_finish();$stop();endendalways @(posedge clk)beginif(stest_wvalid && stest_wready) //ready to changebeginif(~$feof(fp_testin))$fscanf(fp_testin, "%d, %d\n",matlab_in_re,matlab_in_im);endelsebeginmatlab_in_re