-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstruction_fetch.v
More file actions
65 lines (58 loc) · 1.76 KB
/
instruction_fetch.v
File metadata and controls
65 lines (58 loc) · 1.76 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
/*
* Kelvin Lin, Nate Park
* Computer Architecture I
* Winter 2019
*
* Implements instruction fetch operation
*/
module instruction_fetch
(
input wire clk, resetn,
input wire [31:0] pc, // Program counter
output reg [code_width - 1:0] code_mem_rd
);
parameter code_width = 32; // Instruction Width
parameter code_words = 512; // Instruction Depth
parameter code_addr_width = 9;
reg [code_width - 1:0] code_mem[code_words - 1:0]; // Define instruction storage structure
wire [code_addr_width - 1: 0] code_addr;
// wire [7:0] instr_id;
// wire isbranch;
// wire [code_width - 1: 0] offset;
// reg [29:0] pc; // 30 bits for program counter
initial begin
// Use one of these two
// $readmemb("./bin/load_store_conflict_bypass.mem", code_mem);
$readmemb("./bin/lotsa_instructions.mem", code_mem);
end
/*
*31| 28|27 20|19 0|
* | cond | operation | |
*/
// Assign address into code
assign code_addr = pc[code_addr_width + 1:2];
// assign isbranch = (code_mem[code_addr][20:27] == 4'h_a) ? 1 : 0;
// // SignExtend(Adr24:'00', 32)
// assign offset = (isbranch) ? {{8{code_mem[code_addr][23]}}, code_mem[code_addr][0:23]}: 1;
// always @(negedge clk) begin
// code_mem_rd <= code_mem[code_addr];
// end
// always @(pc) begin
// code_mem_rd = code_mem[code_addr];
// end
always @(posedge clk) begin
if (!resetn)
code_mem_rd <= 32'hFF_FF_FF_FF;
else
code_mem_rd <= code_mem[code_addr];
end
// always @(posedge clk) begin
// if (!resetn) begin
// pc <= 0;
// end else if (pc >= code_words || pc < 0) begin // PC limit
// pc <= 0;
// end else begin
// pc <= pc + offset;
// end
// end
endmodule