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
|
// nandgame "combined memory"
// contains registers A, D and *A result
// located in memory.
`timescale 1us/1us
`include "../my_mem.v"
module comb_mem #(
parameter DATA_WIDTH = 16
) (
// store to A register
input a_i,
// store to D register
input d_i,
// store to address in memory pointed to by A (currently)
input pa_i,
// value to store
input [(DATA_WIDTH-1):0] X,
// nandgame updates on falling edge
input wire cl,
output reg [(DATA_WIDTH-1):0] A_o,
output reg [(DATA_WIDTH-1):0] D_o,
output reg [(DATA_WIDTH-1):0] pA_o
);
wire inv_clk;
// my hw uses posedge, nandgame uses negedge.
assign inv_clk = ~cl;
my_mem #(
.DATA_WIDTH(DATA_WIDTH),
// limit memory
.DATA_DEPTH(1024)
) nand_memory (
.clk_i(inv_clk),
.write_en_i(pa_i),
.read_en_i(1'b1),
.r_read_addr(A_o),
.r_write_addr(A_o),
.data_o(pA_o),
.data_i(X)
);
initial begin
A_o = 0;
D_o = 0;
end
always @(negedge cl) begin
if (a_i)
A_o <= X;
if (d_i)
D_o <= X;
end
endmodule
|