首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VHDL ALU未定义值

VHDL ALU未定义值
EN

Stack Overflow用户
提问于 2011-11-17 04:02:51
回答 2查看 3.4K关注 0票数 0

我正在学习为FPGA编程的VHDL,基本的(但很难的)项目.我有这个ALU。它被认为是一个4位ALU。但是,当我想让添加操作时,result的值是UUUU。所有其他操作都很正常。

有什么建议吗?

代码语言:javascript
复制
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;
EN

回答 2

Stack Overflow用户

发布于 2011-11-17 13:09:52

唯一能看到所有U发生的方法(与代码一样)是进程从未执行的情况。这意味着您必须在operation信号上没有用于添加操作的事务。

这只会引起更多的问题:

您肯定得到了Us (而不是X的?):是否还有其他东西驱动信号?

你能把你的测试台代码寄出去吗?

票数 1
EN

Stack Overflow用户

发布于 2011-11-17 12:40:34

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

operation).

  • You
  1. 您应该在进程敏感性列表中包括AB (现在它只包含result(4)不能使用result(4)来设置flags(1),因为result(4)只会在进程之后更新,result本身也不会再次出现在敏感性列表中,因此不会再次触发进程以反映更改的值。最好的选择可能是将和存储在variable中,然后将其分配给result和溢出位。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8161958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档