i';我用VHDL制作了一个2位的算术逻辑单元。它给出了一个类型错误 实体alu是 端口(a、b、Sel):标准逻辑向量(1到0); res:out标准逻辑向量(1到0); 末端alu; alu的体系结构是 开始 过程(Sel、a、b) 开始 case Sel是 当“00”=> 物件 物件 物件 物件 res

i';我用VHDL制作了一个2位的算术逻辑单元。它给出了一个类型错误 实体alu是 端口(a、b、Sel):标准逻辑向量(1到0); res:out标准逻辑向量(1到0); 末端alu; alu的体系结构是 开始 过程(Sel、a、b) 开始 case Sel是 当“00”=> 物件 物件 物件 物件 res,vhdl,Vhdl,您错过了实体结构的一个重要部分: entity alu is Port ( a,b,Sel : in STD_LOGIC_VECTOR (1 downto 0); res : out STD_LOGIC_VECTOR (1 downto 0)); end alu; architecture Behavioral of alu is begin process(Sel,a,b) begin case Sel is when "00" =>

您错过了实体结构的一个重要部分:

entity alu is
        Port ( a,b,Sel : in  STD_LOGIC_VECTOR (1 downto 0);
               res : out  STD_LOGIC_VECTOR (1 downto 0));
end alu;
architecture Behavioral of alu is
begin
process(Sel,a,b)
begin
case Sel is
when "00" =>
    res<=a+b;
when "01" =>
    res<=a+(not b)+1;
when "10" =>
    res<=a and b;
when "11" =>
    res<=a or b;
when others =>
    res<="xx";
end case;
end process;
end Behavioral;
这个过程从哪里开始?它需要看起来像:

architecture Behavioral of alu is
begin
  case Sel is
    -- ...
  end case;
end process;
end Behavioral;
根据评论,您还有一个重复的案例

最后,您分配给
“xx”
的作业需要使用大写字母,即
“xx”
。但是,由于一旦您更正了重复项,您就已经涵盖了
Sel
的所有有效状态,因此您可以更常规地完成
others
子句,如下所示:

architecture Behavioral of alu is
begin
  process (Sel, a, b)  -- process definition and sensitivity list
  begin
    case Sel is
      -- ...
    end case;
  end process;
end Behavioral;

这意味着对其他情况“不做任何事情”。

谢谢,我更正了,但现在第17行显示错误:res的类型与xx的类型不兼容
when others =>
  NULL;