0
0
Verilogprogramming~20 mins

ROM (Read-Only Memory) in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Verilog ROM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this ROM read operation?
Given the following Verilog ROM module and testbench snippet, what value will be output on data_out when addr = 3'b010?
Verilog
module rom_example(input [2:0] addr, output reg [7:0] data_out);
  reg [7:0] rom [0:7];
  initial begin
    rom[0] = 8'hAA;
    rom[1] = 8'hBB;
    rom[2] = 8'hCC;
    rom[3] = 8'hDD;
    rom[4] = 8'hEE;
    rom[5] = 8'hFF;
    rom[6] = 8'h11;
    rom[7] = 8'h22;
  end
  always @(*) begin
    data_out = rom[addr];
  end
endmodule

// Testbench snippet
// addr = 3'b010;
// Expected data_out = ?
A8'hDD
B8'hBB
C8'hEE
D8'hCC
Attempts:
2 left
💡 Hint
Remember that the address 3'b010 corresponds to decimal 2, so the ROM output is the value stored at index 2.
🧠 Conceptual
intermediate
1:00remaining
Which statement about ROM initialization in Verilog is true?
Consider these statements about initializing ROM in Verilog. Which one is correct?
AROM contents can be initialized using an <code>initial</code> block with explicit assignments.
BROM contents must be loaded from an external file at runtime only.
CROM cannot be initialized in Verilog; it must be programmed after synthesis.
DROM contents are automatically zero unless explicitly written during simulation.
Attempts:
2 left
💡 Hint
Think about how Verilog simulation allows setting initial values for memory arrays.
🔧 Debug
advanced
1:30remaining
Why does this ROM code cause a synthesis error?
Examine this ROM code snippet. Why will it cause a synthesis error?
Verilog
module rom_bug(input clk, input [1:0] addr, output reg [3:0] data_out);
  reg [3:0] rom [0:3];
  always @(posedge clk) begin
    data_out <= rom[addr];
  end
endmodule
AThe ROM is not initialized, so synthesis tools cannot infer ROM contents.
BUsing <code>always @(posedge clk)</code> with a ROM array causes synthesis error because ROM is combinational.
CThe output <code>data_out</code> must be declared as wire, not reg.
DThe address width is too small for the ROM size.
Attempts:
2 left
💡 Hint
Think about how ROM is usually modeled in Verilog and how synchronous blocks affect synthesis.
📝 Syntax
advanced
1:00remaining
Which ROM declaration is syntactically correct in Verilog?
Select the correct way to declare a 16x8-bit ROM in Verilog.
Areg [7:0] rom [0:15];
Breg [15:0] rom [7:0];
Creg rom [7:0][7:0];
Dwire [7:0] rom [0:15];
Attempts:
2 left
💡 Hint
Remember the syntax for declaring memory arrays in Verilog: reg [width-1:0] name [0:size-1];
🚀 Application
expert
2:00remaining
How many clock cycles does it take to read data from this ROM?
Given this ROM module with synchronous read, how many clock cycles after addr changes will data_out reflect the new data?
Verilog
module rom_sync(input clk, input [3:0] addr, output reg [7:0] data_out);
  reg [7:0] rom [0:15];
  initial begin
    rom[0] = 8'h01; rom[1] = 8'h02; rom[2] = 8'h03; rom[3] = 8'h04;
    // ... initialize other locations
  end
  always @(posedge clk) begin
    data_out <= rom[addr];
  end
endmodule
ADepends on the synthesis tool
BTwo clock cycles
COne clock cycle
DZero clock cycles (immediate combinational output)
Attempts:
2 left
💡 Hint
Since the ROM read is inside a clocked block with non-blocking assignment, output updates on the next clock edge.