0

我正在学习 VHDL 来编程 FPGA,基本(但对我来说很难)项目。我有这个 ALU。它应该是一个 4 位 ALU。但是当我想让Add操作的值resultUUUU. 对于所有其他操作都工作正常。

有什么建议吗?

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

2 回答 2

1

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

这只会引发更多问题:

你肯定得到Us (不是Xs 可能吗?):还有其他东西在驱动信号吗?

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

于 2011-11-17T13:09:52.280 回答
0

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

  1. 您应该在进程敏感度列表中包含AB(现在它只包含operation)。

  2. 您不能使用result(4)to set flags(1),因为result(4)只会在处理后更新,并且result本身不会再次出现在敏感度列表中,因此不会再次触发处理以反映更改的值。最好的选择可能是将总和存储在 a 中variable,然后将其分配给result溢出位。

于 2011-11-17T12:40:34.023 回答