arrays - 如何在Verilog中将多个数组合并为一个数组?

标签 arrays hardware mips verilog hdl

这是我的代码:

module MIPS_Processor();
    reg [7:0] mem [0:4095];      // 4K memory cells that are 8 bits wide
    reg [7:0] code[0:1023];      // 1K memory cells that are 8 bits wide
    reg [31:0] registers[0:31];  // 32 registers that are 32 bits wide
    reg [31:0] PC;               // The program counter

    initial
        begin
            PC = 0;
        end

    always
        begin
            // 1. Fetch an instruction from memory
            bit [31:0] instruction = {{code[PC * 8 + 7:PC * 8 + 0]},
                                     {code[(PC + 1) * 8 + 7:(PC + 1) * 8 + 0]},
                                     {code[(PC + 2) * 8 + 7:(PC + 2) * 8 + 0]},
                                     {code[(PC + 3) * 8 + 7:(PC + 3) * 8 + 0]}};

            // 2. Increment the program counter register (by the instruction length)
            PC = PC + 4;

            // Rest of the code

    end
endmodule

如何将 4 个数组合并为一个数组以从代码中获取指令?上面的代码无法编译!


编辑:

将代码更改为@toolic建议的内容后:

bit [31:0] instruction = {
                     code[PC + 0],
                     code[PC + 1],
                     code[PC + 2],
                     code[PC + 3]
};

仍然无法编译:

使用赛灵思:

=========================================================================
*                          HDL Compilation                              *
=========================================================================
Compiling verilog file "MIPS_Processor.v" in library work
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 39 expecting ']', found ':'
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 39 unexpected token: '='
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 39 unexpected token: '{'
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 40 expecting '.', found ','
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 41 expecting '.', found ','
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 42 expecting '.', found ','
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 44 expecting '.', found '}'
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 46 unexpected token: '='
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 46 unexpected token: 'PC'
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 46 expecting 'end', found '+'
Module <MIPS_Processor> compiled
ERROR:HDLCompilers:26 - "MIPS_Processor.v" line 46 expecting 'endmodule', found '4'
Analysis of file <"MIPS_Processor.prj"> failed.
--> 

Total memory usage is 274336 kilobytes

Number of errors   :   11 (   0 filtered)
Number of warnings :    0 (   0 filtered)
Number of infos    :    0 (   0 filtered)


Process "Synthesize - XST" failed

使用 Verilogger Extreme:

enter image description here

最佳答案

code 内存的 4 个连续字节形成指令字:

// 1. Fetch an instruction from memory
bit [31:0] instruction = {
                         code[PC + 0],
                         code[PC + 1],
                         code[PC + 2],
                         code[PC + 3]
};

关于arrays - 如何在Verilog中将多个数组合并为一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9745319/

相关文章:

javascript - 返回推送到数组的元素

java - 在 Java 中从文本文件打印字符串数组时出现空指针异常错误

PHP 按时间对数组进行排序并找到与 X 数字最接近的匹配项

Python ctypes 传递指针并获取空指针访问

hardware - USB设备可以直接访问硬件吗?

MIPS 管道停顿 : SW after LW

assembly - MIPS 数据指令

javascript - 如何在 JavaScript 中从数组的每个数组中返回两个最大的数字而不使用 for 循环?

vhdl - modelsim 说 : "near " )": (vcom-1576) expecting IDENTIFIER." while compiling

c++ - MIPS 汇编中的 C 数组索引?