Three options:
Probably the easiest way to do this is to read a file of expected results into a memory residing in the test harness. Initialise a pointer to the start of the file and increment it every time a comparison is made.
reg [7:0] results [0:1023];
reg [10:0] result_pointer;
reg [7:0] comp_value;
initial $readmemh(<filename>, results);
initial
begin
result_pointer = 0;
...
test_next(comp_value); // Fetch value
...
end
task test_next; // Use a task for convenience
output [7:0] value;
begin
if (result_pointer > 1023)
begin
$display(“Out of data!”);
$stop; // Oops! Error
end
else
begin
value = results[result_pointer];
result_pointer = result_pointer + 1;
end
end
endtask
There are several ways to do this.
$display
$write
C-like print statements: (nearly) identical except
$display(…)
adds a LF
to the string end.
If you want to stay on the same line
$write(…)
will do this.
Suggestions:
e.g.
$display(“Starting test”);
...
if (q != 32'h0000_0000)
$display(“Unexpected value: q = %X”, q);
Sometimes it is convenient to watch particular signals rather than all signals through time. This can be done with the $monitor task.
initial
$monitor(“this = %x that = %x at time %t”,
this, that, $time);
This is similar to:
always @ (this, that)
$display(“this = %x that = %x at time %t”,
this, that, $time);
allow you to create your own output files. (“$fwrite” is the same as “$fdisplay” except for line-feeds.) Their use, including file handles, is similar that which should be familiar from C programming.
Up to simulation
Back to initialising simulations
Forward to next session ‘if’s and ‘xxxx’s in simulation