最简单的二位比较模块
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
module eq2(a,b,aeqb);
input wire [1:0] a,b;
output wire aeqb;
assign aeqb = (a==b?1:0);
endmodule
下面是testbench
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
module eq2_test;
// Inputs
reg [1:0] a;
reg [1:0] b;
// Outputs
wire aeqb;
integer log_file,console_file,out_file;
reg[3:0] v_mem[0:7];
integer i;
// Instantiate the Unit Under Test (UUT)
eq2 uut (
.a(a),
.b(b),
.aeqb(aeqb)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
log_file=$fopen("eqlog.txt");
if(!log_file)
$display("can't open log file");
console_file=32'b0000_0001;
out_file=log_file|console_file;
$readmemb("D:\vector.txt",v_mem);
for(i=0;i<8;i=i+1)
begin
{a,b}=v_mem;
#200;
end
$fclose(log_file);
$stop;
end
initial
begin
$display(out_file,"
time
a
b
aeqb") ;
$fmonitor(out_file,"d
%b
%b
%b",$time,a,b,aeqb);
end
endmodule
可以在ISE中调用modelsim直接仿真
我在
D:\vector.txt 这个文件里面内容如下
00_00
01_00
01_11
10_10
10_00
11_11
11_01
00_10 |