I would like to know if I can put below code in a for loop so I can parameterize my code. Thank you.
always@(*) begin
if (exist_reg[0] == 'd0) begin
nth_empty_location_descending = 'd1; // specify
end
else if (exist_reg[1] =='d0) begin
nth_empty_location_descending = 'd2;
end
else if (exist_reg[2] =='d0) begin
nth_empty_location_descending = 'd4;
end
else if (exist_reg[3] =='d0) begin
nth_empty_location_descending = 'd8;
end
else if (exist_reg[4] =='d0) begin
nth_empty_location_descending = 'd16;
end
else if (exist_reg[5] =='d0) begin
nth_empty_location_descending = 'd32;
end
else if (exist_reg[6] =='d0) begin
nth_empty_location_descending = 'd64;
end
else if (exist_reg[7] =='d0) begin
nth_empty_location_descending = 'd128;
end
else if (exist_reg[8] =='d0) begin
nth_empty_location_descending = 'd256;
end
else if (exist_reg[9] =='d0) begin
nth_empty_location_descending = 'd512;
end
else begin
nth_empty_location_descending = 'd0;
end
end
It is basically checking an "exist_reg" bits, if it encounters any bit from left to right is zero then it will rise that bit in "nth_empty_location_descending" register(any better approach?). Now I want to create parameterized code for the width of the register. Currently, it is 10-bit hardcoded code. Thank you experts.