coursework/cw03.tex
changeset 204 fec99c437965
parent 203 f1335c171d50
child 205 0b59588d28d2
equal deleted inserted replaced
203:f1335c171d50 204:fec99c437965
    62 
    62 
    63 \section*{Coursework 3}
    63 \section*{Coursework 3}
    64 
    64 
    65 \noindent
    65 \noindent
    66 This coursework is worth 4\% and is due on 13 December at 16:00. You are asked to 
    66 This coursework is worth 4\% and is due on 13 December at 16:00. You are asked to 
    67 implement a compiler for the WHILE language which targets the
    67 implement a compiler for the WHILE language that targets the
    68 assembler language provided by the Jasmin. This assembler 
    68 assembler language provided by the Jasmin. This assembler 
    69 is available from
    69 is available from
    70 
    70 
    71 \begin{center}
    71 \begin{center}
    72 \url{http://jasmin.sourceforge.net}
    72 \url{http://jasmin.sourceforge.net}
    88 
    88 
    89 \noindent
    89 \noindent
    90 
    90 
    91 
    91 
    92 \noindent
    92 \noindent
    93 You need to submit a document containing the answers for the questions 
    93 You need to submit a document containing the answers for the two questions 
    94 below. You can do the implementation in any programming language you like, but you need 
    94 below. You can do the implementation in any programming language you like, but you need 
    95 to submit the source code with which you answered the questions. However, the coursework 
    95 to submit the source code with which you answered the questions. However, the coursework 
    96 will \emph{only} be judged according to the answers. You can submit your answers
    96 will \emph{only} be judged according to the answers. You can submit your answers
    97 in a txt-file or as pdf.\bigskip
    97 in a txt-file or as pdf.\bigskip
    98 
    98 
   149 \end{lstlisting}
   149 \end{lstlisting}
   150 \end{minipage}
   150 \end{minipage}
   151 \end{center}
   151 \end{center}
   152 
   152 
   153 
   153 
       
   154 \subsection*{Further Information}
       
   155 
       
   156 The Java infrastructure unfortunately does not contain an assembler out-of-the-box
       
   157 (therefore
       
   158 you need to download the additional package Jasmin---see above). But it does contain a 
       
   159 disassembler, called \texttt{javap}. A dissembler does the ``opposite'' of an assembler: it
       
   160 generates readable assembler code from Java Byte Code. Have a look at the
       
   161 following example. Compile using the usual Java compiler, 
       
   162 \texttt{java}, the simple Hello World program below:
       
   163 
       
   164 \begin{center}
       
   165 \begin{minipage}{10cm}
       
   166 \begin{lstlisting}[language=Java,basicstyle=\ttfamily]
       
   167 class HelloWorld {
       
   168     public static void main(String[] args) {
       
   169         System.out.println("Hello World!");
       
   170     }
       
   171 }
       
   172 \end{lstlisting}
       
   173 \end{minipage}
       
   174 \end{center}
       
   175 
       
   176 \noindent
       
   177 You can use the command
       
   178 
       
   179 \begin{center}
       
   180 \texttt{javap -v HelloWorld}
       
   181 \end{center}
       
   182 
       
   183 \noindent
       
   184 in order to see which Java Byte Code has been generated for this
       
   185 program. You can compare this with the code generated for the Scala
       
   186 version of Hello Worlds.
       
   187 
       
   188 \begin{center}
       
   189 \begin{minipage}{10cm}
       
   190 \begin{lstlisting}[language=Scala,basicstyle=\ttfamily]
       
   191 object HelloWorld {
       
   192    def main(args: Array[String]) {
       
   193       println("Hello World!")
       
   194   }
       
   195 }
       
   196 \end{lstlisting}
       
   197 \end{minipage}
       
   198 \end{center}
       
   199 
   154 
   200 
   155 \end{document}
   201 \end{document}
   156 
   202 
   157 %%% Local Variables: 
   203 %%% Local Variables: 
   158 %%% mode: latex
   204 %%% mode: latex