Separate signals per port = input clk, input [7:0] addr_a, input [7:0] data_in_a, output [7:0] data_out_a, input we_a, input [7:0] addr_b, input [7:0] data_in_b, output [7:0] data_out_b, input we_b; [OK]
Hint: Dual-port RAM needs separate signals for each port [OK]
Common Mistakes:
Using single address and data signals for both ports
Missing write enable signals
Confusing read and write signals
3. Given the following Verilog snippet for a dual-port RAM, what will be the value of data_out_b after the clock edge if we_b is 0 and addr_b is 3?
reg [7:0] ram [0:7];
always @(posedge clk) begin
if (we_a) ram[addr_a] <= data_in_a;
if (we_b) ram[addr_b] <= data_in_b;
data_out_a <= ram[addr_a];
data_out_b <= ram[addr_b];
end
medium
A. The value of data_in_b.
B. The value stored at address 3 before the clock edge.
C. Zero, because we_b is 0.
D. Undefined, because data_out_b is not assigned.
Solution
Step 1: Understand write enable effect
Since we_b is 0, no write occurs at addr_b on this clock edge.
Step 2: Determine data_out_b value
data_out_b reads the RAM at addr_b, so it outputs the stored value at address 3 before the clock edge.
Final Answer:
The value stored at address 3 before the clock edge. -> Option B
Quick Check:
we_b=0 means no write; output = stored value [OK]
Hint: If write enable is 0, output shows stored memory value [OK]
Common Mistakes:
Assuming data_out_b equals data_in_b always
Thinking output is zero when no write
Ignoring read operation on clock edge
4. Identify the error in this dual-port RAM Verilog code snippet:
reg [7:0] ram [0:15];
always @(posedge clk) begin
if (we_a) ram[addr_a] <= data_in_a;
if (we_b) ram[addr_b] <= data_in_b;
data_out_a <= ram[addr_a];
data_out_b <= ram[addr_b];
end
assign data_out_a = ram[addr_a];
medium
A. Conflicting assignments to data_out_a: both procedural and continuous.
B. Missing clock signal in sensitivity list.
C. Incorrect RAM size declaration.
D. No write enable signals declared.
Solution
Step 1: Check assignments to data_out_a
Data_out_a is assigned inside the always block and also by continuous assign statement, causing conflict.
Step 2: Understand Verilog rules
A signal cannot be driven by both procedural and continuous assignments simultaneously.
Final Answer:
Conflicting assignments to data_out_a: both procedural and continuous. -> Option A
Quick Check:
Signal driven twice = conflict error [OK]
Hint: Avoid assigning same signal in always block and assign statement [OK]
Common Mistakes:
Ignoring multiple drivers on one signal
Thinking sensitivity list needs clock and addr
Misunderstanding RAM size syntax
5. You want to design a dual-port RAM where Port A is write-only and Port B is read-only. Which modification correctly implements this behavior in Verilog?
hard
A. Disable clock on Port B to make it read-only.
B. Use write enable on both ports and read data from both ports.
C. Use write enable only on Port A and never write on Port B; read data only from Port B.
D. Use a single write enable for both ports.
Solution
Step 1: Define port roles
Port A should only write data, so it needs a write enable and no read output.
Step 2: Configure Port B as read-only
Port B should not write, so write enable is never asserted; it only reads data from RAM.
Final Answer:
Use write enable only on Port A and never write on Port B; read data only from Port B. -> Option C
Quick Check:
Write-only Port A + Read-only Port B = Use write enable only on Port A and never write on Port B; read data only from Port B. [OK]
Hint: Assign write enable only to write port, read from the other [OK]
Common Mistakes:
Trying to write on both ports
Disabling clock to control read/write
Using single write enable for both ports
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.