How to "slice" an std_logic_vector in VHDL?

51,925

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);
Share:
51,925
Earlz
Author by

Earlz

Hello there! My name's Jordan Earls, but most people online know me as "earlz". I'm the lead developer and a co-founder of the Qtum project which brings the Ethereum Virtual Machine (ie, the thing that makes Solidity contracts function) to a UTXO based blockchain similar to Bitcoin. I've been programming since I was 13 and am completely self-taught. Low-level code like assembly and pointer arithmetic is the fun stuff for me. I also make music when I have time even though it's usually awful. Most of my personal projects are open source and BSD licensed. The majority of them are at bitbucket with the rest of them being listed on github Also, you can follow me on the twitters @earlzdotnet

Updated on July 16, 2022

Comments

  • Earlz
    Earlz almost 2 years

    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

  • Earlz
    Earlz about 12 years
    Ah. I'm seeing more and more now that VHDL is a very consistent language. Also, the alias solution is much cleaner, so I'll use that
  • ComFreek
    ComFreek about 8 years
    Note that for example std_logic_vector([some expression])(15 downto 8) won't work. See this answer for more detail when this syntax is applicable.