This documents our humble attempt at automating the testing of a MIPS project in Verilog using Perl.
We had two test scripts, general_test.pl
and predefined_test.pl
.
general_test.pl
is made so that you can easily initialize some registers
and pass a set of instructions and check the values of any number of registers
after the execution; it was used for evaluating and grading the project.
predefined_test.pl
is a set of tests that don't need initializing registers,
nor checking the values of random registers; it depends on $0
being 0 always,
and on $at
being initialized with 1, and after the execution it checks only
the values of $s0
and $s1
; it was used for checking that we haven't messed
anything up yet.
- Make the instruction memory read the instructions from a hexadecimal file:
reg [31:0] I_Memory [0:255]; // 2 power 8 instructions of length 32-bits
initial $readmemh("instructions.hex", I_Memory);
- In the case of
general_test
, which requires initializing the register file, make it read from a hexfile:
reg signed [31:0] data [31:0];
initial $readmemh("registers.hex", data);
And in the case of predefined_test
, initialize $at
to 1.
- Once
xxx
s enter the register file, terminate the execution with$finish
, but before terminating:
In case of general_test
, dump the registers to a hexfile, using:
$writememh("registers.hex", data);
And in case of predefined_test
, print $s0
and $s1
in a specific format:
$display("T: %d %d", data[16], data[17]);
-
Put your instructions, followed by 4
nop
s (because of the previous point), in the suitable place inpredefined_test.pl
orgeneral_test.pl
. -
Modify and run
general_test.pl
and/orpredefined_test.pl
as needed.
Now we have the assembler, the testing script, and code inside the processor that helps us to test it. all we need is to start testing!
The two testing scripts are attached; the assembler can be found here.