怎么写verilog 测试程序
2个回答
展开全部
给你写一个例子,下面是一个设计文件和一个对应的测试程序,希望能起到抛砖引玉的和用:
/*
File Name : test.v
Author : www.flxc.net
Data : 2010-10-14 20:20:52
Description : This module is to shift the 32 bit input data with clock edges.
*/
`timescale 1ns/1ns
`define period 10
module test(
clk,
rst_n,
data_i,
data_o
);
input clk;
input rst_n;
input [31:0] data_i;
output [31:0] data_o;
reg [31:0] data_o;
always@(posedge clk or negedge rst_n)
beg
if(!rst_n)
data_o <= 32'b0;
else
data_o <= data_i >>1;
end
endmodule
module test_tb;
reg clk;
reg rst_n;
reg [31:0] data_i;
wire [31:0] data_o;
initial
begin
clk=1'b1;
rst_n=1'b1;
data_i=32'b1010_1111_1000_1111_1111_0000_0001_0000;
#(`period/3)
rst_n=1'b0;
#(`period/3)
rst_n=1'b1;
#100000000
$stop;
end
always #(`period/2) clk=~clk;
endmodule
/*
File Name : test.v
Author : www.flxc.net
Data : 2010-10-14 20:20:52
Description : This module is to shift the 32 bit input data with clock edges.
*/
`timescale 1ns/1ns
`define period 10
module test(
clk,
rst_n,
data_i,
data_o
);
input clk;
input rst_n;
input [31:0] data_i;
output [31:0] data_o;
reg [31:0] data_o;
always@(posedge clk or negedge rst_n)
beg
if(!rst_n)
data_o <= 32'b0;
else
data_o <= data_i >>1;
end
endmodule
module test_tb;
reg clk;
reg rst_n;
reg [31:0] data_i;
wire [31:0] data_o;
initial
begin
clk=1'b1;
rst_n=1'b1;
data_i=32'b1010_1111_1000_1111_1111_0000_0001_0000;
#(`period/3)
rst_n=1'b0;
#(`period/3)
rst_n=1'b1;
#100000000
$stop;
end
always #(`period/2) clk=~clk;
endmodule
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |