0
0
Verilogprogramming~10 mins

ROM (Read-Only Memory) in Verilog - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - ROM (Read-Only Memory) in Verilog
Start
Address Input
ROM Lookup
Output Data
End
The ROM takes an address input, looks up the stored data at that address, and outputs the data without changing it.
Execution Sample
Verilog
module rom_example(
  input [1:0] addr,
  output reg [3:0] data
);
  always @(*) begin
    case(addr)
      2'b00: data = 4'hA;
      2'b01: data = 4'h3;
      2'b10: data = 4'hF;
      2'b11: data = 4'h0;
      default: data = 4'h0;
    endcase
  end
endmodule
This ROM module outputs a 4-bit value based on a 2-bit address input using a case statement.
Execution Table
StepInput addrCondition checkedData assignedOutput data
12'b00addr == 2'b004'hA1010
22'b01addr == 2'b014'h30011
32'b10addr == 2'b104'hF1111
42'b11addr == 2'b114'h00000
52'b00addr == 2'b004'hA1010
💡 ROM outputs data based on address; no state changes or loops, so execution ends after output.
Variable Tracker
VariableStartStep 1Step 2Step 3Step 4Step 5
addrundefined2'b002'b012'b102'b112'b00
dataundefined4'hA4'h34'hF4'h04'hA
Key Moments - 2 Insights
Why does the ROM output change immediately when the address changes?
Because the ROM uses a combinational always block (@(*)). It updates output 'data' instantly when 'addr' changes, as shown in execution_table steps 1 to 5.
Is the ROM storing data that can be changed during simulation?
No. The ROM data is fixed in the case statement and does not change during simulation, which is why 'data' only depends on 'addr' input.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output data when addr is 2'b10?
A4'h3
B4'h0
C4'hF
D4'hA
💡 Hint
Check row 3 in execution_table where addr is 2'b10 and data assigned is 4'hF.
At which step does the ROM output data 4'h0?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at execution_table row 4 where data assigned is 4'h0.
If the address input changes to 2'b01, what will be the output data?
A4'h3
B4'hA
C4'hF
D4'h0
💡 Hint
Refer to variable_tracker and execution_table rows where addr is 2'b01.
Concept Snapshot
ROM in Verilog stores fixed data accessed by address.
Use combinational always block with case statement.
Input: address; Output: stored data.
Data does not change during simulation.
Outputs update immediately on address change.
Full Transcript
This visual trace shows how a ROM module in Verilog works. The ROM takes a 2-bit address input and outputs a 4-bit data value. The data is fixed and defined in a case statement inside a combinational always block. As the address changes, the output data updates immediately without any delay or state change. The execution table shows each address tested and the corresponding output data. The variable tracker records the address and data values at each step. Key moments clarify why the output changes instantly and why ROM data is read-only. The quiz questions help check understanding of output values for given addresses. This trace helps beginners see how ROM lookup works step-by-step in Verilog.