-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstruction_Fetch.v
More file actions
63 lines (53 loc) · 1.68 KB
/
Instruction_Fetch.v
File metadata and controls
63 lines (53 loc) · 1.68 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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20.07.2024 10:25:40
// Design Name:
// Module Name: Instruction_Fetch
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Instruction_Fetch (
input [31:0] PC,
input Clk,
input Reset,
input IsBranchTaken,
input [31:0] BranchPC,
output reg [31:0] pc_current,
output [31:0] Instruction
);
reg [31:0] instruction_memory [0:255]; // Assuming 256 words of instruction memory for simplicity
// Initialize instruction memory for simulation (can be replaced with actual memory initialization)
initial begin
// Example initialization
instruction_memory[0]=0;
instruction_memory[1] = 32'h4c400002; // mov R1,2
instruction_memory[2] = 32'h4c800006; // mov R2,6
instruction_memory[3] = 32'h0C480003; // sub R1,R2,3
// similarly instruction_memory can be initialized as per our codes
end
// Fetch instruction from instruction memory
assign Instruction = instruction_memory[pc_current];
// Always block to update PC on negative edge of clock or reset
always @(negedge Clk ) begin
if (Reset) begin
pc_current <= 32'b0; // Reset PC to 0
end else begin
if (IsBranchTaken)
pc_current <= BranchPC;
else
pc_current <= pc_current + 1; // Actual pc_current must be pc_current+4 (for the sake of simplicity I have taken it to be 1)
end
end
endmodule