为什么我不断收到此“语法错误二进制基本错误”?在 EDA 游乐场?

发布于 2025-01-11 10:52:27 字数 2257 浏览 0 评论 0原文

我尝试了几种方法,但在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离笑几人歌 2025-01-18 10:52:27

您缺少将每个 case 分支项括起来的 begin/end 关键字。

module alu(
  input wire[63:0] A,B,  // ALU 64-bit Inputs                 
  input wire [3:0] ALU_Sel,// ALU Selection
  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
);
  
always @(*)
    begin
      Carry=0;
      Zero=0;
      Overflow=0;
      Negative=0; 
      case(ALU_Sel[3:0])
          4'b0000:  begin //AND -h0
          ALU_Result = A & B;
          Carry=1;
          end
          4'b0010: begin //ADD -h2
          ALU_Result = A + B;
          end
          4'b0011: begin //ADDS -h3
          ALU_Result = A + B;
          //CREATE FLAGS HERE
          //reg Carry = 1;
          end
          4'b1100: begin//EOR -h12
          ALU_Result =A^B;
          end
          4'b0110: begin //SUB -h6
          ALU_Result = A-B;
          end
          4'b0111: begin//SUBS -h7
          ALU_Result = A-B;
          //CREATE FLAGS HERE
          end
          4'b1001: begin //LSL -h9
          ALU_Result = A << B;
          end
          4'b0001: begin//OR -h1
          ALU_Result = A | B;
          end
         endcase
      end
endmodule

You are missing bracketing begin/end keywords around each case branch item.

module alu(
  input wire[63:0] A,B,  // ALU 64-bit Inputs                 
  input wire [3:0] ALU_Sel,// ALU Selection
  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
);
  
always @(*)
    begin
      Carry=0;
      Zero=0;
      Overflow=0;
      Negative=0; 
      case(ALU_Sel[3:0])
          4'b0000:  begin //AND -h0
          ALU_Result = A & B;
          Carry=1;
          end
          4'b0010: begin //ADD -h2
          ALU_Result = A + B;
          end
          4'b0011: begin //ADDS -h3
          ALU_Result = A + B;
          //CREATE FLAGS HERE
          //reg Carry = 1;
          end
          4'b1100: begin//EOR -h12
          ALU_Result =A^B;
          end
          4'b0110: begin //SUB -h6
          ALU_Result = A-B;
          end
          4'b0111: begin//SUBS -h7
          ALU_Result = A-B;
          //CREATE FLAGS HERE
          end
          4'b1001: begin //LSL -h9
          ALU_Result = A << B;
          end
          4'b0001: begin//OR -h1
          ALU_Result = A | B;
          end
         endcase
      end
endmodule
乱了心跳 2025-01-18 10:52:27

您的代码中有几个错误。

您在 EDAplayground 上看到的第一个错误位于第 20 行(使用 Adlec 模拟器),即这一行:

  asssign Negative = N;

在我的网络浏览器中,EDAplayground 对代码应用语法突出显示,其中 Verilog 关键字是彩色的,其他作品是黑色打印的。这将 asssign 单词显示为黑色,这意味着它无法将其识别为 Verilog 关键字。这是一个错字;将其更改为:

  assign Negative = N;

下一个错误是这一行:

      Carry=1;

就其本身而言,语法很好,但与上面的行一起来看,存在错误。当 case 语句内使用多个语句时,它们必须用 begin/end 关键字括起来。

      4'b0000:  //AND -h0
      begin
          ALU_Result = A & B;
          C=1;
      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:

  asssign Negative = N;

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:

  assign Negative = N;

The next error is this line:

      Carry=1;

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 the begin/end keywords.

      4'b0000:  //AND -h0
      begin
          ALU_Result = A & B;
          C=1;
      end

After making the above changes, there are still errors. You make multiple assignments to the same signal (Carry): one using the assign statement, and another inside the always block. You can't do both, which means you need to decide which is the one you want. Deleting the assign 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, the Z signal is not assigned a value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文