-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonacci_calculator_project.sv
47 lines (40 loc) · 1.2 KB
/
fibonacci_calculator_project.sv
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
module fibonacci_calculator_project (input logic clk, reset_n,
input logic [4:0] input_s,
input logic begin_fibo,
output logic [15:0] fibo_out,
output logic done);
enum logic {IDLE=1'b0, COMPUTE=1'b1} state;
logic [4:0] count;
logic [15:0] R0, R1;
assign done = (count==1) ?1:0;
assign fibo_out = R0;
always_ff @(posedge clk, negedge reset_n)
begin
if (!reset_n) begin
state <= IDLE;
//done <= 0;
end else
case (state)
IDLE:
if (begin_fibo) begin
count <= input_s;
R0 <= 1;
R1 <= 0;
state <= COMPUTE;
end
COMPUTE:
if (count > 1) begin
count <= count - 1;
R0 <= R0 + R1;
R1 <= R0;
$display("state = %s, count = %3d, R0 = %4d, R1 = %4d", state, count, R0, R1);
end else begin
state <= IDLE;
//done <= 1;
//fibo_out <= R0;
end
endcase
end
//assign done = (state==IDLE);
//assign fibo_out = R0;
endmodule