-
Notifications
You must be signed in to change notification settings - Fork 30
/
datamemory.sv
57 lines (51 loc) · 1.3 KB
/
datamemory.sv
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
`timescale 1ns / 1ps
module datamemory #(
parameter DM_ADDRESS = 9,
parameter DATA_W = 32
) (
input logic clk,
input logic MemRead, // comes from control unit
input logic MemWrite, // Comes from control unit
input logic [DM_ADDRESS - 1:0] a, // Read / Write address - 9 LSB bits of the ALU output
input logic [DATA_W - 1:0] wd, // Write Data
input logic [2:0] Funct3, // bits 12 to 14 of the instruction
output logic [DATA_W - 1:0] rd // Read Data
);
logic [31:0] raddress;
logic [31:0] waddress;
logic [31:0] Datain;
logic [31:0] Dataout;
logic [ 3:0] Wr;
Memoria32Data mem32 (
.raddress(raddress),
.waddress(waddress),
.Clk(~clk),
.Datain(Datain),
.Dataout(Dataout),
.Wr(Wr)
);
always_ff @(*) begin
raddress = {{22{1'b0}}, a[8:2], {2{1'b0}}};
waddress = {{22{1'b0}}, a[8:2], {2{1'b0}}};
Datain = wd;
Wr = 4'b0000;
if (MemRead) begin
case (Funct3)
3'b010: //LW
rd <= Dataout;
default: rd <= Dataout;
endcase
end else if (MemWrite) begin
case (Funct3)
3'b010: begin //SW
Wr <= 4'b1111;
Datain <= wd;
end
default: begin
Wr <= 4'b1111;
Datain <= wd;
end
endcase
end
end
endmodule