我正在学习为FPGA编程的VHDL,基本的(但很难的)项目.我有这个ALU。它被认为是一个4位ALU。但是,当我想让添加操作时,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;发布于 2011-11-17 13:09:52
唯一能看到所有U发生的方法(与代码一样)是进程从未执行的情况。这意味着您必须在operation信号上没有用于添加操作的事务。
这只会引起更多的问题:
您肯定得到了Us (而不是X的?):是否还有其他东西驱动信号?
你能把你的测试台代码寄出去吗?
发布于 2011-11-17 12:40:34
在查看代码时,首先想到的两件事是:
operation).
A和B (现在它只包含result(4)不能使用result(4)来设置flags(1),因为result(4)只会在进程之后更新,result本身也不会再次出现在敏感性列表中,因此不会再次触发进程以反映更改的值。最好的选择可能是将和存储在variable中,然后将其分配给result和溢出位。https://stackoverflow.com/questions/8161958
复制相似问题