Write the Fibonacci Sequence using Verilog HDL:
module fib(input clock, input rst, input [5:0] n, output reg ready, output [31:0] value)reg [31:0] previous, current;reg [5:0] counter;// Reset the circuitalways @(posedge clk)if(rst) beginprevious <= 32'd0;current <= 32'd1;counter <= 32'd0;end// Compute next Fibonacci numberalways @(posedge clock)begin// Increment current indexcounter <= counter + 1;// Efficient adders are automatically inferredcurrent <= current + previous;previous <= current;if (counter == n)ready <= 1;end// Read the value of the nth fibonacci number from the internal registerassign value = current;endmodule
No comments:
Post a Comment