Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly VHDL-in-case语句中的语法错误_Assembly_Syntax_Vhdl_Computer Architecture - Fatal编程技术网

Assembly VHDL-in-case语句中的语法错误

Assembly VHDL-in-case语句中的语法错误,assembly,syntax,vhdl,computer-architecture,Assembly,Syntax,Vhdl,Computer Architecture,我对VHDL非常陌生。这里我有一个程序,计算两个数字的GCD。我有很多案例和if陈述。 当我尝试模拟时,它给出了6个错误,没有太多描述 错误: “U:\GCD.dwv”错误0第41行:语法错误 “U:\GCD.dwv”错误0第43行:语法错误 有趣的是,它们之间有两行分隔。所以它从第33行开始,上升到第43行,有相同的错误。它从“when S3=>”行开始。 这是我的密码。谢谢大家! library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_

我对VHDL非常陌生。这里我有一个程序,计算两个数字的GCD。我有很多案例和if陈述。 当我尝试模拟时,它给出了6个错误,没有太多描述

错误: “U:\GCD.dwv”错误0第41行:语法错误 “U:\GCD.dwv”错误0第43行:语法错误

有趣的是,它们之间有两行分隔。所以它从第33行开始,上升到第43行,有相同的错误。它从“when S3=>”行开始。 这是我的密码。谢谢大家!

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

entity GCD is
    port(clk, st : in std_logic; d1, d2 : in std_logic_vector(15 downto 0); dout : out std_logic_vector(15 downto 0); rdy : out std_logic);
end GCD;


architecture behav of GCD is
type state is (S0, S1, S2, S3, S4, S5, S6, S7);
signal new_state : state;
signal eq, It, eq1 : boolean;

begin
        --State Transition Process 
    process is
    variable curr_state : state := S0;
    begin

    if clk ='1' then
        case curr_state is
            when S0 =>
                if st='1' then curr_state := S1;
                end if;
            when S1 =>
                curr_state := S2;
            when S2 =>
                if eq then curr_state := S7;
                else if It then curr_state := S4;
                else if not(eq or It) then curr_state := S3;
                end if;
            when S3 =>
                curr_state := S4;
            when S4 =>
                curr_state := S5;
            when S5 =>
                if eq1 then curr_state := S7;
                else curr_state := S6;
                end if;
            when S6 =>
                curr_state := S1;
            when S7 =>
                if not(st) then curr_state := S0;
                end if;
        end case;
        new_state <= curr_state;
    end if;
    wait on clk;
end process;


-- Asserted Outputs Process:

process is

variable M, N, T, dout_val : std_logic_vector(15 downto 0);
variable rdy_val : std_logic;
variable eq_val, It_val, eq1_val : boolean;
begin

    rdy_val := '0';
    case new_state is
        when S0 =>
            M := d1; N := d2;
        when S1 =>
            eq_val := M=N; It_val := to_integer(M) < to_integer(N);
        when S2 =>
        when S3 =>
            M := T; M := N; N := T;
        when S4 =>
            eq1_val := to_integer(M) = 1;
        when S5 =>
        when S6 =>
            N := N - M; 
        when S7 =>
            rdy_val := '1'; dout_val := M; 
    end case;
    eq <= eq_val;
    It <= It_val;
    eq1 <= eq1_val;
    rdy <= rdy_val;
    dout <= dout_val;
    wait on new_state;
end process;


end behav;
IEEE库;
使用IEEE.std_logic_1164.all;
使用IEEE.std_logic_arith.all;
实体GCD为
端口(clk,st:in标准逻辑;d1,d2:in标准逻辑向量(15向下至0);dout:out标准逻辑向量(15向下至0);rdy:out标准逻辑);
结束GCD;
GCD的体系结构行为是
类型状态为(S0、S1、S2、S3、S4、S5、S6、S7);
信号新_状态:状态;
信号eq,It,eq1:布尔值;
开始
--状态转换过程
过程是
变量当前状态:状态:=S0;
开始
如果clk='1',则
目前的情况是
当S0=>
如果st='1',则当前状态:=S1;
如果结束;
当S1=>
当前状态:=S2;
当S2=>
如果eq,则当前状态:=S7;
否则,如果其当前状态:=S4;
否则,如果不是(eq或It),则当前状态:=S3;
如果结束;
当S3=>
当前状态:=S4;
当S4=>
当前状态:=S5;
当S5=>
如果为eq1,则当前状态:=S7;
其他当前状态:=S6;
如果结束;
当S6=>
当前状态:=S1;
当S7=>
如果不是(st),则当前状态:=S0;
如果结束;
终例;
新州
M:=d1;N:=d2;
当S1=>
等式:M=N;It_val:=to_integer(M)
当S3=>
M:=T;M:=N;N:=T;
当S4=>
eq1_val:=到_整数(M)=1;
当S5=>
当S6=>
N:=N-M;
当S7=>
rdy_val:=“1”;dout_val:=M;
终例;

eq使用
elsif
代替
elseif
。可能还有一些错误潜伏在那里

use ieee.std_logic_unsigned.all;  -- because you use std_logic_arith
。。。国家过渡进程:

        when S7 =>
            if st = '0' then -- not (st) then 
                curr_state := S0;
            end if;
。。。输出过程:

        when S1 =>
            eq_val := M = N; 
            -- It_val := to_integer(M) < to_integer(N);
            It_val := M < N;

        when S4 =>
            -- eq1_val := to_integer(M) = 1;
            eq_val := conv_integer(M) = 1;
当S1=>
等式:M=N;
--It_val:=to_integer(M)
--eq1_val:=到_整数(M)=1;
等式值:=conv_整数(M)=1;
VHDL对分隔符有明确的要求,其余的是样式。由于缺乏一致的风格,您的代码需要仔细阅读


其他读者无疑会建议使用package
numeric\u std
,如果您使用的是兼容VHDL-2008的工具,package
std\u numeric\u unsigned
而不是Synopsys-非标准使用package
std\u logic\u unsigned
。您尝试使用的to_integer是来自
std_logic\u unsigned

我想给您一个关于如何编写FSM的示例。我希望它能对你有用

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;

ENTITY FSM IS
  PORT(
     Clk           : IN  STD_LOGIC;
     nResetLogic   : IN  STD_LOGIC;
     A             : IN  STD_LOGIC;
     B             : IN  STD_LOGIC;
     OUT_A              : OUT STD_LOGIC;
     OUT_B              : OUT STD_LOGIC;
    );
END ENTITY FSM;

ARCHITECTURE RTL OF FSM IS

-- states
TYPE state IS (stateA, stateB, stateC);
signal present_state, next_state : state;

-- Segnals for outputs
signal s_OUT_A              : STD_LOGIC;  
signal s_OUT_B              : STD_LOGIC;  



BEGIN

  -- Sequential section

  PROCESS (nResetLogic, Clk)
  BEGIN

    IF nResetLogic = '0' THEN
      present_state <= stateA;
    ELSIF (RISING_EDGE(Clk)) THEN
      present_state <= next_state;
    END IF;

  END PROCESS;

  -- Comb Section

  PROCESS (A,B,present_state)

  BEGIN
    --defaults
    s_OUT_A <= '0';         
    s_OUT_B <= '0';

    next_state <= present_state;

    CASE present_state IS
        WHEN stateA =>
            -- state definition
            IF (B = '0' AND A = '1') THEN 
                next_state <= stateB;
            ELSIF (B = '1' AND  A = '0') THEN
                next_state <= stateC;
            END IF;

            --output definition
            s_OUT_A <= '0';         
            s_OUT_B <= '1';


        WHEN stateB =>
            -- state definition
            IF (B = '1' AND A = '1') THEN 
                next_state <= stateC;
            ELSIF (B = '1' AND A = '0') THEN 
                next_state <= stateA;

            END IF;

            --output definition
            s_OUT_A <= '1';         
            s_OUT_B <= '1';


        WHEN stateC =>
            -- state definition
            IF (B = '0' AND A = '1') THEN 
                next_state <= statoA;
            ELSIF (B = '1' AND A = '0') THEN
                next_state <= statonB;
            END IF;

            --output definition
            --get defaults        

    END CASE;

  END PROCESS;

  -- Outputs
  OUT_A <= s_OUT_A;         
  OUT_B <= s_OUT_B;  

END ARCHITECTURE RTL;
ieee库;
使用ieee.std_logic_1164.ALL;
使用ieee.numeric_std.ALL;
实体FSM是
港口(
Clk:标准逻辑中;
nResetLogic:标准逻辑;
答:标准逻辑;
B:标准逻辑;
OUT_A:OUT标准_逻辑;
OUT_B:OUT标准_逻辑;
);
终端实体FSM;
FSM的RTL体系结构是
--州
类型状态为(stateA、stateB、stateC);
信号当前\状态,下一\状态:状态;
--输出序列
信号s_OUT_A:标准逻辑;
信号s_OUT_B:标准逻辑;
开始
--连续切片
流程(nResetLogic、Clk)
开始
如果nResetLogic='0',则

present_state对于上面的编码风格有一些不错的评论,但是为了直接回答最初的问题,当您很好地布局“if”语句时,您的错误非常明显:

when S2 =>
    if eq then curr_state := S7;
    else if It then curr_state := S4;
    else if not(eq or It) then curr_state := S3;
    end if;
变成:

when S2 =>
    if eq then
        curr_state := S7;
    else
        if It then
            curr_state := S4;
        else
            if not(eq or It) then
                curr_state := S3;
            end if;

如您所见,缺少两个“end if”语句。通常,您会发现由FPGA工具产生的错误实际上是由前一行中的某些内容引起的。在这种情况下,行“S3= >”产生了错误,因为在“否则”块的中间不能有一个“何时”。

谢谢戴维。成功了。也适用于其他指示!我不能使用其他软件包或库,因为这是一项任务,也是我的第一个vhdl程序。我不确定我们是否被允许。还要注意,虽然模拟器可能不在乎,但合成工具可能会在生成触发器时犹豫不决,因为您只指定
if clk='1'
,而不是
if clk'event和clk='1'
。对变量也要小心。我经常看到初学者使用它们,但它们很少需要(特别是在相当简单的系统中),而且很容易出错。您在这段代码中使用的变量都是不需要的。将它们替换为信号或直接分配给最终输出/信号将清除代码;M:=N;N:=T用于交换N和M。对于信号,这不是问题-您不需要临时值,因为信号分配的右侧在进程执行开始时使用该值(
M@QuantumRipple感谢您的帮助。对于第二个,它们不是信号,而是普通变量,因此我需要一个临时变量。对吗?是的,临时变量是必要的。但是,使用变量是不必要的。如果您生成M和N个信号,并在当前分配值的位置直接分配信号,则变量的作用仍然是一样的。除了更容易出错外,它们还倾向于