mickraj122
mickraj122

Reputation: 1

with this Fibonacci sequence question with instruction sets used to make a assembly code

This is a Fibonacci sequence that I recently attempted to turn into a assembly code through the use of instruction set. I am not sure how to go about testing it and was wondering could confirm if I got this right and if not where I went wrong. Also the "." that is used does this mean I must multiply using the instruction set. Below is the question I got and my answer I have come up with. I would also like to know if I have used the correct #.

Upvotes: 0

Views: 223

Answers (1)

rcgldr
rcgldr

Reputation: 28826

The code needs to add (F(n-1) + F(n-2)) before multiplying F(n) · (F(n-1) + F(n-2)). Since F(n-2) doesn't need to be saved, you could add the register with F(n-1) to the register with F(n-2), so that the sum ends up in the register that was holding F(n-2).

Trivia: F(0) = 0, since F(n-2) = (F(n+1) - (F(n) · F(n-1)))/F(n). You can also calculate F(-1) = 1), but not F(-2) since it that ends up as 1/0 .

Upvotes: 1

Related Questions