我正在尝试通过Xinlix软件使用二维数组初始化内存。代码在语法上是正确的,但它的测试平台提供了意想不到的输出。
例如:
address 0:instruction=1081601; but required output=00108101
和
address 1:instruction=1048834; required output=00100102
有谁能告诉我我的代码有什么问题?
module Imem ( address, instruction);
input [31:0] address;
output reg [31:0] instruction;
reg [31:0]sra [0:256];integer i;
// I-mem is read in every cycle.
// A read signal could be added if necessary.
always @(address)
begin
sra[32'h00000000]=32'h00108101;
sra[32'h00000001]=32'h00100102;
sra[32'h00000002]=32'h34100020;
sra[32'h00000003]=32'h38100020;
sra[32'h00000004]=32'h00108105;
sra[32'h00000005]=32'h00108106;
sra[32'h00000006]=32'h00108147;
sra[32'h00000007]=32'h00100148;
sra[32'h00000008]=32'h0010810F;
sra[32'h00000009]=32'h00108109;
sra[32'h0000000A]=32'h0010014A;
sra[32'h0000000B]=32'h0010810B;
sra[32'h0000000C]=32'h8C105555;
sra[32'h0000000D]=32'hAC10AAAA;
sra[32'h0000000E]=32'h31555555;
sra[32'h0000000F]=32'h28A00000;
sra[32'h00000010]=32'h00000000;
sra[32'h00000011]=32'h00000000;
for(i=32'd18;i<=32'd256;i=i+1)
sra[i]=32'h00000000;
instruction=sra[address];
end
endmodule
我的测试平台是:
module instr_v_v;
// Inputs
reg [31:0] address;
// Outputs
wire [31:0] instruction;
// Instantiate the Unit Under Test (UUT)
Imem uut (
.address(address),
.instruction(instruction)
);
initial
begin
address=32'd0;
$display($time,"address=%h,instruction=%h",address,instruction);
// Initialize Inputs
// Wait 100 ns for global reset to finish
#10 address=32'd1;
#10 address=32'd2;
#10 address=32'd3;
#10 address=32'd4;
// Add stimulus here
end
endmodule
答案 0 :(得分:0)
看起来它工作正常,我将tb改为低于其后驱动每个地址,你等待1次单位显示该值。
这应该是输出
11address=00000000,instruction=00108101
22address=00000001,instruction=00100102
33address=00000002,instruction=34100020
44address=00000003,instruction=38100020
55address=00000004,instruction=00108105
initial
begin
#10 address=32'd0;
#1 $display($time,"address=%h,instruction=%h",address,instruction);
// Initialize Inputs
// Wait 100 ns for global reset to finish
#10 address=32'd1;
#1 $display($time,"address=%h,instruction=%h",address,instruction);
#10 address=32'd2;
#1 $display($time,"address=%h,instruction=%h",address,instruction);
#10 address=32'd3;
#1 $display($time,"address=%h,instruction=%h",address,instruction);
#10 address=32'd4;
#1 $display($time,"address=%h,instruction=%h",address,instruction);
// Add stimulus here
end