0

在这段代码中,我试图将 16 位数字相乘并获得 32 位输出。代码有错误。在线

    c<=c+a;

编译器给出错误:“无法读取模式输出的端口'c'。我的错误是什么?谢谢。

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_arith.all;
    use ieee.std_logic_unsigned.all;

    entity circ is
    port (  a    :in std_logic_vector (15 downto 0);
    b    :in std_logic_vector (15 downto 0);
    c    :out  std_logic_vector (31 downto 0)
        );

    end entity;

    architecture data of circ is
    begin
process(a,b)
begin
c<= '0';   
for i in 15 to 0 loop
if (b(i) = '1') then
c<=c+a;
end if;
END LOOP;

end process;
    end data;
4

1 回答 1

1

该错误正是编译器告诉您的

无法读取模式的端口“c”

您无法读取输出。您在c写作时正在阅读,c <= c + a因为c出现在作业的右侧。您必须像这样重写代码:

signal s : std_logic_vector(31 downto 0);

process(a,b)
begin
  s <= (others => '0');   
  for i in 15 to 0 loop
    if (b(i) = '1') then
      s <= s + a; -- Use a local signal that we can read and write
    end if;
  end loop;
  c <= s; -- Assign the output to the local signal.
end process;
于 2012-05-17T10:13:19.513 回答