给你个简单的例子吧 
功能模块的输入信号就是我们要在测试模块中编写的输出信号,意思就是测试的激励信号有testbench中的输出给出 
如下为二分频功能模块 
module div(clk,rst,clk_out 
       ); 
input clk; 
input rst; 
output clk_out; 
reg clk_out; 
 
always @(posedge clk or negedge rst) 
begin 
   if(!rst) 
         clk_out<=0; 
  else 
         clk_out<=~clk; 
end 
 
endmodule 
 
测试模块如下 
`timescale 1ns/1ns //不可缺少此语句 
module test; 
reg  clk;//输出给功能模块的激励信号在initial中应用要定义成reg型  
reg rst; 
wire clk_out;//功能模块的输出信号定义成wire型 
initial 
 begin 
   clk=0;//clk初始化 
   rst=1;//产生rst信号,初始为高电平, 
  #7 rst=0;//过7ns秒后变为低电平 
 #11 rst=1;//过11ns后变为高电平 
 #1000 $stop;//过1000ns后停止激励信号变化输出 
end 
 
always #10 clk=~clk;//产生周期变化的时钟信号 
 
div div (.clk(clk),.rst(rst),.clk_out(clk_out));// 例化功能模块,实现信号之间的链接,信号一一对应,信号个数不可多也不可少; 
 
endmodule |