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
|
\mytitle{The Last Homework of the Term}{\co}
Now that the term is coming to an end, I am seeing the last couple of
assignments that are being handed out. This week, we had no quiz, but we did
have a homework assignment, and I expect us to have the final exam next week.
The homework assignment was another MARIE-centric assignment, but featured new
questions that we haven't seen yet. The first two questions were complex
questions which asked us to understand the memory architecture of fundamental
types, and find various pieces of information about their characteristics;
including the number of bits required to represent them, maximum and minimum
values, and more.
Following that, we had a couple familiar questions that we have seen before, but
in more complex programs, as well as a questions which asked us to draw
flow-charts for the programs that we have written, without using any condition
logic or branching.
\smallskip
\begin{tikzpicture}[node distance=2.5cm]
\node
(start)
[draw, rectangle, text centered, minimum width=2cm, minimum height=1cm]
{Start};
\node
(loadx)
[draw, rectangle, text centered, right of=start, minimum width=2cm, minimum height=1cm]
{Load X};
\node
(addx)
[draw, rectangle, text centered, right of=loadx, minimum width=2cm, minimum height=1cm]
{Add X};
\node
(addx2)
[draw, rectangle, text centered, right of=addx, minimum width=2cm, minimum height=1cm]
{Add X};
\node
(addy)
[draw, rectangle, text centered, below of=addx2, minimum width=2cm, minimum height=1cm]
{Add Y};
\node
(increment)
[draw, rectangle, text centered, left of=addy, minimum width=2cm, minimum height=1cm]
{Increment};
\node
(storey)
[draw, rectangle, text centered, left of=increment, minimum width=2cm, minimum height=1cm]
{Store Y};
\node
(stop) [draw, rectangle, text centered, minimum width=2cm, minimum height=1cm, left of=storey]
{Stop};
\draw [->] (start) -- (loadx);
\draw [->] (loadx) -- (addx);
\draw [->] (addx) -- (addx2);
\draw [->] (addx2) -- (addy);
\draw [->] (addy) -- (increment);
\draw [->] (increment) -- (storey);
\draw [->] (storey) -- (stop);
\end{tikzpicture}
\smallskip
The final result looks a little bit like this, with some extra implementation
for the increment subroutine.
Finally, we had to implement a program which would take two input for two positive numbers, each
less than 20, and output the absolute value of the difference between the second number subtracted
from the first number. I'm not going to write all that out here, since it involves a length of
conditional logic, but it essentially is just a manual implementation of any standard absolute value
function (\verb|abs(first - second)|).
Within the same program, we had to implement a subroutine that would multiply these two numbers
together. This was tenfold faster to implement since it just requires a looping portion which
decrements one of the numbers every iteration that it adds the other number to the accumulator,
finally storing the result in one of the values.
Reimplemented in C, that would look something like this:
\begin{lstlisting}[language=c]
int multiply(int first, int second) {
/* Initialize the result to 0. */
int result = 0;
/* While the second number is greater than 0, add
* the first number to the result and decrement
* the second number by 1. */
while (second > 0) {
/* Add the first number to the result. */
result += first;
/* Decrement the second number by 1. */
second -= 1;
}
/* Return the result (first * second). */
return result;
}
\end{lstlisting}
If you have dealt with Riemann sums in calculus before, the above function in C
can be expressed as a Riemann sum, where the function is the first number, the
interval is the second number, and the number of rectangles is the second
number, or vice versa.
\begin{equation}
\sum_{n=1}^{first}(second)
\end{equation}
Riemann sums are essentially the \verb|for| loops of calculus.
As a final evaluation, I would give this assignment a ten-out-of-ten for being a
very in-depth assignment, while still being doable for most of the students.
|