Consider the following sequence, (refereed to as the alternating Fibonacci seque
ID: 3624572 • Letter: C
Question
Consider the following sequence, (refereed to as the alternating Fibonacci sequence):
1 -1 2 -3 5 -8 13 …
Here altfib2 = 1, altfib2 = -1, and altfibn = altfibn-2 - altfibn-1 for n > 2.
Write a MIPS program that will produce and print numbers (5 per line) in the alternating Fibonacci sequence in such a way that the code detects when overflow takes place. The “offending” number should not be in your list of numbers, but you should display the bogus value that is produced.
Here are the alternating Fibonacci number that you should be able to produce:
1 -1 2 -3 5
-8 13 -21 34 -55
89 -144 233 -377 610
-987 1597 -2584 4181 -6765
10946 -17711 28657 -46368 75025
-121393 196418 -317811 514229 -832040
1346269 -2178309 3524578 -5702887 9227465
-14930352 24157817 -39088169 63245986 -102334155
165580141 -267914296 433494437 -701408733 1134903170
-1836311903
Value causing overflow = -1323752223
(the next value in the list would have been 1134903170 – (-1836311903) = 1134903170 + 1836311903 = 2971215073, which is too large for a 32-bit 2’s complement number; instead, it is interpreted as -1323752223)