键入不匹配错误,如何解决此问题

时间:2014-04-27 13:32:55

标签: vhdl

这是我添加和减去

的简单ALU的代码
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
library IEEE;
use IEEE.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity alu is
Port ( A : in  STD_LOGIC_VECTOR (15 downto 0);
       B : in  STD_LOGIC_VECTOR (15 downto 0);
          funct: in STD_LOGIC;
          op: in STD_LOGIC_VECTOR (1 downto 0);
       Result : out  STD_LOGIC_VECTOR (15 downto 0));
end alu;

architecture Behavioral of alu is
begin

process (op, funct)
 begin
  case op is
    when "00" => Result <= A+B;
    when "01" => Result <= A-B;
    when others => case funct is 
                        when "0" => Result <= A+B;
                        when "1" => Result <= A-B;
                        when others => null;
    end case;
`end case;
end process;
end Behavioral;

我收到以下错误

ERROR:HDLParsers:800 - "E:/Xilinx Projects/alu/alu.vhd" Line 51. Type of funct is     incompatible with type of 0.
ERROR:HDLParsers:800 - "E:/Xilinx Projects/alu/alu.vhd" Line 52. Type of funct is incompatible with type of 1.
ERROR:HDLParsers:163 - "E:/Xilinx Projects/alu/alu.vhd" Line 55. Unexpected symbol read: `.

我知道它与“功能”和“结果”的类型不匹配有关,但我不知道如何解决它,任何想法?

1 个答案:

答案 0 :(得分:1)

分析:

library ieee;
use ieee.std_logic_1164.all;
--  library ieee;  -- successive library clause has no effect
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity alu is
    port ( 
        a:      in  std_logic_vector (15 downto 0);
        b:      in  std_logic_vector (15 downto 0);
        funct:  in  std_logic;
        op:     in  std_logic_vector (1 downto 0);
        result: out std_logic_vector (15 downto 0)
    );
end alu;

architecture behavioral of alu is
begin

process (op, funct)
 begin
    case op is
        when "00" => 
            result <= a+b;
        when "01" => 
            result <= a-b;
        when others => 
            case funct is 
                when '0' => result <= a+b;  -- "0"
                when '1' => result <= a-b;  -- "1"
                when others => null;
            end case;
    end case; -- `end case;
end process;
end behavioral;

类型std_logic具有使用字符文字的枚举,其本身是标量,不能将字符串分配给funct。从std_logic_1164包声明:

-------------------------------------------------------------------
TYPE std_ulogic IS ( 'U',  -- Uninitialized
                     'X',  -- Forcing  Unknown
                     '0',  -- Forcing  0
                     '1',  -- Forcing  1
                     'Z',  -- High Impedance
                     'W',  -- Weak     Unknown
                     'L',  -- Weak     0
                     'H',  -- Weak     1
                     '-'   -- Don't care
                   );
-------------------------------------------------------------------

-------------------------------------------------------------------
SUBTYPE std_logic IS resolved std_ulogic;

-------------------------------------------------------------------

正如您的问题评论中所提到的,严重重音字符不应位于第二个end case;前面。

相关问题