--- a/progs/fib.j Thu Nov 28 12:51:01 2013 +0000
+++ b/progs/fib.j Fri Nov 29 09:01:08 2013 +0000
@@ -3,39 +3,71 @@
.super java/lang/Object
.method public <init>()V
- aload_0
- invokenonvirtual java/lang/Object/<init>()V
- return
+ aload_0
+ invokenonvirtual java/lang/Object/<init>()V
+ return
.end method
.method public static write(I)V
- .limit locals 5
- .limit stack 5
- iload 0
- getstatic java/lang/System/out Ljava/io/PrintStream;
- swap
- invokevirtual java/io/PrintStream/println(I)V
- return
+ .limit locals 5
+ .limit stack 5
+ iload 0
+ getstatic java/lang/System/out Ljava/io/PrintStream;
+ swap
+ invokevirtual java/io/PrintStream/println(I)V
+ return
.end method
-
.method public static writes(Ljava/lang/String;)V
- .limit stack 2
- .limit locals 2
- getstatic java/lang/System/out Ljava/io/PrintStream;
- aload 0
- invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
- return
+ .limit stack 2
+ .limit locals 2
+ getstatic java/lang/System/out Ljava/io/PrintStream;
+ aload 0
+ invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
+ return
.end method
+.method public static read()I
+ .limit locals 10
+ .limit stack 10
+
+ ldc 0
+ istore 1 ; this will hold our final integer
+Label1:
+ getstatic java/lang/System/in Ljava/io/InputStream;
+ invokevirtual java/io/InputStream/read()I
+ istore 2
+ iload 2
+ ldc 10 ; the newline delimiter
+ isub
+ ifeq Label2
+ iload 2
+ ldc 32 ; the space delimiter
+ isub
+ ifeq Label2
+
+ iload 2
+ ldc 48 ; we have our digit in ASCII, have to subtract it from 48
+ isub
+ ldc 10
+ iload 1
+ imul
+ iadd
+ istore 1
+ goto Label1
+Label2:
+ ;when we come here we have our integer computed in Local Variable 1
+ iload 1
+ ireturn
+.end method
.method public static main([Ljava/lang/String;)V
- .limit locals 200
- .limit stack 200
+ .limit locals 200
+ .limit stack 200
ldc "Fib"
invokestatic fib/fib/writes(Ljava/lang/String;)V
-ldc 19
+invokestatic fib/fib/read()I
istore 0
ldc 0
istore 1
@@ -69,6 +101,6 @@
invokestatic fib/fib/write(I)V
- return
+ return
.end method
--- a/progs/fib.while Thu Nov 28 12:51:01 2013 +0000
+++ b/progs/fib.while Fri Nov 29 09:01:08 2013 +0000
@@ -2,8 +2,8 @@
input: n
*/
write "Fib";
-//read n;
-n := 19;
+read n;
+//n := 19;
minus1 := 0;
minus2 := 1;
while n > 0 do {