编写RAM时哪个代码更好?
分配data_out内部always块:
module memory(
output reg [7:0] data_out,
input [7:0] address,
input [7:0] data_in,
input write_enable,
input clk
);
reg [7:0] memory [0:255];
always @(posedge clk) begin
if (write_enable) begin
memory[address] <= data_in;
end
data_out <= memory[address];
end
endmodule
Run Code Online (Sandbox Code Playgroud)data_out使用assign声明分配:
module memory(
output [7:0] data_out,
input [7:0] address,
input [7:0] data_in,
input write_enable,
input clk
);
reg [7:0] memory [0:255];
always @(posedge clk) begin
if (write_enable) begin
memory[address] <= data_in;
end
end
assign data_out = memory[address];
endmodule
Run Code Online (Sandbox Code Playgroud)有什么建议?
这取决于您的要求.
这会记录您的内存输出.如果你将它合成到门,那么你将有16个触发器,而不是情况2.这意味着你使用更多的区域.这也意味着您的输出相对于时钟的传播延迟比情况2少.此外,输出数据在下一个时钟周期之前不可用.
您的输出数据将在与写入时相同的时钟周期内可用,尽管相对于时钟的传播延迟较长.
您需要根据您的要求决定使用哪个.
第三种选择是使用生成的RAM,这是一个硬宏.与情况1和2相比,这应该具有面积,功率和可能的时序优势.