当单个实体上有多个架构时会发生什么?

时间:2015-04-13 20:20:49

标签: compilation vhdl modelsim quartus

假设有一个实体有两个架构定义。这两种架构使用相同的实体(显然),然后两者将输出引脚设置为不同的值。我的问题是,程序(模拟器)如何确定输出应该是什么(即选择哪种架构)?

以下是一个例子:

library ieee;
use ieee.std_logic_1164.all;

entity Exercise_4 is 
generic (n : integer := 4);
port(
a, b : std_logic_vector (n-1 downto 0);
clk, rst : std_logic;
q, qn : buffer std_logic_vector (n-1 downto 0));
end;

architecture one of Exercise_4  is
begin
process (clk, rst)
    begin
    if rst = '0' then 
        q <= (others=>'0');
    elsif (clk' event and clk = '0') then
        q <= a ;
    end if;
end process;

process (clk, rst)
begin
    if rst = '0' then 
        qn <= (others=>'1');
    elsif (clk' event and clk = '0') then
        for i in a'range loop
            qn(i) <= not q(i) ;
        end loop;
    end if;
end process;
end;

architecture two of Exercise_4  is
begin
process (clk,rst)
    begin
    if rst = '0' then 
        q <= (others=>'0'); 
        qn <= (others=>'0');
    elsif (clk' event and clk = '0') then
        q <= a;
        qn <= b ;
    end if;
end process;
end;

我进行了模拟,发现 q 获得 a 的值, < strong> qn 获取分配的 b 的值。似乎第二个架构已被编译器选中,我不明白为什么程序决定这样做。

谢谢。

2 个答案:

答案 0 :(得分:1)

如果您没有指定自己选择哪种架构,那么编译器将采用“与实体声明关联的最近分析的架构体”(假设编译器符合IEEE标准)[1]。

²您可以选择您喜欢的架构,例如在更高设计级别的组件声明部分(映射信号的位置)中:

.tar.gz

[1] IEEE Std 1076-2008 7.3.3默认绑定指示,第4段。

免责声明:答案是在上述评论的帮助下构建的。无侵犯版权之意。 ; P

答案 1 :(得分:0)

在没有配置绑定的情况下,默认情况下,编译器会考虑代码文件中的最后一个体系结构主体。

相关问题