Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with this question on verilog A Fibonacci like series can be computed with: def fib_like_3( n ): if n == 0 : return
Need help with this question on verilog
A Fibonacci like series can be computed with:
def fib_like_3( n ): if n == 0 : return 0 if n == 1 : return 1 if n == 2 : return 1 fib_n_1 = 1 fib_n_2 = 1 fib_n_3 = 0 for _ in range(n-2): fib_n_1, fib_n_2, fib_n_3 = \ fib_n_1 + fib_n_2 + fib_n_3, fib_n_1, fib_n_2 return fib_n_1
now using that as an example Modify fib.v to compute fib_like_3.
//fib.v starts here
`timescale 1ns / 1ns module dff( q, d, reset, clk ); parameter N=8; // size of register parameter reset_v = 0; // reset value output reg [N-1:0] q; input reset, clk; input [N-1:0] d; always @(posedge clk) begin q <= reset ? reset_v : d; end endmodule // compute fib(n) = fib(n-1) + fib(n-2) // where fib(0) = 0, fib(1) = 1 module fib( fib_n, reset, clk ); parameter N=8; output [N-1:0] fib_n; input reset, clk; wire [N-1:0] fib_n_2, fib_n_1, sum; dff #(N,0) f1( fib_n_2, fib_n_1, reset, clk ); dff #(N,1) f0( fib_n_1, fib_n, reset, clk ); assign fib_n = fib_n_1 + fib_n_2; endmodule module main; localparam N = 16; wire [N-1:0] fib_n; reg reset=1, clk=0; always #1 clk = ~clk; fib #(N) test( fib_n, reset, clk ); initial begin $dumpfile ("fib.vcd"); $dumpvars(0, main); $monitor("t=%3d reset=%b f[n-2]=%4d fib[n-1]=%4d fib=%5d", $time, reset, test.fib_n_2, test.fib_n_1, fib_n ); #4; reset = 0; #20 $finish; end endmodule
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started