progs/fib.j
changeset 545 76a98ed71a2a
parent 471 9476086849ad
child 600 d488a3e7b0ec
equal deleted inserted replaced
544:748207ad3ef0 545:76a98ed71a2a
     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 print(Ljava/lang/String;)V
    12     .limit locals 1 
    12     .limit locals 5
    13     .limit stack 2 
    13     .limit stack 5
    14     getstatic java/lang/System/out Ljava/io/PrintStream; 
    14     aload 0
    15     iload 0
    15     getstatic java/lang/System/out Ljava/io/PrintStream;
    16     invokevirtual java/io/PrintStream/println(I)V 
    16     swap
    17     return 
    17     invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
       
    18     return
    18 .end method
    19 .end method
    19 
    20 
    20 .method public static read()I 
    21 .method public static write(I)V
    21     .limit locals 10 
    22     .limit locals 1
       
    23     .limit stack 2
       
    24     getstatic java/lang/System/out Ljava/io/PrintStream;
       
    25     iload 0
       
    26     invokevirtual java/io/PrintStream/println(I)V
       
    27     return
       
    28 .end method
       
    29 
       
    30 .method public static read()I
       
    31     .limit locals 10
    22     .limit stack 10
    32     .limit stack 10
    23 
    33 
    24     ldc 0 
    34     ldc 0
    25     istore 1  ; this will hold our final integer 
    35     istore 1  ; this will hold our final integer
    26 Label1: 
    36 Label1:
    27     getstatic java/lang/System/in Ljava/io/InputStream; 
    37     getstatic java/lang/System/in Ljava/io/InputStream;
    28     invokevirtual java/io/InputStream/read()I 
    38     invokevirtual java/io/InputStream/read()I
    29     istore 2 
    39     istore 2
    30     iload 2 
    40     iload 2
    31     ldc 10   ; the newline delimiter 
    41     ldc 10   ; the newline delimiter
    32     isub 
    42     isub
    33     ifeq Label2 
    43     ifeq Label2
    34     iload 2 
    44     iload 2
    35     ldc 32   ; the space delimiter 
    45     ldc 32   ; the space delimiter
    36     isub 
    46     isub
    37     ifeq Label2
    47     ifeq Label2
    38 
    48 
    39     iload 2 
    49     iload 2
    40     ldc 48   ; we have our digit in ASCII, have to subtract it from 48 
    50     ldc 48   ; we have our digit in ASCII, have to subtract it from 48
    41     isub 
    51     isub
    42     ldc 10 
    52     ldc 10
    43     iload 1 
    53     iload 1
    44     imul 
    54     imul
    45     iadd 
    55     iadd
    46     istore 1 
    56     istore 1
    47     goto Label1 
    57     goto Label1
    48 Label2: 
    58 Label2:
    49     ;when we come here we have our integer computed in local variable 1 
    59     ;when we come here we have our integer computed in local variable 1
    50     iload 1 
    60     iload 1
    51     ireturn 
    61     ireturn
    52 .end method
    62 .end method
    53 
    63 
    54 .method public static main([Ljava/lang/String;)V
    64 .method public static main([Ljava/lang/String;)V
    55    .limit locals 200
    65     .limit locals 200
    56    .limit stack 200
    66     .limit stack 200
    57 
    67 
    58 invokestatic fib/fib/read()I
    68     ldc "Fib"
    59 istore 0
    69     invokestatic fib/fib/print(Ljava/lang/String;)V
    60 ldc 0
    70     invokestatic fib/fib/read()I
    61 istore 1
    71     istore 0
    62 ldc 1
    72     ldc 0
    63 istore 2
    73     istore 1
    64 ldc 0
    74     ldc 1
    65 istore 3
    75     istore 2
    66 
    76 
    67 Loop_begin_2:
    77 Loop_start_1:
    68 
    78 
    69 ldc 0
    79     iload 0
    70 iload 0
    80     ldc 0
    71 if_icmpge Loop_end_3
    81     if_icmple Loop_end_0
    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
       
    85 
    82 
    86 Loop_end_3:
    83     iload 2
       
    84     istore 3
       
    85     iload 1
       
    86     iload 2
       
    87     iadd
       
    88     istore 2
       
    89     iload 3
       
    90     istore 1
       
    91     iload 0
       
    92     ldc 1
       
    93     isub
       
    94     istore 0
    87 
    95 
    88 iload 1
    96     goto Loop_start_1
    89 invokestatic fib/fib/write(I)V
       
    90 
    97 
       
    98 Loop_end_0:
    91 
    99 
    92    return
   100     ldc "Result"
       
   101     invokestatic fib/fib/print(Ljava/lang/String;)V
       
   102     iload 2
       
   103     invokestatic fib/fib/write(I)V
    93 
   104 
       
   105     return
    94 .end method
   106 .end method