author | Christian Urban <urbanc@in.tum.de> |
Thu, 26 Sep 2019 11:00:17 +0100 | |
changeset 633 | e4889da2fe29 |
parent 624 | 8d0af38389bc |
child 675 | d665e7dd66d7 |
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 read()I |
21 |
.limit locals 10 |
|
22 |
.limit stack 10 |
|
23 |
||
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 |
|
624 | 31 |
ldc 10 ; the newline delimiter |
617 | 32 |
isub |
33 |
ifeq Label2 |
|
34 |
iload 2 |
|
35 |
ldc 32 ; the space delimiter |
|
36 |
isub |
|
37 |
ifeq Label2 |
|
38 |
||
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: |
|
624 | 49 |
;when we come here we have our integer computed in local variable 1 |
50 |
iload 1 |
|
617 | 51 |
ireturn |
52 |
.end method |
|
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 |
|
624 | 58 |
; COMPILED CODE STARTS |
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
|
624 | 60 |
ldc 10 |
61 |
istore 0 |
|
62 |
ldc 0 |
|
63 |
istore 1 |
|
64 |
ldc 1 |
|
65 |
istore 2 |
|
66 |
ldc 0 |
|
67 |
istore 3 |
|
68 |
Loop_begin_0: |
|
69 |
ldc 0 |
|
70 |
iload 0 |
|
71 |
if_icmpge Loop_end_1 |
|
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_0 |
|
85 |
Loop_end_1: |
|
86 |
iload 1 |
|
87 |
invokestatic fib/fib/write(I)V |
|
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
|
624 | 89 |
; COMPILED CODE ENDS |
600 | 90 |
return |
91 |
||
93
4794759139ea
better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
.end method |