what is function of for loop in this code

Status
Not open for further replies.

moonnightingale

Full Member level 6
Joined
Sep 17, 2009
Messages
362
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
3,832
This is test bench for 4x4 multiplier
why book is using for loop for i and j plz explain

module testbench;
reg [ 3:0] A, B; //using reg data type for all inputs
wire [ 7:0] rslt; //using wire data type for outputs from instantiated module

mult mult_inst (A, B, rslt); // Instantiating the module under test

initial
begin : init
parameter FALSE = 0;
parameter TRUE = 1;
reg [ 4:0] i, j;
reg passed;

passed = TRUE;
for (j = 1; j < 16; j = j + 1)
begin
for (i = 1; i < 16; i = i + 1)
begin
A = i;
B = j;
#1;
if (rslt != i * j)
begin
passed = FALSE;
$display("test failed for %d x %d", i, j );
end // if
end // for i
end // for j

if (passed)
$display("test passed");
else
$display("test failed");
$finish;
end

endmodule
 

Because there are 16 combinations which can be done from 4 x 4 multiplier. So the 2 for loop is actually a nested for loop which will scan through the 4x4 matrix and initialize A= i and B = j
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…