This repository was archived by the owner on Jun 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.v
More file actions
83 lines (67 loc) · 1.49 KB
/
Memory.v
File metadata and controls
83 lines (67 loc) · 1.49 KB
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 18:28:38 06/13/2024
// Design Name:
// Module Name: Memory
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Memory
#(
WORD_WIDTH = 8,
ADDRESS_WIDTH = 5
)
(
input CLK,
input read, write,
input Ain, Din, Dout,
input [ADDRESS_WIDTH-1:0] Abus,
inout [WORD_WIDTH-1:0] Dbus,
output reg [ADDRESS_WIDTH-1:0] A = {ADDRESS_WIDTH {1'b0}},
output reg [WORD_WIDTH-1:0] S = {WORD_WIDTH {1'b0}}
);
reg [WORD_WIDTH-1:0] mem [(2**ADDRESS_WIDTH)-1:0];
//initial mem = {(WORD_WIDTH * (2**ADDRESS_WIDTH)) {1'b0}};
integer i;
initial begin
// for(i = 0; i < (2**ADDRESS_WIDTH); i = i+1) begin
// mem[i] = {WORD_WIDTH {1'b0}};
// end
`define RAM_MEMORY mem
`include "meminit_ram.v"
//$readmemb("ram.mem", mem);
end
wire [WORD_WIDTH-1:0] S_safe;
assign S_safe = read ? mem[A] : S;
assign Dbus = Dout ? S_safe : {WORD_WIDTH {1'bZ}};
always @(posedge CLK)
begin
if(Ain) A <= Abus;
if(Din) S <= Dbus;
if(read) S <= mem[A];
if(write) mem[A] <= S;
// if(CLK)
// begin
// if(Ain) A <= Abus;
// if(Din) S <= Dbus;
//
// if(write) mem[A] <= S;
// end
// else
// S <= mem[A];
//
end
//always @(read) S <= mem[A];
endmodule