-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstructmem.sv
More file actions
87 lines (70 loc) · 2.8 KB
/
instructmem.sv
File metadata and controls
87 lines (70 loc) · 2.8 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
// Instruction ROM. Supports reads only, but is initialized based upon the file specified.
// All accesses are 32-bit. Addresses are byte-addresses, and must be word-aligned (bottom
// two words of the address must be 0).
//
// To change the file that is loaded, edit the filename here:
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test01_AddiB.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test02_AddsSubs.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test03_CbzB.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test04_LdurStur.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test05_Blt.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test06_MovkMovz.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test07_LdurbSturb.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test10_forwarding.arm"
//`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test11_Sort.arm"
`define BENCHMARK "D:/jara/course/Lab 4/benchmarks/test12_ToUpper.arm"
`timescale 1ns/10ps
// How many bytes are in our memory? Must be a power of two.
`define INSTRUCT_MEM_SIZE 1024
module instructmem (
input logic [63:0] address,
output logic [31:0] instruction,
input logic clk // Memory is combinational, but used for error-checking
);
// Force %t's to print in a nice format.
initial $timeformat(-9, 2, " ns", 10);
// Make sure size is a power of two and reasonable.
initial assert((`INSTRUCT_MEM_SIZE & (`INSTRUCT_MEM_SIZE-1)) == 0 && `INSTRUCT_MEM_SIZE > 4);
// Make sure accesses are reasonable.
always_ff @(posedge clk) begin
if (address !== 'x) begin // address or size could be all X's at startup, so ignore this case.
assert(address[1:0] == 0); // Makes sure address is aligned.
assert(address + 3 < `INSTRUCT_MEM_SIZE); // Make sure address in bounds.
end
end
// The data storage itself.
logic [31:0] mem [`INSTRUCT_MEM_SIZE/4-1:0];
// Load the program - change the filename to pick a different program.
initial begin
$readmemb(`BENCHMARK, mem);
$display("Running benchmark: ", `BENCHMARK);
end
// Handle the reads.
integer i;
always_comb begin
if (address + 3 >= `INSTRUCT_MEM_SIZE)
instruction = 'x;
else
instruction = mem[address/4];
end
endmodule
module instructmem_testbench ();
parameter ClockDelay = 5000;
logic [63:0] address;
logic clk;
logic [31:0] instruction;
instructmem dut (.address, .instruction, .clk);
initial begin // Set up the clock
clk <= 0;
forever #(ClockDelay/2) clk <= ~clk;
end
integer i;
initial begin
// Read every location, including just past the end of the memory.
for (i=0; i <= `INSTRUCT_MEM_SIZE; i = i + 4) begin
address <= i;
@(posedge clk);
end
$stop;
end
endmodule