-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdm.v
56 lines (48 loc) · 1.38 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
`define BigEndianCPU 1
module dm_4k (addr, din, byteExt, wEn, clk, dout);
input [11:0] addr;
input [31:0] din;
input [1:0] byteExt;
input [1:0] wEn;
input clk;
output reg [31:0] dout;
reg [31:0] dm [1023:0];// 32-bit*1024;
wire [1:0] byteSel;
wire [9:0] gpAddr;
reg [7:0] byteIn;
reg [31:0] tmpReg;
assign byteSel = addr[1:0] ^ 2'b11;// Big endian.
assign gpAddr = addr[11:2];
always @ ( * ) begin
if (byteExt == 2'b01 || byteExt == 2'b00) begin// Load byte.
case (byteSel)
2'b00: byteIn <= dm[gpAddr][7:0];
2'b01: byteIn <= dm[gpAddr][15:8];
2'b10: byteIn <= dm[gpAddr][23:16];
2'b11: byteIn <= dm[gpAddr][31:24];
endcase
case (byteExt)// Embedded extender.
2'b00: dout <= {{24{1'b0}}, byteIn};// Logical Cal;
2'b01: dout <= {{24{byteIn[7]}}, byteIn};// Arithmetic Cal;
endcase
end else begin
dout = dm[gpAddr][31:0];// Load word.
end
end
always @ ( posedge clk ) begin// Write;
if (wEn == 2'b01) begin
if (byteExt == 2'b10) begin// Store byte.
tmpReg = dm[gpAddr][31:0];
case (byteSel)
2'b00: tmpReg[7:0] = din[7:0];
2'b01: tmpReg[15:8] = din[7:0];
2'b10: tmpReg[23:16] = din[7:0];
2'b11: tmpReg[31:24] = din[7:0];
endcase
dm[gpAddr][31:0] = tmpReg[31:0];
end else begin// Store word.
dm[gpAddr][31:0] = din[31:0];
end
end
end
endmodule // 4K Data Memeory;