R
rekz
Guest
I have a test_data.txt which has 276 lines of numbers in hex and I
want to be able to read it and initialize the Memory array using
readmemh.
So I did the following code and tried to pull out the values from the
Memory and only the first value, which is Memory[0] is there and the
rest is 0. How is this possible?
I made sure that my test_data.txt is formatted correctly. The Memory
has the same size as the number of lines in the test_data.txt, so it
should be fine.
Why is this?
module DataMemory(Address, WriteData, MemRead, MemWrite, Clk,
ReadData);
input[31:0] Address; //32-bit address to memory
input[31:0]WriteData; //Data to be written into WriteRegister
input MemRead; //Data in memory location Adress is read if this
control is set
input Clk;
input MemWrite; //WriteData is written in Address during positive
reg [31:0] ReadData;
output[31:0] ReadData;
reg[31:0] Memory [0:275];
//assign ReadData = (MemRead == 1) ? Memory[Address] : 32'h00000000;
always @(posedge Clk) //Memory write
begin
if (MemWrite==1)
Memory[Address] = WriteData;
end
always @(Address or MemRead)
begin
if (MemRead == 1)
ReadData <= Memory[Address]; //Memory read
else
ReadData <= 32'h00000000;
end
initial begin
$readmemh("test_data.txt", Memory);
end
endmodule
want to be able to read it and initialize the Memory array using
readmemh.
So I did the following code and tried to pull out the values from the
Memory and only the first value, which is Memory[0] is there and the
rest is 0. How is this possible?
I made sure that my test_data.txt is formatted correctly. The Memory
has the same size as the number of lines in the test_data.txt, so it
should be fine.
Why is this?
module DataMemory(Address, WriteData, MemRead, MemWrite, Clk,
ReadData);
input[31:0] Address; //32-bit address to memory
input[31:0]WriteData; //Data to be written into WriteRegister
input MemRead; //Data in memory location Adress is read if this
control is set
input Clk;
input MemWrite; //WriteData is written in Address during positive
reg [31:0] ReadData;
output[31:0] ReadData;
reg[31:0] Memory [0:275];
//assign ReadData = (MemRead == 1) ? Memory[Address] : 32'h00000000;
always @(posedge Clk) //Memory write
begin
if (MemWrite==1)
Memory[Address] = WriteData;
end
always @(Address or MemRead)
begin
if (MemRead == 1)
ReadData <= Memory[Address]; //Memory read
else
ReadData <= 32'h00000000;
end
initial begin
$readmemh("test_data.txt", Memory);
end
endmodule