progs/fib.j
changeset 211 deece8c6cf3a
parent 208 bd5a8a6b3871
child 323 4ce07c4abdb4
equal deleted inserted replaced
210:33175abd5474 211:deece8c6cf3a
     1 
     1 
     2 .class public fib.fib
     2 .class public fib.fib
     3 .super java/lang/Object
     3 .super java/lang/Object
     4 
     4 
     5 .method public <init>()V
     5 .method public <init>()V
     6    aload_0
     6         aload_0
     7    invokenonvirtual java/lang/Object/<init>()V
     7         invokenonvirtual java/lang/Object/<init>()V
     8    return
     8         return
     9 .end method
     9 .end method
    10 
    10 
    11 .method public static write(I)V 
    11 .method public static write(I)V 
    12     .limit locals 5 
    12         .limit locals 5 
    13     .limit stack 5 
    13         .limit stack 5 
    14     iload 0 
    14         iload 0 
    15     getstatic java/lang/System/out Ljava/io/PrintStream; 
    15         getstatic java/lang/System/out Ljava/io/PrintStream; 
    16     swap 
    16         swap 
    17     invokevirtual java/io/PrintStream/println(I)V 
    17         invokevirtual java/io/PrintStream/println(I)V 
    18     return 
    18         return 
    19 .end method
    19 .end method
    20 
    20 
    21 
       
    22 .method public static writes(Ljava/lang/String;)V
    21 .method public static writes(Ljava/lang/String;)V
    23    .limit stack 2
    22        .limit stack 2
    24    .limit locals 2
    23        .limit locals 2
    25    getstatic java/lang/System/out Ljava/io/PrintStream;
    24        getstatic java/lang/System/out Ljava/io/PrintStream;
    26    aload 0
    25        aload 0
    27    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    26        invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    28    return
    27        return
    29 .end method
    28 .end method
    30 
    29 
       
    30 .method public static read()I 
       
    31       .limit locals 10 
       
    32       .limit stack 10
       
    33 
       
    34       ldc 0 
       
    35       istore 1  ; this will hold our final integer 
       
    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 Label1 
       
    58 Label2: 
       
    59       ;when we come here we have our integer computed in Local Variable 1 
       
    60       iload 1 
       
    61       ireturn 
       
    62 .end method
    31 
    63 
    32 .method public static main([Ljava/lang/String;)V
    64 .method public static main([Ljava/lang/String;)V
    33    .limit locals 200
    65       .limit locals 200
    34    .limit stack 200
    66       .limit stack 200
    35 
    67 
    36 ldc "Fib"
    68 ldc "Fib"
    37 invokestatic fib/fib/writes(Ljava/lang/String;)V
    69 invokestatic fib/fib/writes(Ljava/lang/String;)V
    38 ldc 19
    70 invokestatic fib/fib/read()I
    39 istore 0
    71 istore 0
    40 ldc 0
    72 ldc 0
    41 istore 1
    73 istore 1
    42 ldc 1
    74 ldc 1
    43 istore 2
    75 istore 2
    67 invokestatic fib/fib/writes(Ljava/lang/String;)V
    99 invokestatic fib/fib/writes(Ljava/lang/String;)V
    68 iload 2
   100 iload 2
    69 invokestatic fib/fib/write(I)V
   101 invokestatic fib/fib/write(I)V
    70 
   102 
    71 
   103 
    72    return
   104       return
    73 
   105 
    74 .end method
   106 .end method