如何修复此 Verilog 语法分配错误?

问题描述 投票:0回答:1

问题

我正在为一个项目创建一个电路。在这段代码中,我想保存曼切获胜者的游戏选择。 我在控制了实际获胜者之后选择游戏选择。 这是代码:

always @(manche) begin : DATAPATH
        last_winner <= manche;
        case (manche)
          2'b00, 2'b11:
                  game_choice <= 2'b00;
            2'b01:
                count1 <= count1 + 1;
            game_choice <= first;
            2'b10:
                count2 <= count2 + 1;
            game_choice <= first;
        endcase
    end

这段代码中的变量是:

  • last_winner
    :存储最后获胜者的寄存器,取自实际输出
    manche
  • game_choice
    :获胜者的选择
  • first
    second
    :玩家的选择
  • count1
    count2
    :玩家反击

每次运行此代码时,我都会收到以下错误:

** Error: (vlog-13069) design.sv(187): near ";": syntax error, unexpected ';', expecting ':'.
** Error: (vlog-13069) design.sv(191): near "2": syntax error, unexpected INTEGER NUMBER.

预计

我尝试将此代码始终拆分为多个,并且它有效,但我只想使用一个

always
。 我怎样才能做到这一点?

verilog system-verilog circuit
1个回答
0
投票

可以通过在每个

begin/end
项中的每对语句周围使用
case
关键字来修复语法错误:

   always @(manche) begin : DATAPATH
            last_winner <= manche;
            case (manche)
                2'b00, 2'b11: begin // "begin/end" is optional here
                      game_choice <= 2'b00;
                end
                2'b01: begin
                    count1 <= count1 + 1;
                    game_choice <= first;
                end
                2'b10: begin
                    count2 <= count2 + 1;
                    game_choice <= first;
                end
            endcase
    end

我们代码的缩进不寻常且具有误导性。

虽然这可能会修复您的语法错误,但此代码还存在其他问题,可能会导致综合问题。

© www.soinside.com 2019 - 2024. All rights reserved.