Complete the code to declare a ROM module with input address and output data.
module rom(input [3:0] addr, output reg [7:0] data); always @(*) begin case([1]) 4'd0: data = 8'hA1; 4'd1: data = 8'hB2; default: data = 8'h00; endcase end endmodule
The case statement uses the input address addr to select the ROM data.
Complete the code to initialize the ROM contents using a Verilog array.
reg [7:0] rom_mem [0:15]; initial begin rom_mem[0] = 8'h1A; rom_mem[1] = 8'h2B; rom_mem[2] = 8'h3C; rom_mem[3] = 8'h4D; // ... other initializations end always @(*) begin data = [1]; end
The output data is assigned from the ROM memory at the given address addr.
Fix the error in the ROM read logic to correctly assign data asynchronously.
always @([1]) begin
data = rom_mem[addr];
endThe ROM output should update whenever the address changes, so the sensitivity list must include addr.
Fill both blanks to create a ROM module with parameterized data width and depth.
module rom #(parameter WIDTH = [1], DEPTH = [2]) ( input [$clog2(DEPTH)-1:0] addr, output reg [WIDTH-1:0] data ); reg [WIDTH-1:0] mem [0:DEPTH-1]; always @(*) begin data = mem[addr]; end endmodule
The data width is set to 8 bits and the depth to 256 locations, common ROM sizes.
Fill all three blanks to implement a ROM with synchronous read using a clock.
module rom_sync( input clk, input [3:0] addr, output reg [7:0] data ); reg [7:0] mem [0:15]; always @(posedge [1]) begin data <= mem[[2]]; end endmodule
The synchronous ROM reads data on the rising edge of the clock clk, using the address addr to index memory.