我正在为一个项目创建一个电路。在这段代码中,我想保存曼切获胜者的游戏选择。 我在控制了实际获胜者之后选择游戏选择。 这是代码:
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
。
我怎样才能做到这一点?
可以通过在每个
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
我们代码的缩进不寻常且具有误导性。
虽然这可能会修复您的语法错误,但此代码还存在其他问题,可能会导致综合问题。