2016-09-24 154 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