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三个寄存器的租号
你的curr是一个integer型,它的位宽与你的系统有关,32bit或者64bit,应该不能声明为一个3bit的变量吧,integer型变量也不能作为位向量来访问,也就是不能使用curr[0]、curr[1:3]....等,仅供参考
integer curr[2:0];