-
Notifications
You must be signed in to change notification settings - Fork 0
/
DM.v
90 lines (82 loc) · 1.6 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10:33:30 11/09/2019
// Design Name:
// Module Name: DM
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module DM(
input Clk,
input reset,
input [31:0] Addr,
input [31:0] WD,
input RE,
input WE,
output reg [31:0] RD
);
//RAM
reg [31:0] DM [4095:0];
//Ƭ
wire[11:0] wordAddr = Addr[13:2]; // [1:0] decide byte
integer i;
// initialization
initial begin
for(i=0; i<4095; i=i+1)begin
DM[i] <= 0;
end
end
//
wire [31:0] Data_old; // Read data using wordAddr
assign Data_old = DM[wordAddr];
// read
wire [31:0] RD_New;
loadEx loadExtra(
datapath.IR_MEM,
Addr,
Data_old,
RD_New
);
always @(*)begin
if(RE)begin
RD = RD_New;
end else begin
RD = 0;
end
end
// save
//
wire [31:0]WD_new;
saveEx saveExtra(
datapath.IR_MEM,
Addr,
Data_old,
WD,
WD_new
);
always @(posedge Clk)begin
if(reset)begin:dmreset
integer i;
for(i=0;i<4095;i=i+1)begin
DM[i] <= 0;
end
end else if (WE)begin
$display("%d@%h: *%h <= %h", $time, (datapath.PC4_MEM-4), (Addr - Addr%4), WD_new);
DM[wordAddr] <= WD_new;
end else begin
DM[wordAddr] <= DM[wordAddr];
end
end
endmodule