author | Christian Urban <urbanc@in.tum.de> |
Tue, 13 Nov 2018 08:16:48 +0000 | |
changeset 600 | d488a3e7b0ec |
parent 545 | 76a98ed71a2a |
child 609 | e33545bb2eba |
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 |
|
16 |
invokevirtual java/io/PrintStream/println(I)V |
|
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 |
|
600 | 20 |
.method public static read()I |
21 |
.limit locals 10 |
|
373
b018234c9126
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
323
diff
changeset
|
22 |
.limit stack 10 |
211
deece8c6cf3a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
208
diff
changeset
|
23 |
|
600 | 24 |
ldc 0 |
25 |
istore 1 ; this will hold our final integer |
|
26 |
Label1: |
|
27 |
getstatic java/lang/System/in Ljava/io/InputStream; |
|
28 |
invokevirtual java/io/InputStream/read()I |
|
29 |
istore 2 |
|
30 |
iload 2 |
|
31 |
ldc 10 ; the newline delimiter |
|
32 |
isub |
|
33 |
ifeq Label2 |
|
34 |
iload 2 |
|
35 |
ldc 32 ; the space delimiter |
|
36 |
isub |
|
373
b018234c9126
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
323
diff
changeset
|
37 |
ifeq Label2 |
211
deece8c6cf3a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
208
diff
changeset
|
38 |
|
600 | 39 |
iload 2 |
40 |
ldc 48 ; we have our digit in ASCII, have to subtract it from 48 |
|
41 |
isub |
|
42 |
ldc 10 |
|
43 |
iload 1 |
|
44 |
imul |
|
45 |
iadd |
|
46 |
istore 1 |
|
47 |
goto Label1 |
|
48 |
Label2: |
|
49 |
;when we come here we have our integer computed in local variable 1 |
|
50 |
iload 1 |
|
51 |
ireturn |
|
211
deece8c6cf3a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
208
diff
changeset
|
52 |
.end method |
207
f824e1331fc6
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
53 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
.method public static main([Ljava/lang/String;)V |
600 | 55 |
.limit locals 200 |
56 |
.limit stack 200 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
|
600 | 58 |
invokestatic fib/fib/read()I |
59 |
istore 0 |
|
60 |
ldc 0 |
|
61 |
istore 1 |
|
62 |
ldc 1 |
|
63 |
istore 2 |
|
64 |
ldc 0 |
|
65 |
istore 3 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
|
600 | 67 |
Loop_begin_2: |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
|
600 | 69 |
ldc 0 |
70 |
iload 0 |
|
71 |
if_icmpge Loop_end_3 |
|
72 |
iload 2 |
|
73 |
istore 3 |
|
74 |
iload 1 |
|
75 |
iload 2 |
|
76 |
iadd |
|
77 |
istore 2 |
|
78 |
iload 3 |
|
79 |
istore 1 |
|
80 |
iload 0 |
|
81 |
ldc 1 |
|
82 |
isub |
|
83 |
istore 0 |
|
84 |
goto Loop_begin_2 |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
|
600 | 86 |
Loop_end_3: |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
|
600 | 88 |
iload 1 |
89 |
invokestatic fib/fib/write(I)V |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
|
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
|
600 | 92 |
return |
93 |
||
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
.end method |