Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MIPS Assembly Language Programming Exercise: Various infinite series for pi have

ID: 3567683 • Letter: M

Question

MIPS Assembly Language Programming Exercise:

Various infinite series for pi have been discovered. The first such series found was the Gregory-Leibniz series:

pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ...)

This series is of little practical value because enormous numbers of terms are required to achieve a good approximation. However, it does provide good programming practice.

Write a program that writes out the sum of the first 1000, 2000, 3000, ... , 10000 terms of the series (e.g., count to 10000 stopping to print after every 1000 passes through the loop). Write both iterative and recursive versions of the function to approximate pi. Have the program call the iterative version then the recursive version for each value, saving the results in an array, and print the corresponding values from the two calls, iterative then recursive, one pair per line, with a tab between the values and a newline after the second value.

DO NOT write this program in Java or C++ format.

Can someone post the MIPS Assembly Language code for this problem?

Explanation / Answer

Program for pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ...)

import java.util.*;
import java.io.*;
class Divya {
public static void main(String args[]) {
int numberTerms=1; // started with one
double sequence=1.0; // sequence of soma
double piFix = 3.14159; // value of PI fix
double piFound; // value of PI found
double signal=-1.0;
System.out.println("Program that calculate series");
//find sequence
for(int d=3; d<200000; d+=2) {
sequence=sequence + signal*(1.0/(double)d);
piFound = 4.0*sequence;
numberTerms++; // increment number os terms
System.out.println("piFix: " + piFix + " "+ "piFound: " + piFound + " Terms: " + numberTerms);
// found number os terms
if( (piFound >= (piFix-0.000005)) && (piFound <= (piFix+0.000005)) ) {
System.out.println("Number of terms need are: " + numberTerms );
break;
}
signal=signal*-1.0;
}
}
}

and

public class Pi {
public void main(String[] args) {
double signo=1,denominador=1,serie=0;
int n=0;
while(true) {
serie+=signo/denominador;
signo*=-1;
denominador+=2;
n++;
if(Math.abs(4*serie-3.14159)<1e-5) break;
}
System.out.println("Iteraciones="+n+" Resultado="+(4*serie));
}
}

Sum of first 1000, 2000, 3000...... 10000 terms of series

//Global declaration

int a=0,b=0;

DefaultTbleModel model=new DefaultTableModel(data,header);

JTable table=new JTable(model);

for(int i=0;i<table.getRowCount();i++){

            a=a+Integer.parseInt(data.get(i).get(column));

            b=b+Integer.parseInt(data.get(i).get(column));

        }

        tj=Integer.toString(a);

        tb=Integer.toString(b);

        Object[] d1={"Total",tj,tb};

        model.addRow(d1);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote