2014-04-27 33 views
0

这里是我的一个简单的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: `. 

代码,我知道这事做类型不匹配的'功能'和'结果',但我不知道如何解决它,任何想法?

+0

'0'是一个字符字面量或std_logic字面量。 “0”是一个字符串。这些有不同的类型。 –

+0

另外,在第二个结尾的情况之前有一个严重的重音字符;'。您的代码片段行数不匹配,我们可能会认为是第55行。正如Brian所说,应该将这些“0”和“1”字符串分别更改为字符文字“0”和“1”,并删除严重重音字符你的代码会分析。只有在IEEE Std 1076-2008的VHDL中才有重音符号,用于表示工具指令。 – user1155120

+0

你们是对的,非常感谢您的帮助,严重的口音被误输入了! – alexhilton

回答

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;的前面。

+0

谢谢大卫!代码现在工作正常! – alexhilton

+0

@alexhilton:如果Davids的答案是**答案,那么你应该考虑点击答案旁边的复选标记,因为这是正确的堆栈溢出行为(参见[当某人回答我的问题时该怎么办?]( http://stackoverflow.com/help/someone-answers))。它也会给你+2的重点(和回答者+15)。 –

+1

@MortenZilmer罗杰! – alexhilton