【问题标题】:Illegal sequential statement. error using std_logic_vector非法顺序语句。使用 std_logic_vector 时出错
【发布时间】:2017-04-28 16:40:30
【问题描述】:

我有一个 VHDL 项目,这是我第一次使用它。我需要创建一个由全加器构成的加法器/减法器,它需要能够添加 8 到 32 位数字。我定义了一个泛型,但是在尝试运行代码时我得到了非法的顺序语句。代码是这样的:

library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all; 
entity Add_Sub is
  generic (N : integer := 8); 
  port(addsub_line: in std_logic;
        A: in std_logic_vector(N-1 downto 0);
        B: in std_logic_vector(N-1 downto 0);
        SumOut: out std_logic_vector(N-1 downto 0);
        Cout: out std_logic);
end Add_Sub;

architecture struct of Add_Sub is
  component FA_Ent is
      port(a: in std_logic;
       b: in std_logic;
       carry_in: in std_logic;
       sum: out std_logic;
       carry_out: out std_logic);
  end component;
  component XOR_GATE is
    port(A: in std_logic;
         B: in std_logic;
         F: out std_logic);
  end component;

  signal BxorAddSub: std_logic_vector(N-1 downto 0);
  begin 
    process 
      begin
      for i in 0 to N-1 loop
        BxorAddSubLine: XOR_GATE port map(B(0), addsub_line, BxorAddSub(0));
      end loop;
    end process;
  end struct;

我猜我在某个地方使用了错误的循环。我正在尝试对我拥有的所有位进行异或,但我不知道我得到了多少,所以我必须使用循环任何人都知道我为什么会收到错误或者我应该如何做我想要达到的目标? 谢谢

【问题讨论】:

  • 组件实例化是一个并发语句,适用于带有for generate方案的generate语句,该方案可以包含并发语句,而进程语句只能包含顺序语句。
  • 如果这是您的第一个项目,您可能还不知道,您必须忘记几乎所有您所知道的有关编程的知识,因为这不是编程。这里有真正的硬件逻辑组件,而不是具有执行流程的程序。

标签: vhdl


【解决方案1】:

您的基本问题是您无法从进程内部实例化组件:

process 
begin
  for i in 0 to N-1 loop
    BxorAddSubLine: XOR_GATE port map(B(0), addsub_line, BxorAddSub(0));
  end loop;
end process;

正确的写法是:

XorGates : for i in 0 to N-1 generate
  BxorAddSubLine: XOR_GATE port map(B(0), addsub_line, BxorAddSub(0));
end generate;

另请注意,港口地图中的位置关联通常被认为是不好的做法。命名关联更易读,更不容易出错:

BxorAddSubLine: XOR_GATE
  port map(A => B(0),
           B => addsub_line,
           F => BxorAddSub(0));

最后,您的所有BxorAddSubLine 实例都连接到B(0)BxorAddSub(0);这可能不是你想要的。也许B(i)BxorAddSub(i)

【讨论】:

  • 其实可能是 B(i) 和 BxorAddSub(i)。这样你就可以将所有东西都连接到 N 而不是 0。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-23
  • 2019-11-09
  • 2015-06-07
  • 2011-08-31
  • 2018-12-12
相关资源
最近更新 更多