Question

MIPS - assembly language Task I (1 mark): Write a program to calculate the nth Fibonacci...

MIPS - assembly language

Task I (1 mark): Write a program to calculate the nth Fibonacci number based on an iterative approach where value n is read from the keyboard and stored in your main program that is calling fib.

 The main program reads number ‘n’ -- restrict range of ‘n’ to 2-50, and display an error message if this condition is not satisfied.

 The main program calls fib with parameter passing. Procedure fib should return the calculated value of the n-th Fibonacci member to the main program.

 You would find that, after F47, the Fibonacci numbers will be greater than INT_MAX (2147483647 or 0x7FFFFFFF) and as a consequence an ‘arithmetic overflow’ occurs. Fib(49)=7778742049; Fib(50)=12586269025

 Rewrite the code by taking the power of double-precision floating point (FP) calculation so as to get around the ‘arithmetic overflow’ problem.

Note: Data transfer between the main program and procedure fib should be managed gracefully via procedure calling interface, namely, via parameter passing ($a registers to be used) and result return ($v registers to be used). Avoid data sharing via registers globally.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

org 100h

.DATA

ANS DW ?

.CODE

MAIN PROC

MOV AX,@DATA

MOV DS,AX

MOV BX,0

MOV DX,1

MOV CX,7

LABEL:

ADD BX,DX

MOV AX,BX

MOV BX,DX

MOV DX,AX

LOOP LABEL

SUB DX,1

MOV ANS,DX

END MAIN

ret

Add a comment
Know the answer?
Add Answer to:
MIPS - assembly language Task I (1 mark): Write a program to calculate the nth Fibonacci...
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
  • 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)

  • 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

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • The task will be to write a program in assembler to enter a number and calculate...

    The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

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