updated
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 28 Nov 2014 13:11:17 +0000
changeset 313 90ccc385c547
parent 312 5cdb4d40eb80
child 314 7dd5797a5ffa
updated
coursework/cw04.pdf
coursework/cw04.tex
slides/slides09.pdf
Binary file coursework/cw04.pdf has changed
--- a/coursework/cw04.tex	Mon Nov 24 09:06:27 2014 +0000
+++ b/coursework/cw04.tex	Fri Nov 28 13:11:17 2014 +0000
@@ -48,7 +48,14 @@
 \noindent
 where you might need to give the correct path to the class file. There
 are also other resources about Jasmin on the Internet, for example
-\mbox{\url{http://goo.gl/Qj8TeK}} and \mbox{\url{http://goo.gl/fpVNyT}}\;.\bigskip
+
+\begin{center}
+\url{http://www.ceng.metu.edu.tr/courses/ceng444/link/f3jasmintutorial.html}
+
+and
+
+\url{http://www.csc.villanova.edu/~tway/courses/csc8505/s2011/handouts/JVM%20and%20Jasmin.pdf}
+\end{center}
 
 \noindent
 You need to submit a document containing the answers for the two questions 
@@ -59,15 +66,22 @@
 in a txt-file or as pdf.\bigskip
 
 
-\subsection*{Question 1 (marked with 2\%)}
+\subsection*{Question 1 (marked with 5\%)}
 
-You need to lex and parse WHILE programs and submit the assembler 
-instructions for the Fibonacci program and for the program you submitted
-in Coursework 2 in Question 3. The latter should be so modified that 
-a user can input the upper bound on the console (in the original question
-it was fixed to 100).
+You need to lex and parse WHILE programs, and then generate
+Java Byte Code instructions for the Jasmin assmebler. As
+solution you need to submit the assembler instructions for the
+Fibonacci and Factorial programs. Both should be so modified
+that a user can input on the console which Fibonacci number 
+and which Factorial should calculated. The Fibonacci program
+is  given in Figure~\ref{fibs}.
 
-\subsection*{Question 2 (marked with 2\%)}
+\begin{figure}[t]
+\lstinputlisting[language=while]{../progs/fib.while}
+\caption{The Fibonacci program in the WHILE language.}
+\end{figure}
+
+\subsection*{Question 2 (marked with 5\%)}
 
 Extend the syntax of you language so that it contains also \texttt{for}-loops, like
 
@@ -128,7 +142,9 @@
 \end{minipage}
 \end{center}
 
-
+\noindent 
+Note that in this program the variable \pcode{i} is used
+twice. You need to make a decision how it should be compiled?
 
 \subsection*{Further Information}
 
@@ -142,7 +158,7 @@
 
 \begin{center}
 \begin{minipage}{10cm}
-\begin{lstlisting}[language=Java,basicstyle=\ttfamily]
+\begin{lstlisting}[language=Java,numbers=none]
 class HelloWorld {
     public static void main(String[] args) {
         System.out.println("Hello World!");
@@ -159,14 +175,14 @@
 \texttt{javap -v HelloWorld}
 \end{center}
 
-\noindent
-to see the assembler instructions of the Java byte code that has been generated for this
-program. You can compare this with the code generated for the Scala
-version of Hello World.
+\noindent to see the assembler instructions of the Java byte
+code that has been generated for this program. You can compare
+this with the code generated for the Scala version of Hello
+World.
 
 \begin{center}
 \begin{minipage}{10cm}
-\begin{lstlisting}[language=Scala,basicstyle=\ttfamily]
+\begin{lstlisting}[language=Scala,numbers=none]
 object HelloWorld {
    def main(args: Array[String]) {
       println("Hello World!")
@@ -179,15 +195,17 @@
 
 \subsection*{Library Functions}
 
-You need to generate code for the commands \texttt{write} and \texttt{read}. This
-will require the addition of some ``library'' functions to your generated code. The first
-command even needs two versions, because you might want to write out an
-integer or a string. The Java byte code will need two separate functions for this.
-For writing out an integer, you can use the assembler code
+You need to generate code for the commands \texttt{write} and
+\texttt{read}. This will require the addition of some
+``library'' functions to your generated code. The first
+command even needs two versions, because you need to write out
+an integer and string. The Java byte code will need two
+separate functions for this. For writing out an integer, you
+can use the assembler code
 
 \begin{center}
 \begin{minipage}{12cm}
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS, numbers=none]
 .method public static write(I)V 
     .limit locals 5 
     .limit stack 5 
@@ -207,7 +225,7 @@
 
 \begin{center}
 \begin{minipage}{8cm}
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS, numbers=none]
 iload n 
 invokestatic XXX/XXX/write(I)V
 \end{lstlisting}
@@ -225,7 +243,7 @@
 
 \begin{center}
 \begin{minipage}{12cm}
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS, numbers=none]
 .method public static writes(Ljava/lang/String;)V
    .limit stack 2
    .limit locals 2
@@ -239,12 +257,12 @@
 \end{center}
 
 \noindent
-The code that needs to be generated for \texttt{write "some\_string"} commands 
+The code that needs to be generated for \code{write "some_string"} commands 
 is
 
 \begin{center}
 \begin{minipage}{8cm}
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS,numbers=none]
 ldc "some_string"
 invokestatic XXX/XXX/writes(Ljava/lang/String;)V
 \end{lstlisting}
@@ -260,7 +278,7 @@
 
 \begin{center}
 \begin{minipage}{8cm}
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS,numbers=none]
 invokestatic XXX/XXX/read()I 
 istore n
 \end{lstlisting}
@@ -272,7 +290,7 @@
 
 
 \begin{figure}[p]\small
-\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
+\begin{lstlisting}[language=JVMIS,numbers=none]
 .method public static read()I 
       .limit locals 10 
       .limit stack 10
Binary file slides/slides09.pdf has changed