Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a MIPS program and execute in MARS 1 . Nested Procedures. The following is a pseudo code for performing the Fibonacci series up to

Write a MIPS program and execute in MARS
1. Nested Procedures. The following is a pseudo code for performing the Fibonacci series up
to n terms using nested functions.
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of terms in the Fibonacci sequence: ");
int n = scanner.nextInt();
// Calculate and print the Fibonacci sequence
System.out.println("Fibonacci sequence:");
for (int i =0; i < n; i++){
System.out.print(fibonacci(i)+"");
}
scanner.close();
}
public static int fibonacci(int n){
if (n <=1){
return n;
} else {
return fibonacci(n -1)+ fibonacci(n -2);
}
}
}
Implement the above pseudo code in MIPS assembly, execute it in MARS simulator and
submit your .asm file. Make sure you add comments next to every instruction.
2. Recursive Function. Write a MIPS program and execute in MARS to recursively reverse
and array of integers. Submit your .asm file with comments included. The following is the
pseudo code for the program.
public class Main {
/* Function to reverse arr[] from start to end
*/
static void reverseArray(int arr[], int start,
int end){
int temp;
if (start >= end)
return;
reverseArray(arr, start +1, end -1);
temp = arr[start];
arr[start]= arr[end];
arr[end]= temp;
}
/* Utility that prints out an array on a line */
static void printArray(int arr[], int size){
for (int i =0; i < size; i++)
System.out.print(arr[i]+"");
System.out.println();
}
/* Driver function to test above functions */
public static void main(String[] args){
int arr[]={1,2,3,4,5,6};
System.out.print("Original array is : ");
printArray(arr,6);
reverseArray(arr,0,5);
System.out.print("Reversed array is : ");
printArray(arr,6);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago