\documentclass[12pt]{article}

\usepackage{fullpage,amsmath,amsfonts,html}

\begin{document}

\title{Basics of Information Systems}
\author{Winter Semester 2022--23}
\date{For discussion on Wednesday, December 14, 2022}
\maketitle

\begin{enumerate}
\item Recall the ``simple language'' from class, which has
non-negative integer variables, the statements \texttt{incr(X)} and
\texttt{decr(X)}, as well as while loops of the form
\begin{verbatim}
while(X):
    loop body
\end{verbatim}
In class, we looked at a macro $\mathtt{Y} \leftarrow \mathtt{X}$
which assigns the value of \texttt{X} to \texttt{Y}, while setting
\texttt{X} to zero.  Modify this example so that the end of the
operation, \texttt{X} retains its original value.

\item Write a RISC-V assembly program, and run it on the simulator
\begin{quote}
  \url{https://www.cs.cornell.edu/courses/cs3410/2019sp/riscv/interpreter/}
\end{quote}
which computes the difference $797-930$ and stores the result into
memory location 0x00000000.

\emph{Hint:} \texttt{sub rd, rs1, rs2} computes $\texttt{rd} \gets
\texttt{rs1} - \texttt{rs2}$.

% addi x5, x0, 797
% addi x6, x0, 930
% sub x7, x5, x6
% sw x7, 0(x0)

\item Write a RISC-V assembly program which stores the maximum of the
integers in registers \texttt{x5} and \texttt{x6} into register
\texttt{x7}, then store the result into memory location 0x00000000.

Test this program on the simulator for two examples with different
order of the given register values.

\emph{Hint:} \texttt{blt rs1, rs2, i} will execute the branch
instruction $\mathtt{if\ rs1} < \mathtt{rs2: pc} \gets \mathtt{pc}
+ \mathtt{i}$.  Note that \texttt{i} must be a multiple of $4$.  To
jump one instruction, you need to use $\mathtt{i}=8$.

% addi x5, x0, 797
% addi x6, x0, 930
% sub x7, x5, x6
% sw x7, 0(x0)


\item Write a RISC-V assembly program, and run it on the simulator,
that computes the product of two numbers, $3$ and $7$, say, by
repeated addition and stores the result into memory location
0x00000000.

% addi x5, x0, 3
% addi x6, x0, 7
% addi x6, x6, -1
% add x7, x0, x5
% add x5, x5, x7
% addi x6, x6, -1
% blt x0, x6, -8
% sw x5, 0(x0)

\end{enumerate}
\end{document}
