打开特定文件以便在内存上写入

时间:2016-03-10 05:13:24

标签: verilog

我写了这段代码来初始化我的记忆。当我以行为方式运行时,它表示它无法打开文件。

request.safe_location

1 个答案:

答案 0 :(得分:0)

module DataMemory(Address, WriteData, Clk, MemWrite, MemRead, ReadData); 

input [4:0] Address;   // Input Address 
input [7:0] WriteData; // Data that needs to be written into the address 
input Clk;
input MemWrite;         // Control signal for memory write 
input MemRead;          // Control signal for memory read 

output reg[7:0] ReadData; // Contents of memory location at Address

reg [7:0] Memory[0:31];    // size needs to be adjusted based on the size of the test_data.txt

always @(posedge Clk) begin      //Memory write
    if (MemWrite==1)
        Memory[Address] = WriteData;
end

always @(Address or MemRead) begin
    if (MemRead == 1)
        ReadData <= Memory[Address];    //Memory read
else
    ReadData <= 8'h00;
end 

initial begin
    $readmemh("C:/Users/Elnaz-laptop/Desktop/test_data.txt", Memory,0,31);
    // Notes: 
    // 1-make sure to adjust the "Memory" size based on your test input
    // 2-watch out for wild characters at the end of the last entry in your test file

end

endmodule