Concatenate bits

Discussion in 'VHDL' started by aleksa, Feb 29, 2012.

  1. aleksa

    aleksa Guest

    constant size : integer := 32;
    datain : in std_logic_vector(9 downto 0);
    signal request : std_logic_vector(size-1 downto 0);

    Now I wish to set "request" to "datain", like this:
    request <= "0000000000000000000000" & datain;
    (datain to lower bits, all other bits to zero)

    How do I write that w/o all those zeros?
    It should also work if I later change "size".

    Thanks
    aleksa, Feb 29, 2012
    #1
    1. Advertising

  2. aleksa wrote:

    > constant size : integer := 32;
    > datain : in std_logic_vector(9 downto 0);
    > signal request : std_logic_vector(size-1 downto 0);
    >
    > Now I wish to set "request" to "datain", like this:
    > request <= "0000000000000000000000" & datain;
    > (datain to lower bits, all other bits to zero)
    >
    > How do I write that w/o all those zeros?
    > It should also work if I later change "size".
    >
    > Thanks


    This is how you can do that:
    request <= (1 TO request'LENGTH-datain'LENGTH => '0') & datain;

    Or, if the signal assignment is in sequential code (process, procedure), you
    can do:

    request <= (OTHERS => '0');
    request(datain'RANGE) <= datain;

    The first assignment sets all bits to zero, while the second assignment
    overwrites bits 9..0 with datain. With sequential signal assignments, the
    last one wins.

    --
    Paul Uiterlinden
    www.aimvalley.nl
    Paul Uiterlinden, Feb 29, 2012
    #2
    1. Advertising

  3. On Wed, 29 Feb 2012 04:04:50 -0800, aleksa wrote:

    > constant size : integer := 32;
    > datain : in std_logic_vector(9 downto 0);
    > signal request : std_logic_vector(size-1 downto 0);
    >
    > Now I wish to set "request" to "datain", like this:
    > request <= "0000000000000000000000" & datain;
    > How do I write that w/o all those zeros?


    -- Given the declarations above,
    request <= (size - 1 downto 10 => '0') & datain;
    -- would work, but a less accident-prone way is
    request <= (size - 1 downto datain'length => '0') & datain;
    -- or even
    request <= (request'high downto datain'length => '0') & datain;
    -- Brian
    Brian Drummond, Feb 29, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GGG
    Replies:
    10
    Views:
    12,509
    Donar
    Jul 6, 2006
  2. Abby

    Concatenate bits, then convert to HEX

    Abby, Oct 28, 2003, in forum: C Programming
    Replies:
    2
    Views:
    8,241
    Mark McIntyre
    Oct 29, 2003
  3. sarmin kho
    Replies:
    2
    Views:
    816
    A. Lloyd Flanagan
    Jun 15, 2004
  4. aleksa

    Concatenate bits

    aleksa, Feb 29, 2012, in forum: VHDL
    Replies:
    1
    Views:
    705
    joris
    Mar 2, 2012
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    854
Loading...

Share This Page