【问题标题】:How to: multidimensional arrays in vhdl如何:vhdl 中的多维数组
【发布时间】:2013-02-15 11:55:36
【问题描述】:

我正在尝试在 VHDL 中创建一个 5 维数组,但我不确定如何设置和初始化这些位。

这是我目前所拥有的:

    type \1-line\ is array (4 - 1 downto 0) of unsigned (32 - 1 downto 0);
    type square is array (4 - 1 downto 0) of \1-line\;
    type cube is array (4 - 1 downto 0) of square;
    type hypercube is array (4 - 1 downto 0) of cube;
    type \5-cube\ is array (4 - 1 downto 0) of cube;

    signal mega_array : \5-cube\;
    begin
        process (clock, reset) begin
                if (reset == '1') then
                        mega_array <= '0';
                end if;
        end process;
    end behv;

【问题讨论】:

    标签: arrays vhdl


    【解决方案1】:

    一种方法是使用 '(others =>'0')'。这是将向量的所有位设置为“0”的干净且安全的方法。您必须对阵列的每一层都执行此操作。

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    
    entity test is
        port (
            clock : in std_logic;
            reset : in std_logic);
    end entity test;
    
    architecture behv of test is
    
        type \1-line\ is array (4 - 1 downto 0) of unsigned (32 - 1 downto 0);
        type square is array (4 - 1 downto 0) of \1-line\;
        type cube is array (4 - 1 downto 0) of square;
        type \5-cube\ is array (4 - 1 downto 0) of cube;
    
        signal mega_array : \5-cube\;
    
    begin
    
        process (clock, reset)
        begin
            if (reset = '1') then           -- note: not '=='
                mega_array <= (others => (others => (others => (others => (others => '0')))));
            end if;
        end process;
    
    end architecture behv;
    

    请注意,尽管\1-... 命名是正确的 VHDL,但我不会使用它来避免令人讨厌的工具问题。我不确定他们会不会来,但避开他们总比解决他们好。我会改用t_1line

    【讨论】:

    • 我只是使用了一个 for 循环来初始化它们
    【解决方案2】:

    您需要的是聚合:

    (others =&gt; '0') 将向量中的所有位设置为“0”

    (others =&gt; (others =&gt; '0')) 将向量数组的所有元素设置为所有位 '0'

    (others =&gt; (others =&gt; (others =&gt; '0')))...等:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多