2018-06-05 23:42:20 -07:00
|
|
|
/**
|
|
|
|
* CPU-specific memory. raddr is used for reading,
|
|
|
|
* while wen (write enable), waddr, and in are used in combination to write.
|
|
|
|
* Reads are performed immediately, but writes are performed on
|
|
|
|
* positive clock edge. Reset clears the memory to 0.
|
|
|
|
*/
|
2018-06-05 00:06:45 -07:00
|
|
|
module memory #(width=32)
|
|
|
|
(input logic [7:0] raddr, waddr,
|
|
|
|
input logic [width-1:0] in,
|
|
|
|
input logic clk, wen, reset,
|
|
|
|
output logic [width-1:0] out);
|
|
|
|
logic [width-1:0] data [0:255];
|
|
|
|
always_ff@(posedge clk)
|
|
|
|
if(reset) begin
|
|
|
|
data <= '{default: 0};
|
|
|
|
end else begin
|
2018-06-05 23:42:20 -07:00
|
|
|
if(wen) begin
|
2018-06-05 22:56:46 -07:00
|
|
|
data[waddr] <= in;
|
|
|
|
end
|
2018-06-05 00:06:45 -07:00
|
|
|
end
|
2018-06-05 23:42:20 -07:00
|
|
|
|
2018-06-05 00:06:45 -07:00
|
|
|
assign out = data[raddr];
|
2018-06-05 23:42:20 -07:00
|
|
|
endmodule
|