【问题标题】:Making a 4-bit ALU from several 1-bit ALUs从几个 1 位 ALU 制作一个 4 位 ALU
【发布时间】:2010-10-26 16:55:11
【问题描述】:

我正在尝试将几个 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 的一个组件,但我怎样才能将它们联系在一起呢?

【问题讨论】:

    标签: vhdl alu


    【解决方案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));
    

    【讨论】:

      【解决方案2】:

      您不能(轻松地)将这些 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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多