为什么我不断收到此“语法错误二进制基本错误”?在 EDA 游乐场?
我尝试了几种方法,但在 EDA 游乐场中不断收到此错误。我该如何修复它?我正在尝试实现一个系统来进行加法、减法等操作,并获取 ADDS 和 SUBS 的标志。我尝试创建一个 reg 变量,然后为其分配标志,但这不起作用。当我在 case 语句中不使用任何标志时,代码就会运行。这是我的代码和以下错误:
module alu(A,B, ALU_Sel,ALU_Out,Carry,Zero,Overflow,Negative,ALU_Result);
input wire[63:0] A,B; // ALU 64-bit Inputs
input wire [3:0] ALU_Sel;// ALU Selection
reg C;
reg Z;
reg O;
reg N;
output reg [63:0] ALU_Out; // ALU 8-bit Output
output reg Carry; // Carry Out Flag
output reg Zero;
output reg Overflow;
output reg Negative;
output reg [63:0] ALU_Result;
assign ALU_Out = ALU_Result; // ALU out
assign Carry=C;
assign Zero = Z;
assign Overflow = O;
asssign Negative = N;
always @(*)
begin
Carry=0;
Zero=0;
Overflow=0;
Negative=0;
case(ALU_Sel[3:0])
4'b0000: //AND -h0
ALU_Result = A & B;
C=1;
4'b0010: //ADD -h2
ALU_Result = A + B;
4'b0011: //ADDS -h3
ALU_Result = A + B;
//CREATE FLAGS HERE
//reg Carry = 1;
4'b1100: //EOR -h12
ALU_Result =A^B;
4'b0110: //SUB -h6
ALU_Result = A-B;
4'b0111: //SUBS -h7
ALU_Result = A-B;
//CREATE FLAGS HERE
4'b1001: //LSL -h9
ALU_Result = A << B;
4'b0001: //OR -h1
ALU_Result = A | B;
endcase
end
endmodule
ERROR VCP2000 "Syntax error. Unexpected token: =." "design.sv" 20 21
ERROR VCP2000 "Syntax error. Unexpected token: =." "design.sv" 31 13
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0011[_BINARY_BASE]." "design.sv" 36 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b1100[_BINARY_BASE]." "design.sv" 41 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0110[_BINARY_BASE]." "design.sv" 44 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0111[_BINARY_BASE]." "design.sv" 47 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b1001[_BINARY_BASE]." "design.sv" 51 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0001[_BINARY_BASE]." "design.sv" 54 18
I tried several things, but I keep getting this error in EDA playground. How do I fix it? I'm trying to implement a system to add, subtract, etc., and get flags for ADDS and SUBS. I tried creating a reg
variable and then assigning the flags to that, but that didn't work. The code runs when I don't use any flags in my case statements. Here is my code and the error below:
module alu(A,B, ALU_Sel,ALU_Out,Carry,Zero,Overflow,Negative,ALU_Result);
input wire[63:0] A,B; // ALU 64-bit Inputs
input wire [3:0] ALU_Sel;// ALU Selection
reg C;
reg Z;
reg O;
reg N;
output reg [63:0] ALU_Out; // ALU 8-bit Output
output reg Carry; // Carry Out Flag
output reg Zero;
output reg Overflow;
output reg Negative;
output reg [63:0] ALU_Result;
assign ALU_Out = ALU_Result; // ALU out
assign Carry=C;
assign Zero = Z;
assign Overflow = O;
asssign Negative = N;
always @(*)
begin
Carry=0;
Zero=0;
Overflow=0;
Negative=0;
case(ALU_Sel[3:0])
4'b0000: //AND -h0
ALU_Result = A & B;
C=1;
4'b0010: //ADD -h2
ALU_Result = A + B;
4'b0011: //ADDS -h3
ALU_Result = A + B;
//CREATE FLAGS HERE
//reg Carry = 1;
4'b1100: //EOR -h12
ALU_Result =A^B;
4'b0110: //SUB -h6
ALU_Result = A-B;
4'b0111: //SUBS -h7
ALU_Result = A-B;
//CREATE FLAGS HERE
4'b1001: //LSL -h9
ALU_Result = A << B;
4'b0001: //OR -h1
ALU_Result = A | B;
endcase
end
endmodule
ERROR VCP2000 "Syntax error. Unexpected token: =." "design.sv" 20 21
ERROR VCP2000 "Syntax error. Unexpected token: =." "design.sv" 31 13
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0011[_BINARY_BASE]." "design.sv" 36 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b1100[_BINARY_BASE]." "design.sv" 41 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0110[_BINARY_BASE]." "design.sv" 44 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0111[_BINARY_BASE]." "design.sv" 47 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b1001[_BINARY_BASE]." "design.sv" 51 18
ERROR VCP2000 "Syntax error. Unexpected token: 4'b0001[_BINARY_BASE]." "design.sv" 54 18
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少将每个 case 分支项括起来的
begin
/end
关键字。You are missing bracketing
begin
/end
keywords around each case branch item.您的代码中有几个错误。
您在 EDAplayground 上看到的第一个错误位于第 20 行(使用 Adlec 模拟器),即这一行:
在我的网络浏览器中,EDAplayground 对代码应用语法突出显示,其中 Verilog 关键字是彩色的,其他作品是黑色打印的。这将
asssign
单词显示为黑色,这意味着它无法将其识别为 Verilog 关键字。这是一个错字;将其更改为:下一个错误是这一行:
就其本身而言,语法很好,但与上面的行一起来看,存在错误。当
case
语句内使用多个语句时,它们必须用begin/end
关键字括起来。进行上述修改后,仍然有错误。您可以对同一个信号进行多次赋值 (
Carry
):一次使用assign
语句,另一个在always
块内。你不能两者兼而有之,这意味着你需要决定哪一个是你想要的。删除assign
语句将消除代码中的所有错误。根据您的评论(“
//CREATE FLAGS HERE
”)判断,我认为您尚未完成设计。例如,Z
信号未分配值。You have several errors in your code.
The 1st error you see on EDAplayground is on line 20 (using the Adlec simulator), which is this line:
In my web browser, EDAplayground applies syntax highlighting to the code, where Verilog keywords are colored and other works are in black print. This shows the
asssign
word as black, which means it does not recognize it as a Verilog keyword. It is a typo; change it to:The next error is this line:
On its own, the syntax is fine, but taken together with the line above it, there is an error. When multiple statements are used inside a
case
statement, they must be enclosed by thebegin/end
keywords.After making the above changes, there are still errors. You make multiple assignments to the same signal (
Carry
): one using theassign
statement, and another inside thealways
block. You can't do both, which means you need to decide which is the one you want. Deleting theassign
statements would remove all the errors from your code.Judging by your comments ("
//CREATE FLAGS HERE
"), I assume you are not yet finished with the design. For example, theZ
signal is not assigned a value.