aboutsummaryrefslogtreecommitdiff
path: root/sem6/dig/mpc2/opgaver.tex
blob: 74aba7d078d93f4431fa20e7159900dcb8ab4d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
\title{Opgaver til Microprocessors 2}
\date{2021-03-24}

Har fundet ud af at jeg har lavet de forkerte opgaver \texttt{:-(}.

\section{Problem 4.1}

\begin{opg}
    What are the four steps CPUs use to execute instructions
\end{opg}

\paragraph{Fetch} comes first, where the instruction is fetched from memory.
This is taken from where the instruction pointer is pointing.

\paragraph{Decode} instruction, where it most likely requires multiple microcode instructions.

Whether to \textbf{Access memory} is determined in the decoding step.
If this is required, this memory must be fetched from memory.

\paragraph{Execute} the instruction using the fetched memory and register values.

\paragraph{Repeat} from the beginning with a new fetch.

\section{Problem 4.2}

\emph{In Fig. 4-6, the B bus register is encoded in a 4-bit field, but the C bus is represented
as a bit map. Why?}

It is often wanted to save the result from the ALU in multiple destination registers.
Therefore one cannot take the shortcut with a 4-bit field, as that would only allow one save at the time.

One cannot present 1 and 2 at the same time in 4-bit field, as that would activate register 3.

\section{Problem 4.4}

{\itshape
    Suppose that in the example of Fig. 4-14(a) the statement
\begin{verbatim}
    k = 5;
\end{verbatim}
    is added after the if statement. What would the new assembly code be? Assume that
    the compiler is an optimizing compiler.
}

Well k is set either way, so one can invert the if.

\begin{verbatim}
    ILOAD j
    ILOAD k
    IADD
    BIPUSH 3
    IF_ICMPEQ L1
    ILOAD j
    BIPUSH 1
    ISUB
    ISTORE j
    L1: BIPUSH 5
    ISTORE k
\end{verbatim}

\section{Problem 4.4 Moodle}

\begin{opg}
    Give two different IJVM translations for the following IJVM code:
\begin{verbatim}
    i = j + m + 8;
\end{verbatim}
\end{opg}

Dette kan man gøre ved at load $j$ og $m$ fra stacken og add dem.
Derefter kan push 8 og add den.
Herefter gemmer man i $i$.

\begin{verbatim}
    ILOAD j
    ILOAD m
    IADD
    BIPUSH 8
    IADD
    ISTORE i
\end{verbatim}

En anden måde er at push alle ting først også add flere gange efter hinnanden.

\begin{verbatim}
    ILOAD j
    ILOAD m
    BIPUSH 8
    IADD
    IADD
    ISTORE i
\end{verbatim}

\section{Problem 4.9}

{\itshape
    How long does a 2.5-GHz Mic-1 take to execute the Java statement
\begin{verbatim}
    i = j + k;
\end{verbatim}
    Give your answer in nanoseconds
}

First we "compile" the java statement :-).

\begin{verbatim}
    ILOAD j
    ILOAD k
    IADD
    ISTORE i
\end{verbatim}

Then we can add how many microinstructions each takes (\textbf{bold} number) multiplied with how many times it is used.

\[
\underbrace{\mathbf 1 \cdot 4}_{\mathrm{MAIN}} + \underbrace{\mathbf 5 \cdot 2}_{\mathrm{ILOAD}} + \underbrace{\mathbf 3}_{\mathrm{IADD}} + \underbrace{\mathbf 6}_{\mathrm{ISTORE}} = 23
\]

Then we can multiply with the nanoseconds a single instruction takes
\[
    \frac 1 {\SI{2.5e9}{Hz}} \cdot 23 = \SI{9.2e-9}{s}\,,
\]
which is 9.2 Nanoseconds.