-
Notifications
You must be signed in to change notification settings - Fork 0
/
PC.v
executable file
·77 lines (70 loc) · 1.95 KB
/
PC.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module PC
#(parameter ADDR_WIDTH=32)
(
clock,
halt,
jump,
reset,
write_quantum,
quantum,
jump_address,
output_address,
program_ended
);
input wire clock;
input wire halt;
input wire jump;
input wire reset;
input wire write_quantum;
input wire [(ADDR_WIDTH - 1):0] quantum;
input wire [(ADDR_WIDTH - 1):0] jump_address;
output reg [(ADDR_WIDTH - 1):0] output_address;
output reg program_ended;
reg [(ADDR_WIDTH - 1):0] current_quantum;
reg [(ADDR_WIDTH - 1):0] max_quantum;
initial begin
program_ended <= 1'b0;
current_quantum <= 32'b0;
max_quantum <= 32'b0;
output_address <= 32'b0;
end
always @(posedge clock) begin
if (write_quantum) begin
max_quantum <= quantum;
end
end
always @(posedge clock) begin
if (reset == 1) begin
program_ended <= 1'b1;
current_quantum <= 32'b0;
output_address <= 32'b0;
end else if (halt == 1) begin
program_ended <= 1'b1;
current_quantum <= 32'b0;
output_address <= 32'b0;
end else if (max_quantum != 0 && current_quantum >= max_quantum) begin
// Estouro de quantum, voltar pro sistema operacional
program_ended <= 1'b0;
current_quantum <= 32'b0;
output_address <= 32'b0;
end else if (jump == 1) begin
program_ended <= 1'b0;
// Apenas executar se não estiver no sistema operacional
if (max_quantum != 0 && output_address >= 512) begin
current_quantum <= current_quantum + 1;
end else begin
current_quantum <= 32'b0;
end
output_address <= jump_address;
end else begin
program_ended <= 1'b0;
// Apenas executar se não estiver no sistema operacional
if (max_quantum != 0 && output_address >= 512) begin
current_quantum <= current_quantum + 1;
end else begin
current_quantum <= 32'b0;
end
output_address <= output_address + 1;
end
end
endmodule