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

Free

50.1K

Verified Solution

Question

Programming

The Fibonacci Sequence is a series of integers. The first twonumbers in the sequence are both 1; after that, each number is thesum 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, sofor example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2,fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is3, 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 fibonacciterm and print it out.

The program should produce this input:

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

Answer & Explanation Solved by verified expert
3.7 Ratings (625 Votes)

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


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students