从几个1位ALU中产生4位ALU

时间:2010-10-26 16:55:12

标签: vhdl alu

我正在尝试将几个1位ALU组合成一个4位ALU。我对如何在VHDL中实际执行此操作感到困惑。以下是我正在使用的1位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的一个组件,但我怎样才能将它们绑在一起?

2 个答案:

答案 0 :(得分: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));

答案 1 :(得分:0)

您不能(轻松地)将这些1位ALU串联成功能多位版本。没有办法处理加法和减法模式正常工作所需的进/出(按位和&amp;或者应该正常工作)。

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

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;
相关问题