题解 | #单端口RAM#

单端口RAM

https://www.nowcoder.com/practice/a1b0c13edba14a2984e7369d232d9793

`timescale 1ns/1ns

module RAM_1port(
    input clk,
    input rst,
    input enb,
    input [6:0]addr,//深度 128
    input [3:0]w_data,
    output reg [3:0]r_data
);
//*************code***********//

//写入数据
reg [3:0] RAM[127:0] ;
always@(posedge clk) begin
    if(enb)
        RAM[addr] <= w_data ;
end

//读出数据  
always@(negedge clk) begin
    if(!rst)
        r_data <= 0 ;
    else if(!enb)
        r_data <= RAM[addr]  ;
    else 
        r_data <= r_data  ;
end
//*************code***********//
endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
01-01 11:31
字节 算法 38x15 +15W 大专
沉淀小子:每次看到这种侮辱价直接拒的装逼仔,就想你是不是秒接了然后在这里装逼,有啥侮辱的。你要真有钱,还需要打工?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务