updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Sat, 04 Dec 2021 00:41:31 +0000
changeset 859 f766d3486c9d
parent 858 13a6eb21706b
child 860 6f80e6df34f7
updated
cws/cw04.pdf
cws/cw04.tex
cwtests/cw03/fib.while
cwtests/cw04/fib.while
Binary file cws/cw04.pdf has changed
--- a/cws/cw04.tex	Sat Dec 04 00:13:20 2021 +0000
+++ b/cws/cw04.tex	Sat Dec 04 00:41:31 2021 +0000
@@ -292,12 +292,12 @@
 \begin{minipage}{12cm}
 \begin{lstlisting}[language=JVMIS, numbers=none]
 .method public static write(I)V 
-    .limit locals 1 
-    .limit stack 2  
-    getstatic java/lang/System/out Ljava/io/PrintStream; 
-    iload 0
-    invokevirtual java/io/PrintStream/println(I)V 
-    return 
+  .limit locals 1 
+  .limit stack 2  
+  getstatic java/lang/System/out Ljava/io/PrintStream; 
+  iload 0
+  invokevirtual java/io/PrintStream/println(I)V 
+  return 
 .end method
 \end{lstlisting}
 \end{minipage}
@@ -380,36 +380,37 @@
 \begin{figure}[t]\small
 \begin{lstlisting}[language=JVMIS,numbers=left]
 .method public static read()I 
-      .limit locals 10 
-      .limit stack 10
+    .limit locals 10 
+    .limit stack 10
 
-      ldc 0 
-      istore 1  ; this will hold our final integer 
+    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 for Unix (Windows 13)
-      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 
+    getstatic java/lang/System/in Ljava/io/InputStream; 
+    invokevirtual java/io/InputStream/read()I 
+    istore 2 
+    iload 2 
+    ldc 10  ; the newline delimiter for Unix (Windows 13)
+    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 
+    ; when we come here we have our integer computed
+    ; in local variable 1 
+    iload 1 
+    ireturn 
 .end method
 \end{lstlisting}\normalsize
 \caption{Assembler code for reading an integer from the console.\label{read}}
--- a/cwtests/cw03/fib.while	Sat Dec 04 00:13:20 2021 +0000
+++ b/cwtests/cw03/fib.while	Sat Dec 04 00:41:31 2021 +0000
@@ -1,7 +1,7 @@
 write "Fib: ";
 read n;  
-minus1 := 0;
-minus2 := 1;
+minus1 := 1;
+minus2 := 0;
 while n > 0 do {
        temp := minus2;
        minus2 := minus1 + minus2;
--- a/cwtests/cw04/fib.while	Sat Dec 04 00:13:20 2021 +0000
+++ b/cwtests/cw04/fib.while	Sat Dec 04 00:41:31 2021 +0000
@@ -1,12 +1,14 @@
-write "Fib";
-read n;
-minus1 := 0;
-minus2 := 1;
+write "Fib: ";
+read n;  
+minus1 := 1;
+minus2 := 0;
 while n > 0 do {
-  temp := minus2;
-  minus2 := minus1 + minus2;
-  minus1 := temp;
-  n := n - 1
+       temp := minus2;
+       minus2 := minus1 + minus2;
+       minus1 := temp;
+       n := n - 1
 };
-write "Result";
-write minus2
+write "Result: ";
+write minus2 ;
+write "\n"
+