The most common file operation is loading ROM/RAM contents:
$readmemh and $readmemb
module rom_tb;
reg [7:0] memory [0:255]; // 256 x 8-bit memory
initial begin
// Load hex file (each line = one memory word)
$readmemh("rom_data.hex", memory);
// Or binary file
$readmemb("rom_data.bin", memory);
// With start/end address
$readmemh("data.hex", memory, 0, 127); // Load to first half
end
endmodule
// Example rom_data.hex file:
// @00 // Optional: start address
// AB
// CD
// 12
// 34
File Format
Each line contains one value. Use @address to set load address. Comments use
//.