题解 | #单端口RAM#
单端口RAM
https://www.nowcoder.com/practice/a1b0c13edba14a2984e7369d232d9793
//深度是128 ram【127:0】 adder【$clog(depth)] //有一个复位时候,必须吧ram每一位都置0 integer i; always@(posedge clk or negedge rst) begin if(!rst) begin for(i=0;i<128;i=i+1) begin num[i]<=0; end `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=128,width=4; reg [3:0]num[0:127]; reg [3:0]data; integer i; always@(posedge clk or negedge rst) begin if(!rst) begin for(i=0;i<128;i=i+1) begin num[i]<=0; end end else if(enb) num[addr]<=w_data; end assign r_data=enb?0:num[addr]; //*************code***********// endmodule