-
Notifications
You must be signed in to change notification settings - Fork 1
/
mem_test.v
86 lines (74 loc) · 2.32 KB
/
mem_test.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
`ifndef MIPS_H
`include "mips.h"
`endif
`include "memory/mem.v"
`include "memory/mem_stage.v"
`include "memory/mem_pipeline_register.v"
module mem_test;
reg clk=0, RegWriteE, MemtoRegE, MemWriteE = 0;
reg [31:0] ALUOutE, WriteDataE = 0;
reg [4:0] WriteRegE = 1;
wire [31:0] ALUOutM, WriteDataM;
wire [4:0] WriteRegM;
// mem_pipeline_register myMemPipeline(clk, RegWriteE, MemtoRegE, MemWriteE, ALUOutE, WriteDataE, WriteRegE,
// RegWriteM, MemtoRegM, MemWriteM, ALUOutM, WriteDataM, WriteRegM);
wire RegWriteM, MemtoRegM;
wire [31:0] RD;
mem_stage myMemStage(clk, RegWriteE, MemtoRegE, MemWriteE,
ALUOutE, WriteDataE, WriteRegE, RegWriteM, MemtoRegM, RD,
ALUOutM, WriteRegM);
initial begin
$dumpfile("mem_test.vcd");
$dumpvars(0, mem_test);
// Test read/write to data
MemWriteE = 1;
ALUOutE = 32'h000401;
WriteDataE = 32'h000001;
#1 clk = 1; #1 clk = 0;
#1 clk = 1; #1 clk = 0;
MemWriteE = 0;
#1 clk = 1; #1 clk = 0;
#1 clk = 1; #1 clk = 0;
if (RD == 32'h000001) begin
$display("Success: Read written data from data segment");
end else begin
$display("Failure: Data Segment @%h: %h", ALUOutE, RD);
end
// Test read/write to stack
MemWriteE = 1;
ALUOutE = 32'h7FFBFC;
WriteDataE = 32'h000001;
#1 clk = 1; #1 clk = 0;
MemWriteE = 0;
#1 clk = 1; #1 clk = 0;
#1 clk = 1; #1 clk = 0;
if (RD == 32'h000001) begin
$display("Success: Read written data from stack segment");
end else begin
$display("Failure: Stack Segment @%h: %h", ALUOutE, RD);
end
// Test read/write to text
MemWriteE = 1;
ALUOutE = 32'h000000;
WriteDataE = 32'h000001;
#1 clk = 1; #1 clk = 0;
MemWriteE = 0;
#1 clk = 1; #1 clk = 0;
#1 clk = 1; #1 clk = 0;
if (RD == 32'h000001) begin
$display("Success: Read written data from text segment");
end else begin
$display("Failure: Text Segment @%h: %h", ALUOutE, RD);
end
// Test read/write to unallocated (shoud print 2 errors)
ALUOutE = 32'h000402;
MemtoRegE = 0;
#1 clk = 1; #1 clk = 0;
#1 clk = 1; #1 clk = 0;
if (RD === `undefined) begin
$display("Success: Read undefined from unallocated segment");
end else begin
$display("Failure: Unallocated Memory @%h: %h", ALUOutE, RD);
end
end
endmodule