-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU_Test.v
More file actions
68 lines (53 loc) · 1.62 KB
/
Copy pathCPU_Test.v
File metadata and controls
68 lines (53 loc) · 1.62 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
`default_nettype none
`include "Melcr_Josef_CPU.v"
module top ( input clk, reset,
output [31:0] data_to_mem, address_to_mem,
output write_enable);
wire [31:0] pc, instruction, data_from_mem;
inst_mem imem(pc[7:2], instruction);
data_mem dmem(clk, write_enable, address_to_mem, data_to_mem, data_from_mem);
processor CPU(clk, reset, pc, instruction, write_enable, address_to_mem, data_to_mem, data_from_mem);
endmodule
//-------------------------------------------------------------------
module data_mem (input clk, we,
input [31:0] address, wd,
output [31:0] rd);
reg [31:0] RAM[63:0];
initial begin
$readmemh ("memfile_data.hex",RAM,0,63);
end
assign rd=RAM[address[31:2]]; // word aligned
always @ (posedge clk)
if (we)
RAM[address[31:2]]<=wd;
endmodule
//-------------------------------------------------------------------
module inst_mem (input [5:0] address,
output [31:0] rd);
reg [31:0] RAM[63:0];
initial begin
$readmemh ("memfile_inst.hex",RAM,0,63);
end
assign rd=RAM[address]; // word aligned
endmodule
module testbench();
reg clk;
reg reset;
wire [31:0] data_to_mem, address_to_mem;
wire write_enable;
top simulated_system (clk, reset, data_to_mem, address_to_mem, write_enable);
initial begin
$dumpfile("test");
$dumpvars;
reset<=1; # 2; reset<=0;
#1000;
$writememh ("memfile_data_after_simulation.hex",simulated_system.dmem.RAM,0,63);
$writememh ("memfile_regs_after_simulation.hex",simulated_system.CPU.registers.rf,0,31);
$finish;
end
// generate clock
always begin
clk<=1; # 1; clk<=0; # 1;
end
endmodule
`default_nettype wire