2018-01-26 13:21:05 +00:00
|
|
|
module ram(
|
|
|
|
input clk,
|
2018-01-27 11:13:52 +00:00
|
|
|
input reset,
|
2018-01-26 13:21:05 +00:00
|
|
|
input [12:0] address,
|
|
|
|
input w_en,
|
|
|
|
input [7:0] din,
|
|
|
|
output reg [7:0] dout
|
|
|
|
);
|
|
|
|
|
2018-01-27 03:27:10 +00:00
|
|
|
parameter RAM_FILENAME = "../roms/ram.hex";
|
|
|
|
|
2018-01-26 13:21:05 +00:00
|
|
|
reg [7:0] ram[0:8191];
|
|
|
|
|
|
|
|
initial
|
2018-01-27 03:27:10 +00:00
|
|
|
$readmemh(RAM_FILENAME, ram, 0, 8191);
|
2018-01-26 13:21:05 +00:00
|
|
|
|
|
|
|
always @(posedge clk)
|
|
|
|
begin
|
2018-01-27 11:13:52 +00:00
|
|
|
dout <= reset ? 8'h0 : ram[address];
|
|
|
|
if (w_en && ~reset) ram[address] <= din;
|
2018-01-26 13:21:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|