I'm developing a little thing in VHDL and am quite new to it. I'm having trouble figuring out how to slice a bigger std_logic_vector into a smaller one.
For instance I have 3 signals:
signal allparts: std_logic_vector(15 downto 0); signal firstpart: std_logic_vector(7 downto 0); signal secondpart: std_logic_vector(7 downto 0);
Basically, what I want is to assign bits 15 through 8 to secondpart
and bits 7 through 0 to firstpart
. How exactly would I "slice" a vector like this without assigning individual bits
The VHDL keyword “std_logic_vector” defines a vector of elements of type std_logic. For example, std_logic_vector(0 to 2) represents a three-element vector of std_logic data type, with the index range extending from 0 to 2.
Description. The slice is a subarray of a one-dimensional array, from a single element up to complete array. The prefix used for a slice is the name of the parent array. The index used for a slice must fall in the range of the indexes of the parent array.
Std_logic signals represent one data bit and std_logic_vector represents several data bits. The signal assignments for standard logic and standard logic vector data types are shown in Example 1-15. The number of data bits for a std_logic_vector is defined in the signal assignment statement.
The keywords downto and to specify the direction of ranges in VHDL. downto is descending (going down); to is ascending (going up).
You can directly assign them:
firstpart <= allparts(15 downto 8); secondpart <= allparts(7 downto 0);
...or if firstpart and secondpart are simply alternate ways to refer to part of the allparts signal, you may want to use an alias:
alias firstpart is allparts(15 downto 8); alias secondpart is allparts(7 downto 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With