2016-09-24 247 views
-1

我是VHDL的新手。我正在嘗試使用代碼來查找位矢量是否甚至不是(使用位矢量的漢明權重)。我寫的代碼是:vhdl中if語句的語法錯誤

entity hw_mod is 
generic(
bits:integer ); 
port (
inp : in std_logic_vector((bits-1) downto 0; 
    cout : out std_logic); 
end entity hw_mod 

architecture hw_arch of hw_mod is 
begin 

process(inp) 
variable count : Integer:=0; 

begin 
    labelloop: for i in 0 to (bits-1) loop 
       if(inp(i)=='1') then 
        count:= count+1; 
         end if; 
         end loop; 
        if ((count mod 2)== '0') then 
         cout:=1; 
        else 
      cout:=0; 
      end if; 
end process; 
    end hw_arch; 

我不斷收到「鄰近‘=’錯誤:語法錯誤 在兩個地方

+2

所以我搜索了「vhdl比較運算符」,第一個結果表示等於'=',而不是'=='。 – melpomene

+0

我早些時候嘗試過,但是我得到的錯誤是「near」=「:expectcting == or + or - or& –

+1

你的問題不是一個最小完整和可驗證的例子,因爲非VHDL的傢伙注意到」== 「不是VHDL中的關係運算符(」=「is),參見IEEE Std 1076-2008 9.2.3關係運算符在缺少inp端口聲明子類型指示範圍的結束符」end entity hw_mod'缺少一個關閉分號的語句,'count'是一個整數,它將其與一個十進制文字進行比較,使用cout的信號分配,並且它是基於std_ulogic的(例如'cout <='0'';而不是'cout:= 0;')在你的if語句條件中你有多餘的括號 – user1155120

回答

0

我檢查你的代碼: - 一般是不正常
- COUT是一個信號,所以它需要<=
- 。:=僅供變量

它給沒有錯誤,但還是有鎖變量在使用前需要進行initalized

LIBRARY ieee; 
    USE ieee.std_logic_1164.all; 
    USE ieee.numeric_std.all; 
entity hw_mod is 
generic( 
    bits : integer range 0 to 3 := 3); 
port ( 
    inp : in std_logic_vector((bits-1) downto 0); 
    cout : out std_logic); 
end entity hw_mod; 

architecture hw_arch of hw_mod is 
begin 
    process(inp) 
    variable count : Integer:=0; 
    begin 
     labelloop: 
      for i in 0 to (bits-1) loop 
       if(inp(i)='1') then 
        count:= count+1; 
       end if; 
      end loop; 
      if ((count mod 2)= 0) then 
       cout <= '1'; 
      else 
       cout <= '0'; 
      end if; 
    end process; 
end hw_arch; 
1

幾個問題。使用編輯器在鍵入時檢查語法。

  • 括號不匹配。
  • 你缺少一些分號,
  • 您使用C風格的比較(的==代替=
  • 在你需要變量賦值信號(的:=代替<=

enter image description here