Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "slice" an std_logic_vector in VHDL?

Tags:

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

like image 938
Earlz Avatar asked Apr 29 '12 20:04

Earlz


People also ask

What is std_logic_vector in VHDL?

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.

What is a slice in VHDL?

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.

What is the difference between std_logic and std_logic_vector?

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.

What is downto in VHDL?

The keywords downto and to specify the direction of ranges in VHDL. downto is descending (going down); to is ascending (going up).


Video Answer


1 Answers

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); 
like image 67
Charles Steinkuehler Avatar answered Sep 20 '22 12:09

Charles Steinkuehler