Question

In: Computer Science

The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are...

The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers.

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc.

The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not 5.

Your assignment is to write an ARM assembler code (Fibonacci.s) that prompts the user for the nth term of the fibonacci sequence. The program will then calculate the users selected nth fibonacci term and print it out.

The program should produce this input:

Enter the desired Fibonacci term: 6
The 6th Fibonacci number is: 8

Solutions

Expert Solution

Please find the ARM code for finding the desired term in Fibonnaci Sequence

.LC0:

        .ascii  "Enter the desired Fibonacci term: \000"

.LC1:

        .ascii  "%d\000"

.LC2:

        .ascii  "Fibonacci of negative number is not possible.\000"

.LC3:

        .ascii  "The %d of Fibonacci is %d\012\000"

main:

        push    {fp, lr}

        add     fp, sp, #4

        sub     sp, sp, #8

        ldr     r0, .L5

        bl      printf

        sub     r3, fp, #12

        mov     r1, r3

        ldr     r0, .L5+4

        bl      __isoc99_scanf

        ldr     r3, [fp, #-12]

        cmp     r3, #0

        bge     .L2

        ldr     r0, .L5+8

        bl      puts

        b       .L3

.L2:

        ldr     r3, [fp, #-12]

        mov     r0, r3

        bl      fibonacci

        str     r0, [fp, #-8]

        ldr     r3, [fp, #-12]

        ldr     r2, [fp, #-8]

        mov     r1, r3

        ldr     r0, .L5+12

        bl      printf

.L3:

        mov     r3, #0

        mov     r0, r3

        sub     sp, fp, #4

        pop     {fp, lr}

        bx      lr

.L5:

        .word   .LC0

        .word   .LC1

        .word   .LC2

        .word   .LC3

fibonacci:

        push    {r4, fp, lr}

        add     fp, sp, #8

        sub     sp, sp, #12

        str     r0, [fp, #-16]

        ldr     r3, [fp, #-16]

        cmp     r3, #0

        bne     .L8

        mov     r3, #0

        b       .L9

.L8:

        ldr     r3, [fp, #-16]

        cmp     r3, #1

        bne     .L10

        mov     r3, #1

        b       .L9

.L10:

        ldr     r3, [fp, #-16]

        sub     r3, r3, #1

        mov     r0, r3

        bl      fibonacci

        mov     r4, r0

        ldr     r3, [fp, #-16]

        sub     r3, r3, #2

        mov     r0, r3

        bl      fibonacci

        mov     r3, r0

        add     r3, r4, r3

.L9:

        mov     r0, r3

        sub     sp, fp, #8

        pop     {r4, fp, lr}

        bx      lr


Related Solutions

(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence,...
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0,...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you add these numbers you get 2 = 1+1, which becomes the third number in the sequence. When you add the second and third numbers, you get 3 = 1+2, which becomes the fourth number in the sequence. When you add the third and fourth numbers, you get 5 = 2+3, which becomes the fifth number in the sequence; and so on to generate the...
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13,...
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 . . . See the pattern? Each element in the series is the sum of the preceding two elements. Here is a recursive formula for calculating the nth number of the sequence: Fib(N) = {N, if N = 0 or 1 Fib(N - 2) + Fib(N - 1), if N > 1 a) Write a recursive method fibonacci that returns...
Google the first 50 numbers of the Fibonacci sequence (starting with 1) to answer the following...
Google the first 50 numbers of the Fibonacci sequence (starting with 1) to answer the following questions:          (a) Test to see if the leading digits conform to Benford’s law. Do this both graphically and analytically.          (b) Using the first 10 odd numbers in the sequence as sample 1 and the first 10 even numbers in the sequence as sample 2, use Wilcoxon’s Rank-Sum to test the claim that the numbers come from different populations.          (c) Repeat (b)...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently using dynamic programming. Create a program that uses dynamic programming techniques to list the first 30 Fibonacci numbers.
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally,...
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally, it can be expressed as: fib0 = 0 fib1 = 1 fibn = fibn-1 + fibn-2 Write a multithreaded C++ program that generates the Fibonacci series using the pthread library. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program will generate. The program will then create a separate thread that will...
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics...
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics and applications to arrangement of flower petals, population growth of rabbits, and genetics. For each natural number n ≥ 1, the nth Fibonacci number fn is defined inductively by f1 = 1, f2 = 2, and fn+2 = fn+1 + fn (a) Compute the first 8 Fibonacci numbers f1, · · · , f8. (b) Show that for all natural numbers n, if α...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
In this assignment, you will calculate and print a list of Fibonacci Numbers . Fibonacci numbers...
In this assignment, you will calculate and print a list of Fibonacci Numbers . Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: The sequence Fn of Fibonacci numbers is defined by the recurrence relation:  which says any Nth Fibonacci number is the sum of the (N-1) and (N-2)th Fibonacci numbers. Instructions Your task will be...
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT