\documentstyle[11pt]{article}
% frob with the margins
\addtolength{\topmargin}{-1in}
\addtolength{\footskip}{-1in}
\addtolength{\textheight}{2in}
\addtolength{\oddsidemargin}{-.5in}
\addtolength{\evensidemargin}{-.5in}
\addtolength{\textwidth}{1in}
% no page numbers
\pagestyle{empty}
% counter for page numbers
\newcounter{pg}
\setcounter{pg}{2}

% DEFINE THE PROBLEM SET NUMBER
\def\psnum{6}

% title command
\newcommand{\mytitle}[1]{\begin{center} {\Large Computation Structures -- 
6.004 Problem Set \psnum \\ Juliet Bourne -- #1} \\ \vspace{-.1in} 
\rule{6in}{.5mm} \end{center}}
% problem command
\newcommand{\prob}[1]{\vspace{.15in}\noindent{\fbox{\large\bf Problem #1}}}
% subproblem command
\newcommand{\subprob}[1]{\vspace{.15in} \noindent{\large\bf #1.}}
% equations commands
\newcommand{\beq}{\vspace*{-.3in}\begin{eqnarray*}}
\newcommand{\eeq}{\end{eqnarray*}}
% newpage setup command 
\newcommand{\mynewpage}{\newpage\noindent
\begin{center}
{\Large 6.004 Problem Set \psnum -- Juliet Bourne -- {\bf Page \thepg}}
\rule{6in}{.5mm}
\end{center}
\addtocounter{pg}{1}}
% see-page command
\newcommand{\seepage}{\noindent See page \rule{.2in}{.1mm} for the
computer output.}

\begin{document}

\mytitle{10/31/90}

\prob{1: {\em Lab 5 Pre-lab}}

\subprob{A}  \verb+Word(0x6004) --> 000001000  01100000+ 

\subprob{B} (All numbers after \verb+-->+ are in hex.)
\begin{verbatim}
sc4(3)        	--> 06 00 03 00 00
sc4(fib)      	--> 06 00 11 00 00
scall(4)	--> 30 04 00
shalt		--> 00
shalt		--> 00
shalt		--> 00
shalt		--> 00
slaa(0)		--> 02 00 00
sl4		--> 0E
sc4(2)		--> 06 00 02 00 00
scmp4		--> 1A
sc4(tiny)	--> 06 __ __ __ __  (whatever address tiny is at)
sjlo		--> 2E
slaa(0)		--> 02 00 00
sl4		--> 0E
...
\end{verbatim}

\subprob{C} The argument to \verb+salloc+ is a word, which is 16 bits, one
of which is a sign bit. Therefore the highest value is $2^{15} - 1$.

\subprob{D} The POP4 macro calls the microsubroutine \verb+pop4+ , which in
turn calls \verb+get4+, another microsubroutine. \verb+get4+ calls the
microsubroutine \verb+getdatum+ , which doesn't call any other
microsubroutines.

\subprob{E} PC = 0x5C ; SP = 0x58 ; B = 32 = 0x20

\subprob{F} After \verb+scmp4+ SP = 0x0F3E - 8 + 4 = 0x0F3A.  The result
will be at 0x0F3A - 4 = 0x0F36.

\subprob{G} The result will be on the top of the stack, after \verb+srtn4+
pushes the value onto the stack.

\subprob{H}
\vspace*{.5in}

\subprob{I}
\vspace*{.5in}

\subprob{J} The numeric value used to initialize the S machine is 7.

\mynewpage

\subprob{K} The MAYBE dispatches on the command from the HP. It calls
\verb+tinit+ which calls \verb+MInit+ (initialization state of the MAYBE),
clears the instruction execution count, and returns to the terminal loop
waiting for a command from the HP.

\prob{2: {\em Conditional Nanocode}}

\subprob{A} 

\begin{verbatim}
|                C    A       M    I
|                o    D ALU  Co    nS DR  LD   |
|  OPCODE  CLOK  n == R FUNC id N  h/ SEL SEL  | COMMENTS
| 76543210 3210  d    + 3210 ne C  bL 210 210  |

| min(x, y, z)
  11110001 0000 *  =  1 1111 11 1  11 001 101  | MAR <- uROM; ADR+
  11110001 0001 *  =  0 1111 11 1  11 100 010  | A <- SRAM
  11110001 0010 *  =  1 1111 11 1  11 001 101  | MAR <- uROM; ADR+
  11110001 0011 *  =  0 1111 11 1  11 100 011  | B <- SRAM
  11110001 0100 *  =  0 0110 10 1  00 010 011  | B <- A-B-1, latch CCs
  11110001 0101 *  =  0 1111 11 1  01 100 011  | B <- SRAM, shift CCs
  
| A > B (i.e. x > y)
  11110001 0110 0  =  1 1111 11 1  11 001 101  | MAR <- uROM; ADR+
  11110001 0111 0  =  0 1111 11 1  11 011 100  | SRAM <- B
  11110001 1000 0  =  1 1111 11 1  11 001 000  | OPCODE <- uROM; ADR+

| B >= A 
  11110001 0110 1  =  1 1111 11 1  11 001 101  | MAR <- uROM; ADR+
  11110001 0111 1  =  0 1111 11 1  11 010 100  | SRAM <- A
  11110001 1000 1  =  1 1111 11 1  11 001 000  | OPCODE <- uROM; ADR+
\end{verbatim}

\subprob{B} \verb+ .macro min(x,y,z) 0xF1 x y z +

\prob{3: {\em Stack Conventions}}

\subprob{A}

\mynewpage

\subprob{B}
\vspace*{1.5in}

\subprob{C}
\vspace*{1.5in}

\subprob{D}
\vspace*{1.5in}

\prob{4: {\em Writing S-Machine Code}}

\subprob{A} 4 recursive calls to \verb+reverse+, with arguments:
\begin{verbatim}
*S = ``cerrotni'', n = 5 
*S = ``errctni'', n = 3
*S = ``rectni'', n = 1
*S = ``ectni'', n = -1
\end{verbatim}

\subprob{B} \verb+ *S -> correctni +

\mynewpage

\subprob{C}
\begin{verbatim}
reverse:	salloc(1)		| local variable TEMP
		slaa(1)  sl4		| fetch n
		sc4(0)   scmp4		| compare with 0
		sc4(no)  sjle		| jump to ``no'' if n<=0
		
		slla(0)			| fetch address of TEMP
		slaa(0)  sl4		| fetch address of S[0]
		sl1			| fetch <S[0]>
		ss1			| TEMP <- <S[0]>

		slaa(0)  sl4		| address of S[0]
		slaa(0)	 sl4		| address of S[0]
		slaa(1)  sl4		| n
		sc4(1)   ssub4		| n - 1
		sadd4			| address of S[n-1] 
		sl1			| <S[n-1]>
		ss1			| S[0] <- <S[n-1]>

		slaa(0)  sl4		| address of S[0]
		slaa(1)  sl4		| n
		sc4(1)   ssub4		| n - 1
		sadd4			| address of S[n-1]
		slla(0)  sl1		| <TEMP>
		ss1			| S[n-1] <- <TEMP>

		slaa(0)  sl4		| address of S[0]
		sc4(1)   sadd4		| address of S[1] (S + 1)
		slaa(1)  sl4		| n 
		sc4(2)   ssub4		| n - 2
		sc4(reverse) scall(8)   | reverse(S+1, n-2)

no:		srtn
\end{verbatim}

\subprob{D} 0x00000410

\subprob{E} 0x1031

\subprob{F}

\end{document}


