17 compiling a WHILE-program? |
17 compiling a WHILE-program? |
18 |
18 |
19 \item What is the main difference between the Java assembler |
19 \item What is the main difference between the Java assembler |
20 (as processed by Jasmin) and Java Byte Code? |
20 (as processed by Jasmin) and Java Byte Code? |
21 |
21 |
|
22 \item Remember symbolic labels in the Jasmin-assembler are meant to |
|
23 be used for jumps (like in loops or if-conditions). Assume |
|
24 you generated a Jasmin-file with some redundant |
|
25 labels, that is some labels are not used in your code for any jumps. For |
|
26 example \texttt{L\_begin} and \texttt{L\_end} are not used |
|
27 in the fol,lowing code-snippet: |
|
28 |
|
29 \begin{lstlisting}[language=JVMIS,numbers=none] |
|
30 L_begin: |
|
31 ldc 1 |
|
32 ldc 2 |
|
33 ldc 3 |
|
34 imul |
|
35 ldc 4 |
|
36 ldc 3 |
|
37 isub |
|
38 iadd |
|
39 iadd |
|
40 L_end: |
|
41 \end{lstlisting} |
|
42 |
|
43 Do these redundant labels affect the size of the generated |
|
44 JVM-code? (Hint: What are the labels translated to by |
|
45 the Jasmin-assembler?). |
|
46 |
|
47 \solution{The answer is no. The reason is that assemblers |
|
48 calculate for labels either relative or explicit adresses, |
|
49 which are then used in the JVM-byte-code. Relative addresses |
|
50 are like ``jump 10 bytes forward'' or ``12 bytes backward''. So |
|
51 additional labels do not increase the size of the generated code.} |
|
52 |
|
53 |
22 \item Consider the following Scala snippet. Are the two functions |
54 \item Consider the following Scala snippet. Are the two functions |
23 \texttt{is\_even} and \texttt{is\_odd} tail-recursive? |
55 \texttt{is\_even} and \texttt{is\_odd} tail-recursive? |
24 |
56 |
25 \begin{lstlisting}[numbers=none] |
57 \begin{lstlisting}[numbers=none] |
26 def is_even(n: Int) : Boolean = { |
58 def is_even(n: Int) : Boolean = { |