progs/fib.j
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 23 Oct 2015 08:35:17 +0100
changeset 361 9c7eb266594c
parent 323 4ce07c4abdb4
child 373 b018234c9126
permissions -rw-r--r--
updated
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
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     6
   aload_0
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     7
   invokenonvirtual java/lang/Object/<init>()V
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
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
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
.method public static write(I)V 
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    12
    .limit locals 5 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    13
    .limit stack 5 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    14
    iload 0 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    15
    getstatic java/lang/System/out Ljava/io/PrintStream; 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    16
    swap 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    17
    invokevirtual java/io/PrintStream/println(I)V 
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
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
211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    21
.method public static read()I 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    22
      .limit locals 10 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    23
      .limit stack 10
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    25
      ldc 0 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    26
      istore 1  ; this will hold our final integer 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    27
Label1: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    28
      getstatic java/lang/System/in Ljava/io/InputStream; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    29
      invokevirtual java/io/InputStream/read()I 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    30
      istore 2 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    31
      iload 2 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    32
      ldc 10   ; the newline delimiter 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    33
      isub 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    34
      ifeq Label2 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    35
      iload 2 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    36
      ldc 32   ; the space delimiter 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    37
      isub 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    38
      ifeq Label2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    39
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    40
      iload 2 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    41
      ldc 48   ; we have our digit in ASCII, have to subtract it from 48 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    42
      isub 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    43
      ldc 10 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    44
      iload 1 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    45
      imul 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    46
      iadd 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    47
      istore 1 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    48
      goto Label1 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    49
Label2: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    50
      ;when we come here we have our integer computed in Local Variable 1 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    51
      iload 1 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    52
      ireturn 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    53
.end method
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    54
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    55
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
.method public static main([Ljava/lang/String;)V
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    57
   .limit locals 200
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    58
   .limit stack 200
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    60
invokestatic fib/fib/read()I
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
istore 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
ldc 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
istore 1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
ldc 1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
istore 2
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    66
ldc 0
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    67
istore 3
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
Loop_begin_0:
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
ldc 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
iload 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
if_icmpge Loop_end_1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
iload 2
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
istore 3
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
iload 1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
iload 2
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
iadd
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
istore 2
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
iload 3
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
istore 1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
iload 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
ldc 1
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
isub
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
istore 0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
goto Loop_begin_0
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
Loop_end_1:
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
iload 2
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
invokestatic fib/fib/write(I)V
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    94
   return
93
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
4794759139ea better organised
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
.end method
323
4ce07c4abdb4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
    97