2010-10-26 78 views
0

我试图将几个1位ALU组合成一个4位ALU。我很困惑如何在VHDL中实际做到这一点。下面是1位ALU,我使用的代码:我假设我定义为ALU1较大实体ALU4的一个组成部分从几个1位ALU制作一个4位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 

,但我怎么能绑在一起?

回答

0

您不能(容易地)将这些1位ALU串联到一个功能多位版本中。无法处理加/减模式正常工作所需的进/出(然而,按位和&或应该工作正常,但是)。

暂时忽略进位问题,你通常只安装一个用于生成循环和实例化按位逻辑的多个副本,可能是特殊的外壳中的第一和/或最后一个元素,即:

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; 
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));