-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.v
54 lines (48 loc) · 1.23 KB
/
memory.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 01:21:59 06/01/2015
// Design Name:
// Module Name: memory
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module memory(
input wire clk,
input wire RE,
input wire WE,
input wire [31:0] addr,
input wire [31:0] data_in,
output reg [31:0] data_out
);
parameter ADDR_WIDTH=6;
reg [7:0] mem [(1<<ADDR_WIDTH)-1:0];
initial begin
$readmemh("data.hex",mem);
data_out=32'b0;
end
always@(negedge clk) begin
if(WE&&~RE&&addr[31:ADDR_WIDTH]==0) begin
mem[addr[ADDR_WIDTH-1:0]+3]=data_in[31:24];
mem[addr[ADDR_WIDTH-1:0]+2]=data_in[23:16];
mem[addr[ADDR_WIDTH-1:0]+1]=data_in[15:8];
mem[addr[ADDR_WIDTH-1:0]+0]=data_in[7:0];
end
end
always@(negedge clk) begin
if(RE&&~WE&&addr[31:ADDR_WIDTH]==0) begin
data_out={mem[addr[ADDR_WIDTH-1:0]+3],mem[addr[ADDR_WIDTH-1:0]+2],mem[addr[ADDR_WIDTH-1:0]+1],mem[addr[ADDR_WIDTH-1:0]+0]};
end
end
endmodule