K
kb33
Guest
Hi,
I have two pieces of code, one works, the other doesn't. I am not able
to figure out why the second one doesn't. Any insight would be
appreciated. The second piece of code has an additional condition in
the IF statement
//Definitions common to both pieces of code:
reg [4:0] data_array [0:3];
reg [1:0] index_array1 [0:5],
index_array2 [0:5];
reg [1:0] var_1;
integer i;
initial
begin
//Initialization....
var_1 <= 2;
index_array1 [0] <= 0;
index_array1 [1] <= 2;
index_array2 [0] <= 1;
index_array2 [1] <= 3;
data_array [0] <= 8;
data_array [1] <= 4;
data_array [2] <= 3;
data_array [3] <= 1;
//This piece of code works:
for (i=0; i<2; i=i+1)
if (data_array [index_array1 ] > data_array
[index_array2 ])
begin
data_array [index_array1] <= data_array
[index_array2];
data_array [index_array2] <= data_array
[index_array1];
end
//This piece of code doesn't work:
for (i=0; i<2; i=i+1)
begin
if ((var_1 & index_array1 == 0) && (data_array
[index_array1 ] > data_array [index_array2]))
begin
data_array [index_array1 ] <= data_array
[index_array2 ];
data_array [index_array2 ] <= data_array
[index_array1 ];
end
else
if ((var_1 & index_array1 != 0) && (data_array
[index_array1 ] < data_array [index_array2]))
begin
data_array [index_array1 ] <= data_array
[index_array2 ];
data_array [index_array2 ] <= data_array
[index_array1 ];
end
end
I have two pieces of code, one works, the other doesn't. I am not able
to figure out why the second one doesn't. Any insight would be
appreciated. The second piece of code has an additional condition in
the IF statement
//Definitions common to both pieces of code:
reg [4:0] data_array [0:3];
reg [1:0] index_array1 [0:5],
index_array2 [0:5];
reg [1:0] var_1;
integer i;
initial
begin
//Initialization....
var_1 <= 2;
index_array1 [0] <= 0;
index_array1 [1] <= 2;
index_array2 [0] <= 1;
index_array2 [1] <= 3;
data_array [0] <= 8;
data_array [1] <= 4;
data_array [2] <= 3;
data_array [3] <= 1;
//This piece of code works:
for (i=0; i<2; i=i+1)
if (data_array [index_array1 ] > data_array
[index_array2 ])
begin
data_array [index_array1] <= data_array
[index_array2];
data_array [index_array2] <= data_array
[index_array1];
end
//This piece of code doesn't work:
for (i=0; i<2; i=i+1)
begin
if ((var_1 & index_array1 == 0) && (data_array
[index_array1 ] > data_array [index_array2]))
begin
data_array [index_array1 ] <= data_array
[index_array2 ];
data_array [index_array2 ] <= data_array
[index_array1 ];
end
else
if ((var_1 & index_array1 != 0) && (data_array
[index_array1 ] < data_array [index_array2]))
begin
data_array [index_array1 ] <= data_array
[index_array2 ];
data_array [index_array2 ] <= data_array
[index_array1 ];
end
end