2016-09-24 3 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つの場所で構文エラー

+2

私は "vhdl比較演算子"のためのグーグルで、最初の結果は平等は '='ではなく、 '=='であると言いました。 – melpomene

+0

私はこれを以前に試みましたが、エラーは "near" = ":expecting == or + or - または& –

+1

あなたの質問は最小限の完全で検証可能な例ではありません。 "はVHDL内の関係演算子ではありません(" = "はあります)。IEEE Std 1076-2008 9.2.3関係演算子。inpポート宣言サブタイプの表示範囲の終わりの実体hw_modがありません。 'count'は10進リテラルと比較し、coutのシグナル割り当てを使用し、std_ulogicに基づいています(例えば' cout <= '0'; 'cout:= 0;') – user1155120

答えて

0

私はあなたのコードを確認: - ジェネリックは
OKではなかったです。 - 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

関連する問題