author | Christian Urban <urbanc@in.tum.de> |
Sat, 29 Dec 2018 10:30:27 +0000 | |
changeset 617 | f7de0915fff2 |
parent 612 | 7a12053567d4 |
child 624 | 8d0af38389bc |
permissions | -rw-r--r-- |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
|
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
.class public fib.fib |
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
.super java/lang/Object |
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
.method public <init>()V |
600 | 6 |
aload_0 |
7 |
invokenonvirtual java/lang/Object/<init>()V |
|
8 |
return |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
.end method |
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
|
600 | 11 |
.method public static write(I)V |
12 |
.limit locals 1 |
|
13 |
.limit stack 2 |
|
14 |
getstatic java/lang/System/out Ljava/io/PrintStream; |
|
15 |
iload 0 |
|
617 | 16 |
invokevirtual java/io/PrintStream/println(I)V |
600 | 17 |
return |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
18 |
.end method |
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
19 |
|
617 | 20 |
.method public static writes(Ljava/lang/String;)V |
21 |
.limit stack 2 |
|
22 |
.limit locals 1 |
|
23 |
getstatic java/lang/System/out Ljava/io/PrintStream; |
|
24 |
aload 0 |
|
25 |
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V |
|
26 |
return |
|
27 |
.end method |
|
28 |
||
29 |
.method public static read()I |
|
30 |
.limit locals 10 |
|
31 |
.limit stack 10 |
|
32 |
||
33 |
ldc 0 |
|
34 |
istore 1 ; this will hold our final integer |
|
35 |
||
36 |
Label1: |
|
37 |
getstatic java/lang/System/in Ljava/io/InputStream; |
|
38 |
invokevirtual java/io/InputStream/read()I |
|
39 |
istore 2 |
|
40 |
iload 2 |
|
41 |
ldc 10 ; the newline delimiter |
|
42 |
isub |
|
43 |
ifeq Label2 |
|
44 |
iload 2 |
|
45 |
ldc 32 ; the space delimiter |
|
46 |
isub |
|
47 |
ifeq Label2 |
|
48 |
||
49 |
iload 2 |
|
50 |
ldc 48 ; we have our digit in ASCII, have to subtract it from 48 |
|
51 |
isub |
|
52 |
ldc 10 |
|
53 |
iload 1 |
|
54 |
imul |
|
55 |
iadd |
|
56 |
istore 1 |
|
57 |
goto Label2 |
|
58 |
goto Label1 |
|
59 |
||
60 |
Label2: |
|
61 |
iload 1 ; when we come here we have our integer computed in local variable 1 |
|
62 |
ireturn |
|
63 |
.end method |
|
64 |
||
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
.method public static main([Ljava/lang/String;)V |
600 | 66 |
.limit locals 200 |
67 |
.limit stack 200 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
|
609 | 69 |
ldc 10 |
600 | 70 |
istore 0 |
71 |
ldc 0 |
|
72 |
istore 1 |
|
73 |
ldc 1 |
|
74 |
istore 2 |
|
75 |
ldc 0 |
|
76 |
istore 3 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
|
609 | 78 |
Loop_begin_0: |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
|
600 | 80 |
ldc 0 |
81 |
iload 0 |
|
609 | 82 |
if_icmpge Loop_end_1 |
600 | 83 |
iload 2 |
84 |
istore 3 |
|
85 |
iload 1 |
|
86 |
iload 2 |
|
87 |
iadd |
|
88 |
istore 2 |
|
89 |
iload 3 |
|
90 |
istore 1 |
|
91 |
iload 0 |
|
92 |
ldc 1 |
|
93 |
isub |
|
94 |
istore 0 |
|
609 | 95 |
goto Loop_begin_0 |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
|
609 | 97 |
Loop_end_1: |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
|
600 | 99 |
iload 1 |
100 |
invokestatic fib/fib/write(I)V |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
|
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
|
600 | 103 |
return |
104 |
||
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
.end method |