progs/fib.j
changeset 675 d665e7dd66d7
parent 624 8d0af38389bc
equal deleted inserted replaced
674:e0a41a1f24cf 675:d665e7dd66d7
    11 .method public static write(I)V 
    11 .method public static write(I)V 
    12     .limit locals 1 
    12     .limit locals 1 
    13     .limit stack 2 
    13     .limit stack 2 
    14     getstatic java/lang/System/out Ljava/io/PrintStream; 
    14     getstatic java/lang/System/out Ljava/io/PrintStream; 
    15     iload 0
    15     iload 0
    16     invokevirtual java/io/PrintStream/println(I)V 
    16     i2c
       
    17     invokevirtual java/io/PrintStream/print(C)V 
    17     return 
    18     return 
    18 .end method
       
    19 
       
    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 
       
    31     ldc 10   ; the newline delimiter 
       
    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: 
       
    49     ;when we come here we have our integer computed in local variable 1 
       
    50     iload 1 
       
    51     ireturn 
       
    52 .end method
    19 .end method
    53 
    20 
    54 .method public static main([Ljava/lang/String;)V
    21 .method public static main([Ljava/lang/String;)V
    55    .limit locals 200
    22    .limit locals 200
    56    .limit stack 200
    23    .limit stack 200
    57 
    24 
    58 ; COMPILED CODE STARTS
    25 ldc 10
       
    26 istore 0
       
    27 ldc 0
       
    28 istore 1
       
    29 ldc 1
       
    30 istore 2
       
    31 ldc 0
       
    32 istore 3
    59 
    33 
    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:
    34 Loop_begin_0:
    69    ldc 0
    35 
    70    iload 0
    36 ldc 0
    71    if_icmpge Loop_end_1
    37 iload 0
    72    iload 2
    38 if_icmpge Loop_end_1
    73    istore 3
    39 iload 2
    74    iload 1
    40 istore 3
    75    iload 2
    41 iload 1
    76    iadd
    42 iload 2
    77    istore 2
    43 iadd
    78    iload 3
    44 istore 2
    79    istore 1
    45 iload 3
    80    iload 0
    46 istore 1
    81    ldc 1
    47 iload 0
    82    isub
    48 ldc 1
    83    istore 0
    49 isub
    84    goto Loop_begin_0
    50 istore 0
       
    51 goto Loop_begin_0
       
    52 
    85 Loop_end_1:
    53 Loop_end_1:
    86    iload 1
       
    87    invokestatic fib/fib/write(I)V
       
    88 
    54 
    89 ; COMPILED CODE ENDS
    55 iload 1
       
    56 invokestatic fib/fib/write(I)V
       
    57 
       
    58 
    90    return
    59    return
    91 
    60 
    92 .end method
    61 .end method