Answered Essay: NEEDS TO BE IN JASMIN so a .j file NOT a .java file

NEEDS TO BE IN JASMIN so a .j file NOT a .java file

The following jasmin code estimates e using the series:

0! 1! 2! 3!

Modify this code to estimate pi using the series:

pi=4-frac{4}{3}+frac{4}{5}-frac{4}{7}+:...

The series for e converges very quickly, so the following code only goes for 20 iterations. The series for pidoes not converge quickly. Calculate to at least 100,000 terms once you know your code is working. The following code prints at each iteration of the loop. You probably don’t want to do that for 100000 terms! Take the print out of the loop and move it to after the loop.

; — Copyright Jonathan Meyer 1996. All rights reserved. —————–
; File:      jasmin/examples/Count.j
; Author:    Jonathan Meyer, 10 July 1996
; Purpose:   Counts from 0 to 9, printing out the value
; ————————————————————————-

.class public Eest
.super java/lang/Object

;
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method

.method public static main([Ljava/lang/String;)V
; set limits used by this method
.limit locals 16
.limit stack 8

; setup local variables:

;    1 – the PrintStream object held in java.lang.System.out
getstatic java/lang/System/out Ljava/io/PrintStream;
astore_1

;    2 – the counter used in the loop
bipush 20   ; loop counter in 2
istore_2
dconst_1
dconst_1
dadd
dstore 4   ; e sum in 4
dconst_1
dstore 6   ; f.p. factorial in 6
dconst_1
dstore 8   ; f.p. n in 8

; now loop 10 times printing out a number

Loop:

; compute 10 – <local variable 2> …
dload 8
dconst_1
dadd       ; increment n
dup2
dstore 8   ; store n
dload 6
dmul
dstore 6   ; store n!
dconst_1
dload 6    ; load n!
ddiv
dload 4
dadd
dup2
dstore 4
invokestatic java/lang/String/valueOf(D)Ljava/lang/String;
astore_3
; … and print it
aload_1    ; push the PrintStream object
aload_3    ; push the string we just created – then …
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

; decrement the counter and loop
iinc 2 -1
iload_2
ifne Loop

; done
return

.end method

Show transcribed image text0! 1! 2! 3!

Expert Answer

 

Java Code:

//Define a class Eest

public class Eest

{

//Define main

public static void main(String[]args)

{

//Compute value

double val=compute_Pi(100000);

//Display value

System.out.println(val);

}

//Define a method

public static double compute_Pi(int count)

{

//Declare variable

double val=1;

//Loop

for(int i=3;i<count;i+=4)

{

//Compute value

val=val-(1/(double)i)+(1/(double)(i+2));

}

//Return

return val * 4;

}

}

Modified bytecode:

Compiled from “Eest.java”

public class Eest {

public Eest();

Code:

0: aload_0

1: invokespecial #1                  // Method java/lang/Object.”<init>”:

()V

4: return

public static void main(java.lang.String[]);

Code:

0: ldc           #2                  // int 100000

2: invokestatic #3                  // Method compute_Pi:(I)D

5: dstore_1

6: getstatic     #4                  // Field java/lang/System.out:Ljava/

io/PrintStream;

9: dload_1

10: invokevirtual #5                  // Method java/io/PrintStream.printl

n:(D)V

13: return

public static double compute_Pi(int);

Code:

0: dconst_1

1: dstore_1

2: iconst_3

3: istore_3

4: iload_3

5: iload_0

6: if_icmpge     29

9: dload_1

10: dconst_1

11: iload_3

12: i2d

13: ddiv

14: dsub

15: dconst_1

16: iload_3

17: iconst_2

18: iadd

19: i2d

20: ddiv

21: dadd

22: dstore_1

23: iinc          3, 4

26: goto          4

29: dload_1

30: ldc2_w        #6                  // double 4.0d

33: dmul

34: dreturn

}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.