我正在尝试将几个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的一个组件,但是我如何将它们绑定在一起呢?
发布于 2010-11-16 00:18:35
有趣的是你甚至会问这个问题。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-10-27 02:03:17
您不能(轻松地)将这些1位ALU串在一起,形成一个功能强大的多位版本。没有办法处理add和subtract模式正常工作所需的进位输入/输出(但是,按位and & or应该可以工作)。
暂时忽略进位问题,您通常只需设置一个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;https://stackoverflow.com/questions/4025962
复制相似问题