0
0
Verilogprogramming~20 mins

Single-port RAM design in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Single-port RAM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this single-port RAM read operation?
Consider this Verilog code snippet for a single-port RAM. What value will be read on data_out after the clock edge if addr = 3 and the memory was initialized with mem[3] = 8'hA5?
Verilog
reg [7:0] mem [0:7];
reg [7:0] data_out;
reg [2:0] addr;

always @(posedge clk) begin
  data_out <= mem[addr];
end
Adata_out = 8'hA5
Bdata_out = 8'h00
Cdata_out = 8'hFF
Ddata_out = undefined (X)
Attempts:
2 left
💡 Hint
Remember that on the positive clock edge, the data at the address is loaded into data_out.
Predict Output
intermediate
2:00remaining
What is the value of mem[5] after this write operation?
Given this single-port RAM write code, what will be the value stored in mem[5] after the clock edge if addr = 5, data_in = 8'h3C, and we = 1?
Verilog
reg [7:0] mem [0:7];
reg [7:0] data_in;
reg [2:0] addr;
reg we;

always @(posedge clk) begin
  if (we) begin
    mem[addr] <= data_in;
  end
end
Amem[5] = 8'h3C
Bmem[5] = 8'h00
Cmem[5] = undefined (X)
Dmem[5] = previous value (unchanged)
Attempts:
2 left
💡 Hint
Write enable (we) controls whether the memory is updated on the clock edge.
🔧 Debug
advanced
2:30remaining
Why does this single-port RAM code cause a synthesis error?
Examine this single-port RAM code. Why will it cause a synthesis error or not work as intended?
Verilog
reg [7:0] mem [0:7];
reg [7:0] data_out;
reg [2:0] addr;
reg we;

always @(posedge clk) begin
  if (we) begin
    mem[addr] <= data_out;
  end else begin
    data_out <= mem[addr];
  end
end
ABecause mem is not declared as a wire
BBecause data_out is used as input for writing, causing read-write conflict on the same port
CBecause the clock signal is missing from sensitivity list
DBecause the address width is too small for the memory size
Attempts:
2 left
💡 Hint
Think about what happens when you try to read and write the same memory location on the same clock edge.
📝 Syntax
advanced
1:30remaining
Which option correctly declares a 16x8 single-port RAM in Verilog?
Select the correct Verilog declaration for a single-port RAM with 16 addresses and 8-bit data width.
Awire [7:0] mem [0:15];
Breg [15:0] mem [0:7];
Creg [7:0] mem [0:15];
Dreg mem [7:0] [0:15];
Attempts:
2 left
💡 Hint
Remember the syntax for declaring memory arrays in Verilog: data width first, then address range.
🚀 Application
expert
2:30remaining
How many clock cycles does it take for data_out to reflect a write at address 4?
In a synchronous single-port RAM design, if you write data to address 4 at clock cycle N, at which clock cycle will a read from address 4 return the new data on data_out?
AImmediately, combinationally without clock delay
BAt clock cycle N (same cycle as write)
CAt clock cycle N+2 (two cycles after write)
DAt clock cycle N+1 (one cycle after write)
Attempts:
2 left
💡 Hint
Think about synchronous RAM behavior and when data is updated and available on output.