题解 | #单端口RAM#
单端口RAM
https://www.nowcoder.com/practice/a1b0c13edba14a2984e7369d232d9793
为啥答案是在下降沿的时候读出数据啊???
`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***********// reg [3:0] rdata_reg; reg [3:0] ram [0:127]; always@(posedge clk or negedge rst) begin if(!rst) begin rdata_reg <= 'd0; end else begin rdata_reg <= enb?'d0:ram[addr]; end end integer i; always@(posedge clk or negedge rst) begin if(!rst) begin for(i=0;i<=127;i=i+1) begin ram[i] <= 'd0; end end else begin ram[addr] <= enb?w_data:ram[addr]; end end assign r_data = rdata_reg; //*************code***********// endmodule