RAM and ROM Verilog Code Examples
Advertisement
This page covers RAM Verilog code and ROM Verilog code. It also provides a link that compares RAM vs ROM.
RAM Verilog Code
Following is the figure and Verilog code of RAM (Random Access Memory).

module RAM_code(out, in, addr, RW, CS);
output [7:0] out;
input [7:0] in;
input [3:0] addr;
input RW, CS;
reg [7:0] out;
reg [7:0] DATA[15:0];
always @(negedge CS) begin
if(RW==1'b0) //READ
out=DATA[addr];
else if(RW==1'b1) //WRITE
DATA[addr]=in;
else
out=8'bz;
end
endmodule
ROM Verilog Code
Following is the figure and Verilog code of ROM (Read Only Memory).

module ROM_code(out, addr, CS);
output[15:0] out;
input[3:0] addr;
input CS;
reg [15:0] out;
reg [15:0] ROM[15:0];
always @(negedge CS) begin
ROM[0]=16'h5601;
ROM[1]=16'h3401;
ROM[2]=16'h1801;
ROM[3]=16'h0ac1;
ROM[4]=16'h0521;
ROM[5]=16'h0221;
ROM[6]=16'h5601;
ROM[7]=16'h5401;
ROM[8]=16'h4801;
ROM[9]=16'h3801;
ROM[10]=16'h3001;
ROM[11]=16'h2401;
ROM[12]=16'h1c01;
ROM[13]=16'h1601;
ROM[14]=16'h5601;
ROM[15]=16'h5401;
out=ROM[addr];
end
endmodule
Explore Verilog Logic Gates, Mux & Encoders
- Verilog HDL Code for All Logic Gates
- 2-to-4 Decoder (Verilog HDL Code)
- 4-to-1 Multiplexer and 1-to-4 Demultiplexer (Verilog Code)
- Verilog Code: 1-to-4 Demultiplexer
- 8-to-1 Multiplexer (Verilog HDL Code)
- 8-to-3 Encoder Without Priority (Verilog)
- 8-to-3 Priority Encoder (Verilog)
- 8-to-3 Priority Encoder (Verilog Code)
- 1-Bit and 4-Bit Comparator Design (Verilog)
Explore Verilog Flip-Flops, Counters & Registers
- T, D, SR, JK Flip Flop (Verilog HDL Code)
- D Flip Flop Synchronous Reset (Verilog)
- D Flip Flop Without Reset (Verilog)
- Verilog Code for Binary Up-Down Counter
- Verilog HDL: BCD & Gray Counters
- 4-bit Down Counter (Verilog Code Test Bench)
- 4-bit Binary Asynchronous Reset Counter (Verilog)
- 4-bit Binary Synchronous Reset Counter (Verilog)
- 4-bit BCD Asynchronous Reset Counter (Verilog)
- 4-bit BCD Synchronous Reset Counter (Verilog Code)
- 4-bit Mod-13 Counter (Verilog Code Test Bench)
- Shift Left / Shift Right Register (Verilog)
- Parallel Load Shift Left Register (Verilog Code)
- PRBS Generator (Verilog Code Test Bench)
Explore Verilog Math, Processing & Memory
- Full Adder (Verilog HDL Code)
- Verilog Code: Half Adder, Half Subtractor, Full Subtractor
- 32-Bit ALU (Verilog Code)
- RAM / ROM (Verilog Code)
- Asynchronous FIFO (Verilog Code Test Bench)
- Asynchronous FIFO Design (Verilog Code and Explanation)
- Mealy / Moore Machine (Verilog)
- Low Pass FIR Filter (Verilog Code)
- 4-bit Binary to Gray Counter Converter in Verilog
