不太建议使用该方法,建议还是直接使用IP核 reg [:] ROM [:] ; integer i;
initial begin
for (i=;i<=;i=i+) begin
ROM[i] <= {{'b0}};
end
end
同时可以考虑双端口ROM
module ram_2port
#(parameter DWIDTH=,
parameter AWIDTH=)
(input clka,
input ena,
input wea,
input [AWIDTH-:] addra,
input [DWIDTH-:] dia,
output reg [DWIDTH-:] doa = 'd0, input clkb,
input enb,
input web,
input [AWIDTH-:] addrb,
input [DWIDTH-:] dib,
output reg [DWIDTH-:] dob = 'd0); reg [DWIDTH-:] ram [(<<AWIDTH)-:]; /*
integer i;
initial begin
for (i=0;i<(1<<AWIDTH);i=i+1) begin
ram[i] <= {DWIDTH{1'b0}};
end
end
*/ always @(posedge clka) begin
if (ena)
begin
if (wea)
ram[addra] <= dia;
doa <= ram[addra];
end
end
always @(posedge clkb) begin
if (enb)
begin
if (web)
ram[addrb] <= dib;
dob <= ram[addrb];
end
end
endmodule // ram_2port