Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!