progs/fib.j
changeset 612 7a12053567d4
parent 609 e33545bb2eba
child 617 f7de0915fff2
equal deleted inserted replaced
611:060f33b5661d 612:7a12053567d4
    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