-1

我从这段代码的第 15 行得到一个解析错误。

12: module DoShellSort(
13:    input [10*20-1:0] toSort,
14:    output [10*20-1:0] sorted
15:    reg arrBitSize
16: );

这是我正在初始化 input 和 reg 变量的测试台的一部分。

module ShellSort_tb;
    reg [10*19:0] toSort, arrBitSize;
    wire [10*19:0] sorted;
    integer i;

    DoShellSort ss_tb ([10*19:0] toSort, [10*19:0] sorted, arrBitSize);

    // Input values you want to sort here
    // Note: Should be 20 bits in size
    initial $readmemh ("memory_hex.txt", toSort);

    initial begin
        #1 $display("\nThis program implements SHELL SORT to arrange values.\n");

        // Display initial array
        #10 $display("Array to sort: ");
        #10 for (i = 0; i < arrBitSize + 1; i = i + 1)
            $write("%h", toSort[i]);

        #10 arrBitSize = 4'd9;

        // ................
endmodule

我正在使用 iVerilog 进行合成。这是错误消息:

在此处输入图像描述

谁能帮我弄清楚为什么我会遇到解析错误?谢谢!

4

2 回答 2

2

您定义端口的方式有误,缺少逗号和端口方向,或者将 rweg 放在错误的位置并缺少逗号。你有:

 module DoShellSort(
    input [10*20-1:0] toSort,
    output [10*20-1:0] sorted //missing comma?
    reg arrBitSize            //missing port direction?
);

我想你的意思是:

 module DoShellSort(
    input      [10*20-1:0] toSort,
    output reg [10*20-1:0] sorted, arrBitSize
);

我发现单独列出每个端口是更好的做法,因为这样可以更轻松地更新代码并且即使对于那些不熟悉该语言的人来说界面也很清晰。

 module DoShellSort(
    input      [10*20-1:0] toSort,
    output reg [10*20-1:0] sorted, 
    output reg [10*20-1:0] arrBitSize
);
于 2014-12-08T13:27:08.967 回答
0

你的端口连接不好。除了类型声明之外,您不能有未打包的维度。DoShellSort ss_tb (toSort[10*19:0], sorted[10*19:0], arrBitSize);

并且您的模块端口声明在输出 [10*20-1:0] 排序后缺少“,”。

于 2014-12-08T13:20:25.677 回答