Consider the following Verilog code for a synchronous RAM read. What is the output value of data_out after the rising edge of clk when addr is 2?
module sync_ram(input clk, input [1:0] addr, output reg [7:0] data_out); reg [7:0] mem [0:3]; initial begin mem[0] = 8'hAA; mem[1] = 8'hBB; mem[2] = 8'hCC; mem[3] = 8'hDD; end always @(posedge clk) begin data_out <= mem[addr]; end endmodule
Think about when the data is updated in synchronous logic.
In synchronous RAM, the output data_out updates only on the rising edge of the clock. So when addr changes, data_out does not change immediately but updates after the next clock edge.
Given the following Verilog code for an asynchronous RAM read, what is the value of data_out when addr changes to 3?
module async_ram(input [1:0] addr, output [7:0] data_out); reg [7:0] mem [0:3]; initial begin mem[0] = 8'h11; mem[1] = 8'h22; mem[2] = 8'h33; mem[3] = 8'h44; end assign data_out = mem[addr]; endmodule
Asynchronous read means output changes immediately with address.
In asynchronous RAM, the output data_out changes immediately when the address changes, without waiting for a clock edge.
Which statement correctly describes the timing difference between synchronous and asynchronous RAM reads?
Think about when the output changes relative to the clock and address.
Synchronous read waits for the clock edge to update output, while asynchronous read updates output immediately when the address changes.
What error will this Verilog code produce?
module mixed_ram(input clk, input [1:0] addr, output reg [7:0] data_out);
reg [7:0] mem [0:3];
initial begin
mem[0] = 8'h01;
mem[1] = 8'h02;
mem[2] = 8'h03;
mem[3] = 8'h04;
end
always @(posedge clk) begin
data_out <= mem[addr];
end
assign data_out = mem[addr];
endmoduleCheck how data_out is assigned in both procedural and continuous assignments.
The code tries to assign data_out both inside an always block and with a continuous assign, causing multiple drivers error.
You need to design a memory module for a system that requires the fastest possible read access without waiting for a clock edge. Which read type should you choose and why?
Consider which read type updates output fastest after address changes.
Asynchronous read outputs data immediately when the address changes, providing the lowest latency. Synchronous read waits for clock edges, adding delay.