aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hdl/verilog/reg_mem.v
blob: a8d37cdd78b35650ca5718a42d481602b06d1293 (plain) (blame)
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
`timescale 1ns / 1ps

module reg_mem(
    input [9:0] addr,
    input clk,
    input [31:0] din,
    output [31:0] dout,
    input en,
    input we
    );
    
    reg [31:0] mem [1023:0];
    
    integer i;
    initial
    begin
        for(i=0; i<1024; i=i+1)
            mem[i]=0;
    end
        
    reg [31:0] out;
        
    assign dout=out;    
        
    always @(posedge clk)
    begin
        if(we)
            mem[addr]<=din;
        else if(en)
            out<=mem[addr];
    end
            
endmodule