progs/fib.j
author Christian Urban <urbanc@in.tum.de>
Wed, 24 Oct 2018 16:03:07 +0100
changeset 586 451a95e1bc25
parent 545 76a98ed71a2a
child 600 d488a3e7b0ec
permissions -rw-r--r--
typos
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
     6
    aload_0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
     7
    invokenonvirtual java/lang/Object/<init>()V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
     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
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    11
.method public static print(Ljava/lang/String;)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    12
    .limit locals 5
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    13
    .limit stack 5
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    14
    aload 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    15
    getstatic java/lang/System/out Ljava/io/PrintStream;
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    16
    swap
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    17
    invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    18
    return
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    19
.end method
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    20
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    21
.method public static write(I)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    22
    .limit locals 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    23
    .limit stack 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    24
    getstatic java/lang/System/out Ljava/io/PrintStream;
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    25
    iload 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    26
    invokevirtual java/io/PrintStream/println(I)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    27
    return
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    28
.end method
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    29
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    30
.method public static read()I
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    31
    .limit locals 10
373
b018234c9126 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 323
diff changeset
    32
    .limit stack 10
211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    33
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    34
    ldc 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    35
    istore 1  ; this will hold our final integer
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    36
Label1:
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    37
    getstatic java/lang/System/in Ljava/io/InputStream;
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    38
    invokevirtual java/io/InputStream/read()I
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    39
    istore 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    40
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    41
    ldc 10   ; the newline delimiter
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    42
    isub
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    43
    ifeq Label2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    44
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    45
    ldc 32   ; the space delimiter
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    46
    isub
373
b018234c9126 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 323
diff changeset
    47
    ifeq Label2
211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    48
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    49
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    50
    ldc 48   ; we have our digit in ASCII, have to subtract it from 48
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    51
    isub
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    52
    ldc 10
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    53
    iload 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    54
    imul
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    55
    iadd
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    56
    istore 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    57
    goto Label1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    58
Label2:
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    59
    ;when we come here we have our integer computed in local variable 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    60
    iload 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    61
    ireturn
211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    62
.end method
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    63
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
.method public static main([Ljava/lang/String;)V
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    65
    .limit locals 200
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    66
    .limit stack 200
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    68
    ldc "Fib"
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    69
    invokestatic fib/fib/print(Ljava/lang/String;)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    70
    invokestatic fib/fib/read()I
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    71
    istore 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    72
    ldc 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    73
    istore 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    74
    ldc 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    75
    istore 2
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    77
Loop_start_1:
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    78
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    79
    iload 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    80
    ldc 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    81
    if_icmple Loop_end_0
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    83
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    84
    istore 3
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    85
    iload 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    86
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    87
    iadd
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    88
    istore 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    89
    iload 3
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    90
    istore 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    91
    iload 0
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    92
    ldc 1
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    93
    isub
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    94
    istore 0
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    96
    goto Loop_start_1
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    98
Loop_end_0:
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
   100
    ldc "Result"
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
   101
    invokestatic fib/fib/print(Ljava/lang/String;)V
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
   102
    iload 2
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
   103
    invokestatic fib/fib/write(I)V
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
   105
    return
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
.end method