题解 | #单端口RAM#
单端口RAM
https://www.nowcoder.com/practice/a1b0c13edba14a2984e7369d232d9793
reset时需要对128个地址都复位。
`timescale 1ns/1ns module RAM_1port( input clk, input rst, input enb, input [6:0]addr, input [3:0]w_data, output wire [3:0]r_data ); //*************code***********// parameter DEPTH = 1<<7; reg [3:0] mem [0:DEPTH-1]; integer i; always@(posedge clk or negedge rst) begin if(!rst) begin for(i=0;i<DEPTH;i=i+1) begin mem[i] <= 'd0; end end else begin mem[addr] <= enb?w_data:mem[addr]; end end assign r_data = enb?'d0:mem[addr]; //*************code***********// endmodule