NEEDS TO BE IN JASMIN so a .j file NOT a .java file
The following jasmin code estimates e using the series:
Modify this code to estimate using the series:
The series for converges very quickly, so the following code only goes for 20 iterations. The series for does 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!