-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGforce_cputest.v
More file actions
103 lines (78 loc) · 1.92 KB
/
Copy pathGforce_cputest.v
File metadata and controls
103 lines (78 loc) · 1.92 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
G-Force CPU Test Bench
Test bench will operate the following C statement: d = a+b-c
where a,b,c are in memory and the result d will be stored in memory.
*/
module CPU_tb();
reg Reset, Clock, Newinstr;
reg [31:0] Instrword;
mipscpu mycpu(
Reset,
Clock,
Instrword,
Newinstr);
//Initialize inputs and memory
initial
begin
Reset = 0;
Clock = 0;
Instrword = 0;
Newinstr = 0;
mycpu.memcpu.mem_file[0] = 10;//a
mycpu.memcpu.mem_file[1] = 22;//b
mycpu.memcpu.mem_file[2] = 6;//c
end
//Initialize the Clock
always #1 Clock = ~Clock;
initial
begin
// lw $1,0($0)
Instrword = 32'b10001100000000010000000000000000;
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Register 1: %d",mycpu.registerfilecpu.regfile[1]);
// lw $2,1($0)
Instrword = 32'b10001100000000100000000000000001; //load b to r2 32,0,1,1
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Register 2: %d",mycpu.registerfilecpu.regfile[2]);
// lw $3,2($0)
Instrword = 32'b10001100000000110000000000000010;//load c to r3 32,0,2,2
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Register 3: %d",mycpu.registerfilecpu.regfile[3]);
// add $4,$1,$2
Instrword = 32'b00000000001000100010000000100000; //Instructions for r1+r3 = R4
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Register 4: %d",mycpu.registerfilecpu.regfile[4]);
// sub $5,$4,$3
Instrword = 32'b00000000100000110010100000100010; //Instructions for r4-r2=r5
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Register 5: %d",mycpu.registerfilecpu.regfile[5]); //
// sw $5,3($0)
#1Instrword = 32'b10101100000001010000000000000011; //Stores 26 to d in memort
Newinstr = 0;
#1 Newinstr = 1;
#1 Newinstr = 0;
#10;
$display("Memory value d: %d",mycpu.memcpu.mem_file[3]);
$finish;
end
initial
begin
$dumpfile("test.vcd");
$dumpvars(0,CPU_tb);
end
endmodule