Challenge - 5 Problems
Dual-Port RAM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Dual-Port RAM Write and Read
What is the output of the following Verilog testbench snippet that writes and reads from a dual-port RAM?
Verilog
module dual_port_ram( input wire clk, input wire we_a, we_b, input wire [3:0] addr_a, addr_b, input wire [7:0] din_a, din_b, output reg [7:0] dout_a, dout_b ); reg [7:0] ram [0:15]; always @(posedge clk) begin if (we_a) ram[addr_a] <= din_a; dout_a <= ram[addr_a]; end always @(posedge clk) begin if (we_b) ram[addr_b] <= din_b; dout_b <= ram[addr_b]; end endmodule module testbench; reg clk = 0; reg we_a, we_b; reg [3:0] addr_a, addr_b; reg [7:0] din_a, din_b; wire [7:0] dout_a, dout_b; dual_port_ram ram_inst(clk, we_a, we_b, addr_a, addr_b, din_a, din_b, dout_a, dout_b); always #5 clk = ~clk; initial begin we_a = 1; addr_a = 4'd3; din_a = 8'hAA; we_b = 1; addr_b = 4'd3; din_b = 8'h55; #10; we_a = 0; we_b = 0; #10; $display("dout_a = %h, dout_b = %h", dout_a, dout_b); $finish; end endmodule
Attempts:
2 left
💡 Hint
Remember that both ports write to the same address on the same clock edge. The order of writes affects the final stored value.
✗ Incorrect
Both ports write to address 3 on the same clock edge. Port B's write happens after Port A's in the code, so the final stored value is 0x55. Both dout_a and dout_b read the updated value 0x55 after the clock edge.
🧠 Conceptual
intermediate1:30remaining
Understanding Dual-Port RAM Read Behavior
In a synchronous dual-port RAM, if both ports read from the same address simultaneously without any write enable active, what will be the output on both ports?
Attempts:
2 left
💡 Hint
Think about how synchronous RAM reads work when no writes occur.
✗ Incorrect
When no write occurs, both ports read the stored data at the requested address. Since both read the same address, both outputs show the stored value.
🔧 Debug
advanced2:00remaining
Identify the Bug in Dual-Port RAM Write Logic
What is the main problem in this dual-port RAM write logic snippet?
always @(posedge clk) begin
if (we_a) ram[addr_a] <= din_a;
else if (we_b) ram[addr_b] <= din_b;
end
Attempts:
2 left
💡 Hint
Check how the if-else structure affects port B's write enable.
✗ Incorrect
The else if means port B's write only happens if port A's write enable is false. But if port A's write enable is true, port B's write is skipped. This structure prevents simultaneous writes and may block port B's write incorrectly.
📝 Syntax
advanced1:30remaining
Syntax Error in Dual-Port RAM Declaration
Which option contains the correct syntax to declare a 16x8-bit dual-port RAM array in Verilog?
Attempts:
2 left
💡 Hint
Remember the order: data width first, then address range.
✗ Incorrect
The correct syntax is reg [7:0] ram [0:15]; which means 16 locations (0 to 15) each 8 bits wide. Other options have incorrect dimension order or ranges.
🚀 Application
expert3:00remaining
Number of Unique Data Values Stored After Writes
Given a dual-port RAM with 16 addresses, initially all zero, the following writes occur simultaneously on the same clock edge:
- Port A writes 8'h1A to address 5
- Port B writes 8'h2B to address 7
- Port A writes 8'h3C to address 7
- Port B writes 8'h4D to address 5
Assuming the write order in code is Port A then Port B for each port's write, how many unique data values are stored in the RAM after this clock edge?
Attempts:
2 left
💡 Hint
Consider that writes to the same address overwrite each other in order.
✗ Incorrect
Port A writes 0x1A to addr 5, then Port B overwrites addr 5 with 0x4D. Similarly, Port A writes 0x3C to addr 7, then Port B overwrites addr 7 with 0x2B. So final values at addr 5 and 7 are 0x4D and 0x2B respectively. Only these two addresses changed, so 2 unique values stored.