% 1997 Fall, Midterm exam for V22.0201.002

\documentclass{article}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\topmargin}{-.5in}
\setlength{\textwidth}{6.1in}
\setlength{\textheight}{8.5in}
\def\baselinestretch{1.6}
\newcommand{\pts}[1]{{\bf\ (#1 POINTS)\\}}

\newenvironment{tightlist}[1]{
\begin{list}{#1}{
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\parsep}{0in}
\setlength{\parskip}{0in}
\setlength{\itemsep}{0in}
}
}{\end{list}}


\begin{document}
\begin{center}
\large
Yap \hfill    V22.0201.002, Computer Systems Organization I  \hfill        Fall 1997\\
\end{center}
\begin{center}
\Large
MIDTERM EXAM\\
\large
For full credit show all rough work and justify all answers.
\\
% Write directly on the exam.
You are allowed 2 pages (=1 sheets) of 8.5''x11'' set of notes.
\end{center}

\normalsize

% \def\baselinestretch{1.8}
\begin{enumerate}

\item
\pts{10}
Name the three kinds of buses.

% \vskip 1.in

\item
\pts{5}
The ALU is found in:
\begin{enumerate}
\item The bus interface unit
\item The memory unit
\item The CPU
\item None of the above
\end{enumerate}

\item
\pts{5+5}
(a) How many kilobytes are there in a segment? 
\\
(b) What is the offset of the physical address
0ABCDEh in the segment whose number is 9FF9h?
% ANS: (a) 64, (b) 0AC4Eh

\item
\pts{5+5+5}
\\ (a)
Convert 0BADh to binary.
\\ (b)
Convert 101010b to decimal.
\\ (c)
Convert 698d to hexadecimal.

\item
\pts{5+5}
Suppose we use 6 bits to represent signed numbers.
Answer in decimal notation.
\begin{enumerate}
\item What is the largest positive number that can be represented?
\item What number does the bit pattern $110100$ represent? 
\end{enumerate}

% ans: 2^5 -1 = 31.
% ans: -16
% \pagebreak

\item
\pts{10}
Which of the following 7 names are valid in our Assembler?
\begin{verbatim}
    _here_, 1and2, my.val, isn't_it?, yap@nyu, %$?, Johnson&Johnson
\end{verbatim}
% Ans: _here_, yap@nyu, %$?

\item
\pts{5+5}
Assume a program has the following declarations at the beginning of the
data segment, i.e. at offset 0000h.
\begin{tightlist}{}
\item \verb+    var1  DB  20d+
\item \verb+    var2  DW 0ABCDh, 3 dup (?)+
\item \verb+    var3  DW 'ABCD'+
\end{tightlist}
(a) What is the offset of \verb+var3+?
\\
(b) What is in register AX after the execution of the following:
\\
	\verb+     mov AX, WORD PTR var1+
% Ans: (a) 7, (b) 0AB14h.

\item
\pts{25}
Write a code fragment to compute the sum $1+2+3+\cdots+n$
where $n$ is an input number in register DL.  The output
should be register DH.  Note that
$n$ is non-negative and if $n=0$, the output should be $0$.
You must use the LOOP instruction to solve this.

% \newpage

\item
\pts{30}
Write a complete assembly language program to print
the contents of register BH in hexadecimal.  ``Complete'' means
the program will run after assembling and linking.  Please
follow the following outline:
\begin{verbatim}
	0. Move any value (say, 97d) into BH
		(you can change this value each time you assemble the program).
	1. Move BH to DL.
	2. Shift DL 4 times to the right.
	3. If DL<10, then convert it to characters in '0',...,'9' (by adding 30h).
	4. If DL>=10, then convert it to characters in 'A',...,'F' (by adding 41h).
	5. Output the character in DL (using function 2, INT 21h).
	6. Move BH to DL.
	7. Clear the high order 4 bits of DL.
	8. Do one more time: steps 3 to 5.
\end{verbatim}

\end{enumerate}
\end{document}

