2

I want to use std_logic_vector as index for an array, for example:

Data: in std_logic_vector(7 downto 0);
signal counter : std_logic_vector(3 downto 0);

output <= Data(counter);

Since VHDL syntax check tells me that I should use an integer with Data as index, I want to ask if it's possible to use an std_logic_vector as index.

In case not, if I use a counter like this:

signal counter : integer range 0 to 7 := 7;

Synthesizer will create a 8 bit counter(because 7 is maximum value) or it will create a 32bit counter? I ask this question becouse if I assign a value of 8 to counter vhdl syntax check doesn't tell me that is an error.

1
  • Synthesizer don't enforce VHDL standard (unlike a good simulator like ModelSim). Assigning 8 to a range 0 to 7 is illegal by VHDL standard. A synthesizer might accept it (and probably assign 0), but you really shouldn't rely on that. Commented Apr 18, 2015 at 14:24

1 Answer 1

6

To use std_logic_vector, you have to convert it:

Data: in std_logic_vector(7 downto 0);
signal counter : std_logic_vector(3 downto 0);

output <= Data(to_integer(unsigned(counter)));

Regarding your second question, this will be a 3 bit counter:

signal counter : integer range 0 to 7 := 7;

Physically, integer and std_logic_vector makes no difference. It will result in exactly the same hardware after synthesis. Use the data type that makes most sense in your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.