问题遇到的现象和发生背景
Verilog使用变量索引
问题相关代码
`timescale 1ns / 1ps
module testbench(
input [15:0]Opcode,
output reg[15:0] rt,
output reg[15:0] psw
);
reg [3:0] order;
reg [15:0] str_1[15:0];
reg [15:0] str_2[15:0];
reg [15:0] td[15:0];
integer curr[2:0];
alu test (
.Opcode(Opcode[15:12]),
.alu_src1(str_1[curr[2]]),
.alu_src2(str_2[curr[1]]),
.PSW(PSW),
.td(td[curr[0]])
);
// Initialize Inputs
always@(*)
begin
curr[2] = Opcode[11:8];
curr[1] = Opcode[7:4];
curr[0] = Opcode[3:0];
str_1[(curr[1])] = $random;
str_2[(curr[0])] = $random;
td[(curr[2])] = $random;
end
// Wait 100 ns for global reset to finish
endmodule
运行结果及报错内容
[VRFC 10-2951] 'curr' is not a constant
我的解答思路和尝试过的方法
我希望通过指令中的地址进行索引,但由于没学过该语言,当C来写 的……
显示我的索引非常量,不知道如何需求
我想要达到的结果
通过Opcode[11:0]中每4位产生一个索引值(地址)索引rt,str_1和str_2三个寄存器的租号