# HG changeset patch # User Christian Urban # Date 1447735994 0 # Node ID bf36664a31961850e06ead22627dea5104a8de6a # Parent 0e25fb72d339073ce768653a8b1f1edc706351b8 updated diff -r 0e25fb72d339 -r bf36664a3196 handouts/ho07.pdf Binary file handouts/ho07.pdf has changed diff -r 0e25fb72d339 -r bf36664a3196 handouts/ho07.tex --- a/handouts/ho07.tex Tue Nov 17 04:38:01 2015 +0000 +++ b/handouts/ho07.tex Tue Nov 17 04:53:14 2015 +0000 @@ -578,6 +578,23 @@ work harder and find out appropriate values for the stack and local variables. +To sum up, in Figure~\ref{test} is the complete code generated +for the slightly non-sensical program + +\begin{lstlisting}[mathescape,language=While] +x := 1 + 2; +write x +\end{lstlisting} + +\noindent Having this code at our disposal, we need the +assembler to translate the generated code into bytecode (a +class file) that can be understood by the JVM. + + +\begin{figure}[p] +\lstinputlisting{../progs/test-small.j} +\caption{Generated code for a test program.\label{test}} +\end{figure} \end{document} diff -r 0e25fb72d339 -r bf36664a3196 progs/test-small.j --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/test-small.j Tue Nov 17 04:53:14 2015 +0000 @@ -0,0 +1,29 @@ +.class public test.test +.super java/lang/Object + +.method public ()V + aload_0 + invokenonvirtual java/lang/Object/()V + return +.end method + +.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 +.end method + +.method public static main([Ljava/lang/String;)V + .limit locals 200 + .limit stack 200 + ldc 1 + ldc 2 + iadd + istore 0 + iload 0 + invokestatic test/test/write(I)V + return +.end method