-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSU.v
107 lines (96 loc) · 2.57 KB
/
LSU.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module LSU #(parameter WIDTH = 32)(Address,Data,DatatoWrite,BHW,signFlag,MemWrite,ReadData,WriteData);
input [WIDTH-1:0] Address; // Input Address
input [WIDTH-1:0] Data;
input [WIDTH-1:0] DatatoWrite;
input [1:0] BHW;
input signFlag,MemWrite;
output reg[WIDTH-1:0] ReadData; // Contents of memory location at Address
output reg[WIDTH-1:0] WriteData;
wire [WIDTH-1:0]Data;
// Data_Memory b1(.in_Data(ReadData),.A(Address),.clk(clk),.WE(MemWrite),.o_Data(Data));
always @(*) //Memory write
begin
if (MemWrite==1) begin
case (BHW)
0: begin
case (Address[1:0])
0:
WriteData = {Data[31:8],DatatoWrite[7:0]};
1:
WriteData = {Data[31:16],DatatoWrite[7:0],Data[7:0]};
2:
WriteData = {Data[31:24],DatatoWrite[7:0],Data[15:0]};
3:
WriteData = {DatatoWrite[7:0],Data[23:0]};
endcase
end
1: begin
case (Address[1])
0:
WriteData = {Data[31:16],DatatoWrite[15:0]};
1:
WriteData = {DatatoWrite[15:0],Data[15:0]};
endcase
end
2: begin
WriteData = DatatoWrite;
end
endcase
// Memory[Address>>2] = Data;
end
else
begin
case (BHW)
0: begin // BYTE
case (Address[1:0]) // 31:24,23:16,15:8,7:0
0: begin
if (signFlag && Data[7])
ReadData <= {24'hffffff,Data[7:0]};
else
ReadData <= {24'b0,Data[7:0]};
end
1: begin
if (signFlag && Data[15])
ReadData <= {24'hffffff,Data[15:8]};
else
ReadData <= {24'b0,Data[15:8]};
end
2: begin
if (signFlag && Data[23])
ReadData <= {24'hffffff,Data[23:16]};
else
ReadData <= {24'b0,Data[23:16]};
end
3: begin
if (signFlag && Data[31])
ReadData <= {24'hffffff,Data[31:24]};
else
ReadData <= {24'b0,Data[31:24]};
end
endcase
end
1: begin // HALFWORD
case (Address[1])
0: begin
if (signFlag && Data[15])
ReadData <= {16'hffff,Data[15:0]};
else
ReadData <= {16'b0,Data[15:0]};
end
1: begin
if (signFlag && Data[31])
ReadData <= {16'hffff,Data[31:16]};
else
ReadData <= {16'b0,Data[31:16]};
end
endcase
end
2: begin // WORD
ReadData <= Data;
end
default:begin ReadData <= Data;
end
endcase
end
end
endmodule