Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

can i declare a 2D array as following ?

hi every body

can i declare a 2D array as following ?

type dataout is array (6 downto 0,11 downto 0) of std_logic_vector(7 downto 0);

i guess this is a 3D array not 2D.

so how i can have a 2d array of std_logic_vector?

thank u

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    For a 2D array just have one range in the brackets, instead of two.

    type dataout is array (6 downto 0) of std_logic_vector(7 downto 0);

    This will result in an array of 7 std_logic_vectors of range 7 downto 0.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    For a 2D array just have one range in the brackets, instead of two.

    type dataout is array (6 downto 0) of std_logic_vector(7 downto 0);

    --- Quote End ---

    Nope, thats not a 2d array, thats a 1d array of 1d array. So you access it like this:

    output <= dout(x).

    A 2d array is declared like the OP posted. He made a 2d array of 1d arrays. You would access it like this:

    output <= dout(x,y); --and then add 2nd set of brackets to get individual bits
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks a lot my friend!

    --- Quote Start ---

    Nope, thats not a 2d array, thats a 1d array of 1d array. So you access it like this:

    output <= dout(x).

    A 2d array is declared like the OP posted. He made a 2d array of 1d arrays. You would access it like this:

    output <= dout(x,y); --and then add 2nd set of brackets to get individual bits

    --- Quote End ---

    i wanna initialize this vector, i have a 2d matrix of std_logic_vector

    can i write like this:

    
    constant d : dataout :=(
                    -- Content           -- Address(i,j)
                    "00111100",        -- 0,0               "11110000"    --0,1               "01100010"   --0,2                 "01100010"   --0,3           ...
                             
                    "01100010",        -- 1,0               "10011000",   --1,1              "10111000"   --1,2               "00111000"    --1,3           ...
                          
                    "00111100",        -- 2,0               "11110000"   --2,1                "01100010"  --2,2                 "01100010"   --2,3            ...
                   
                       ........