设计一个Verilog或VHDL模块,用于实现一个双端口的存储器模块。
双端口存储器模块设计
module dual_port_memory(
input wire clk, // 时钟信号
input wire reset, // 复位信号
input wire [7:0] addr1, // 端口1地址信号
input wire [7:0] addr2, // 端口2地址信号
input wire we1, // 端口1写使能信号
input wire we2, // 端口2写使能信号
input wire [7:0] data_in1, // 端口1输入数据
input wire [7:0] data_in2, // 端口2输入数据
output reg [7:0] data_out1, // 端口1输出数据
output reg [7:0] data_out2, // 端口2输出数据
// 双端口存储器数组
reg [7:0] dual_port_memory [0:255];
// 端口1读写操作
always @(posedge clk) begin
if (reset) begin
dual_port_memory[addr1] <= 8'b0;
end else begin
if (we1) begin
dual_port_memory[addr1] <= data_in1;
end else begin
data_out1 <= dual_port_memory[addr1];
end
end
end
// 端口2读写操作
always @(posedge clk) begin
if (reset) begin
dual_port_memory[addr2] <= 8'b0;
end else begin
if (we2) begin
dual_port_memory[addr2] <= data_in2;
end else begin
data_out2 <= dual_port_memory[addr2];
end
end
end
endmodule