Question

Write an ARM assembly language subroutine (named n
0 0
Add a comment Improve this question Transcribed image text
Answer #1
nfibo proc
  PUSH EBP          ; save previous frame pointer
  MOV  EBP, ESP     ; set current frame pointer

  MOV  EAX, [EBP+8] ; get argument N
  CMP  EAX, 1       ; N<=1?
  JA   Recurse      ; no, compute it recursively
  MOV  ECX, 1       ; yes, Fib(1)--> 1
  JMP  exit

Recurse:
  DEC  EAX          ; = N-1
  MOV  EDX, EAX     ; = N-1
  PUSH EDX          ; save N-1
  PUSH EAX          ; set argument = N-1
  CALL nfibo    ; compute Fib(N-1) to ECX
  POP  EAX          ; pop N-1
  DEC  EAX          ; = N-2
  PUSH ECX          ; save Fib(N-1)
  PUSH EAX          ; set argument = N-2
  CALL nfibo    ; compute Fib(N-2) to ECX
  POP  EAX          ; = Fib(N-1)
  ADD  ECX, EAX     ; = Fib(N-1)+FIB(N-2)
exit:
  MOV  ESP,EBP      ; reset stack to value at function entry 
  POP  EBP          ; restore caller's frame pointer
  RET               ; and return
Add a comment
Know the answer?
Add Answer to:
Write an ARM assembly language subroutine (named nfibo) to calculate and return the n-th Fibonacci number....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ARM assembly language Write a program "fibonacci.s" that computes the Nth Fibonacci number where N is...

    ARM assembly language Write a program "fibonacci.s" that computes the Nth Fibonacci number where N is not so large that overflow of integer arithmetic is a concern. When your assembly language program is called it should expect the value of N to be passed using register r0 and your program should return the Nth Fibonacci number in register r0. Please include comments as well. Do not just use the output generated by gcc -S

  • Write a recursive static method that will return the n’th term in the Fibonacci series, a...

    Write a recursive static method that will return the n’th term in the Fibonacci series, a series of numbers in which each number is the sum of the two preceding numbers. The first terms are 1, 1, 2, 3, 5, 8, 13, … Therefore fibonacci(5) will return 5.

  • In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int...

    In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5,...

    in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89.. 1 See the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence (the oth number if Fib(0)-0): 8 Fib(N)-/N, if N 0 or 1 ifN> 1 Fib(N-2) Fib(N-1), a. b. c. Write a recursive version of the function Fibonacci. Write...

  • Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 =...

    Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1, where i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers. Write a recursive function definition in C++ that has one parameter n of type int and that returns the n-th Fibonacci number. You can call this function inside the main function to print the Fibonacci numbers. Sample Input...

  • This is from discrete math. Please write clearly so I can understand. 3. Recall the Fibonacci...

    This is from discrete math. Please write clearly so I can understand. 3. Recall the Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, .... These are formed by defining the first two numbers, followed by a recursive formula for the rest: Fi = 1 and F2 = 1, where F = F.-2+ FR-2, where n EN and n 3. Let ne N and F. be the nth Fibonacci number. Prove that (6) +(";")+(";2)+(";") +--+ () =...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT