-
Notifications
You must be signed in to change notification settings - Fork 0
/
IF.v
57 lines (47 loc) · 1009 Bytes
/
IF.v
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
`include "define.v"
module IF (
input wire clk_in,
input wire rst_in,
input wire blk_in,
input wire branch_we_in,
input wire [`InstAddr] branch_pc_in,
input wire [`InstData] mem_d_in,
output wire [`InstAddr] mem_a_out,
output wire [`InstAddr] pc_out,
output reg [`InstData] inst_out,
output reg rec_out,
output reg blk_out
);
reg [`InstAddr] q_pc, d_pc;
always @ (posedge clk_in or posedge rst_in) begin
if (rst_in) begin
q_pc <= `ZeroWord - 32'h4;
end else begin
q_pc <= d_pc;
end
end
always @ (*) begin
if (rst_in) begin
d_pc = `ZeroWord;
inst_out = `ZeroWord;
rec_out = 1'b0;
blk_out = blk_in;
end else begin
rec_out = 1'b1;
inst_out = mem_d_in;
if (branch_we_in) begin
d_pc = branch_pc_in;
blk_out = 1'b0;
end else begin
blk_out = blk_in;
if (blk_in) begin
d_pc = q_pc;
end else begin
d_pc = q_pc + 32'h4;
end
end
end
end
assign mem_a_out = d_pc;
assign pc_out = d_pc;
endmodule