\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.
