繁体   English   中英

VHDL ALU未定义值

[英]VHDL ALU undefined value

我正在学习VHDL,用于对FPGA(基本(但难于实现)项目)进行编程。 我有这个ALU。 假定是4位ALU。 但是当我要执行Add操作时, result值为UUUU 对于所有其他操作都正常。

有什么建议吗?

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

use IEEE.NUMERIC_STD.ALL;


entity ALU is
    Port (
                clk: in std_logic;
                reset: in std_logic;
                operation: in std_logic_vector (2 downto 0)
          );
end ALU;

architecture Behavioral of ALU is
    signal A : std_logic_vector (3 downto 0) := "0001";
    signal B : std_logic_vector (3 downto 0) := "1111";
    signal result : std_logic_vector (7 downto 0);
    signal flags : std_logic_vector (2 downto 0);   -- [S,OF,Z] 
begin

    process (operation) begin
        flags <= (others => '0');
        result <= (others => '0');
        case operation is
            when "000" => 
                result <= std_logic_vector((unsigned("0000"&A) + unsigned(B)));
                flags(1) <= result(4);
            when "001" =>
                if (A >= B) then
                    result <= std_logic_vector(unsigned("0000"&A) - unsigned(B));
                    flags(2) <= '0';
                else
                    result <= std_logic_vector(unsigned("0000"&B) - unsigned(A));
                    flags(2) <= '1';
                end if;
            when "010" =>
                result <= "0000"&A and "0000"&B;
            when "011" =>
                result <= "0000"&A or "0000"&B;
            when "100" =>
                result <= "0000"&A xor "0000"&B;
            when "101" =>
                result <= not ("1111"&A);
            when "110"  =>
                result <= not ("1111"&B);
            when "111" =>
                result <= std_logic_vector(unsigned(A) * unsigned(B));
            when others =>
                result <= (others => 'Z');
        end case;
    end process;

end Behavioral;

我可以看到所有U发生的唯一方法(按原样使用代码)是该进程永不执行。 这意味着添加操作必须在operation信号上没有事务。

这只会引发更多问题:

您是否肯定会得到U (也许不是X ?):信号是否也在驱动其他信号?

您可以发布测试平台代码吗?

查看您的代码时想到的前两件事是:

  1. 您应该在过程敏感性列表中包括AB (现在它仅包含operation )。

  2. 您不能使用result(4)来设置flags(1) ,因为result(4)仅在该过程之后才会更新,并且result本身不在敏感列表中,因此该过程不会再次触发反映更改后的值。 最好的选择可能是将总和存储在variable ,然后将其分配给result和溢出位。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM