module memory( input clk, input [7:0]data_in, input [7:0]address, input write_en, input read_en, output reg[7:0]data_out ); reg[7:0]mem[0:255]; always@(posedge clk) begin if(write_en) mem[address]<=data_in; if(read_en) data_out<=mem[address]; end endmodule 的测试程序
时间: 2024-01-13 20:05:23 浏览: 100
好的,以下是一个简单的测试程序,它将数据写入RAM并从中读取数据:
```verilog
module memory_test;
reg clk;
reg [7:0] data_in;
reg [7:0] address;
reg write_en;
reg read_en;
wire [7:0] data_out;
memory mem(clk, data_in, address, write_en, read_en, data_out);
initial begin
clk = 0;
write_en = 0;
read_en = 0;
data_in = 0;
address = 0;
// Write data to memory
write_en = 1;
data_in = 8'hAA;
address = 8'h00;
#10;
write_en = 0;
// Read data from memory
read_en = 1;
address = 8'h00;
#10;
read_en = 0;
// Verify data
if (data_out == 8'hAA) begin
$display("Test passed!");
end else begin
$display("Test failed!");
end
$finish;
end
always #5 clk = ~clk;
endmodule
```
该测试程序使用了一个简单的测试向量。它先将数据0xAA写入地址0x00处,然后从该地址读取数据并验证是否正确。如果数据正确,则测试通过,否则测试失败。
在仿真中运行此测试程序,您应该能够看到“Test passed!”的输出,这意味着RAM模块可以正常读取和写入数据。
阅读全文