0

我正在尝试将几个 1 位 ALU 组合成一个 4 位 ALU。我对如何在 VHDL 中实际执行此操作感到困惑。这是我正在使用的 1bit ALU 的代码:

component alu1 -- define the 1 bit alu component
  port(a, b: std_logic_vector(1 downto 0);
  m: in std_logic_vector(1 downto 0);
  result: out std_logic_vector(1 downto 0));
end alu1;

architecture behv1 of alu1 is
begin
  process(a, b, m)
  begin
   case m is
     when "00" =>
        result <= a + b;
      when "01" =>
        result <= a + (not b) + 1;
      when "10" =>
        result <= a and b;
      when "11" =>
        result <= a or b;
    end case
  end process
end behv1

我假设我将 alu1 定义为更大实体 alu4 的一个组件,但我怎样才能将它们联系在一起呢?

4

2 回答 2

1

有趣的是,你甚至会问这个问题。VHDL 合成器非常有能力推断您喜欢的任何加法器。您只需输入您需要的内容:

use ieee.numeric_std.all;
...
signal r : unsigned(3 downto 0);
signal a : unsigned(2 downto 0);
signal b : unsigned(2 downto 0);
signal c : unsigned(2 downto 0);
...
r  <=  a + b + c;

然后您可以切片r以满足您的需求:

result  <=  std_logic_vector(r(2 downto 0));
于 2010-11-15T16:18:34.923 回答
0

您不能(轻松)将这些 1 位 ALU 串在一起形成一个功能性的多位版本。无法处理加减模式正常工作所需的进位/输出(但是,按位和 & 或应该可以正常工作)。

暂时忽略进位问题,您通常只需设置一个 for generate 循环并实例化您的按位逻辑的多个副本,可能对第一个和/或最后一个元素进行特殊封装,即:

MyLabel : for bitindex in 0 to 3 generate
begin
  alu_x4 : entity work.alu1
  port map (
    a => input_a(bitindex),
    b => input_b(bitindex),
    m => mode,
    result => result_x4(bitindex) );
end generate;
于 2010-10-26T18:03:17.163 回答