2014-04-27 37 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