减去两个 32 位输入时 Icarus Verilog 语法错误?

Icarus Verilog syntax error when subtracting two 32-bit inputs?

我在学习 Verilog 的第一周经历了一次非常令人沮丧的经历。

我正在尝试编译以下代码 - 来自 mipsalu.v

module MIPSALU (ALUctl, A, B, ALUOut, Zero);
  input [3:0] ALUctl;
  input [31:0] A,B;
  output reg [31:0] ALUOut;
  output Zero;
  assign Zero = (ALUOut==0); //Zero is true if ALUOut is 0; goes anywhere
  always @(ALUctl, A, B) //reevaluate if these change
    case (ALUctl)
      0: ALUOut <= A & B;
      1: ALUOut <= A | B;
      2: ALUOut <= A + B;
      3: ALUOut <= A ^ B;
      6: ALUOut <= A – B;
      7: ALUOut <= A < B ? 1:0;
      12: ALUOut <= ~(A | B); // result is nor
      default: ALUOut <= 0; //default to 0, should not happen;
    endcase
endmodule

当我尝试使用 iverilog -o test mipsalu.v 编译它时,iverilog 告诉我

mipsalu.v:13: syntax error
I give up.

当我删除有问题的行并再次编译时,没有错误-

module MIPSALU (ALUctl, A, B, ALUOut, Zero);
  input [3:0] ALUctl;
  input [31:0] A,B;
  output reg [31:0] ALUOut;
  output Zero;
  assign Zero = (ALUOut==0); //Zero is true if ALUOut is 0; goes anywhere
  always @(ALUctl, A, B) //reevaluate if these change
    case (ALUctl)
      0: ALUOut <= A & B;
      1: ALUOut <= A | B;
      2: ALUOut <= A + B;
      3: ALUOut <= A ^ B;
      //6: ALUOut <= A – B;
      7: ALUOut <= A < B ? 1:0;
      12: ALUOut <= ~(A | B); // result is nor
      default: ALUOut <= 0; //default to 0, should not happen;
    endcase
endmodule

如有任何见解,我们将不胜感激。谢谢!

编辑:值得一提的是,我在 Windows 8.1 上 运行 Icarus Verilog 版本 10 使用 MinGW/MSYS

不确定您是怎么做到的,但是您的 是 ISO 8859-1 下扩展 ASCII 中的一个字符。根据 ascii-code.com,ASCII 代码编号为 150 DEC(HTML 代码 &#150;)。 Verilog 期望 - ASCII 代码编号 45 DEC(HTML 代码 &#45;)。

两者看起来几乎一模一样; (&#150;) 仅比 - (&#45;) 长几个像素,至少对于某些字体而言。

可能是您的文本编辑器正在即时更改它,认为破折号看起来比减号更具可读性。


仅供参考:在 Verilog 中,您通常希望组合逻辑分配有阻塞分配 (=),顺序逻辑分配有 non-blocking 分配 (<=)。您正在将 non-blocking 用于组合逻辑,应该更改为阻塞。

always @(ALUctl, A, B) 是合法的,但请注意还有 always @*(或 SystemVerilog 的 always_comb),它是一个 auto-sensitivity 列表。如果您遗漏了敏感度列表中的某个项目,仿真中的 verilog 功能行为和综合功能行为可能会有所不同。

如果你想减少一些输入,你可能想试试 ANSI header 风格。它已与其他问题讨论过多次 (https://whosebug.com/search?q=%5Bverilog%5D+ANSI)