Altera_Forum
Honored Contributor
10 years agoArray indexing questions
Hi all, new user here, and new to verilog as well. I have some questions about indexing an array. Say I have a 16x8bit array. There will be an address input that points to which one of the 16 bytes to do action on. The trigger tells it when to do the action.
Here's the initialization stuff - module arraymem (new_width, trigger, address, stored_width); input trigger; input [7:0] new_width; input [3:0] address; output reg [7:0] stored_width; parameter memsize = 16; reg [7:0] width [memsize-1:0]; //16 x 8bit internal storage array
how to declare "k"?
initial begin for (k = 0; k <= memsize - 1; k = k + 1) //tells it to be 16 long begin width[k] = 4'h0000; end end
Immediately, I have a problem. The input address will be in binary form, 1111 indexing the 15th byte, 0000 indexing the 0th bye, 0010 indexing the 2nd byte, etc. But the parameter memsize where I declare that it is 16 long, it is an integer (or a non-binary at least). I want the binary input address to correspond to the proper integer parameter value, but I do not know how to do this. Any suggestions on this? I think I will start with this question before moving onto my next question. Thanks.