「Verilog学习笔记」单端口RAM

专栏前言

本专栏的内容主要是记录本人学习Verilog过程中的一些知识点,刷题网站用的是牛客网

「Verilog学习笔记」单端口RAM_第1张图片

「Verilog学习笔记」单端口RAM_第2张图片

`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 [6:0] mem[127:0] ;
    integer i ;

    always @ (posedge clk or negedge rst) begin 
        if (~rst) 
            for (i = 0 ; i < 127 ; i = i + 1) 
                mem[i] <= 0 ;
        else if (enb) // 使能高电平写数据
            mem[addr] <= w_data ;  
    end

    assign r_data = (~enb) ? mem[addr] : 0 ; // 使能低电平读数据

//*************code***********//
endmodule

你可能感兴趣的:(Verilog学习笔记,学习,笔记,fpga开发,Verilog)