forked from jmahler/mips-cpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dm.v
41 lines (34 loc) · 912 Bytes
/
dm.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Data Memory.
*
* 32-bit data with a 7 bit address (128 entries).
*
* The read and write operations operate somewhat independently.
*
* Any time the read signal (rd) is high the data stored at the
* given address (addr) will be placed on 'rdata'.
*
* Any time the write signal (wr) is high the data on 'wdata' will
* be stored at the given address (addr).
*
* If a simultaneous read/write is performed the data written
* can be immediately read out.
*/
`ifndef _dm
`define _dm
module dm(
input wire clk,
input wire [6:0] addr,
input wire rd, wr,
input wire [31:0] wdata,
output wire [31:0] rdata);
reg [31:0] mem [0:127]; // 32-bit memory with 128 entries
always @(posedge clk) begin
if (wr) begin
mem[addr] <= wdata;
end
end
assign rdata = wr ? wdata : mem[addr][31:0];
// During a write, avoid the one cycle delay by reading from 'wdata'
endmodule
`endif