\section{Assemblers}

\subsubsection{Overview}
Assemblers in MLRISC satisfy the signature 
\mlrischref{emit/instruction-emitter.sig}{INSTRUCTION\_EMITTER},
which is defined as:
\begin{SML}
signature INSTRUCTION_EMITTER =
sig
   structure I : \href{instructions.html}{INSTRUCTIONS}
   structure C : \href{cells.html}{CELLS}
   structure S : \href{streams.html}{INSTRUCTION_STREAM}
   structure P : \href{pseudo-ops.html}{PSEUDO_OPS}
      sharing I.C = C
      sharing S.P = P

   val makeStream : Annotations.annotations ->
                     ((int -> int) -> I.instruction -> unit,
                      unit,'b,'c,'d,'e) S.stream
end
\end{SML}

The function \sml{makeStream} returns an instruction stream.
By default the output is bound to the stream \sml{AsmStream.asmOutStream} 
defined in the structure 
\mlrischref{emit/asmStream.sml}{AsmStream} at creation time.

The structure \sml{AsmStream} satisfy the following signature.
\begin{SML}
signature ASM_STREAM = sig
  val asmOutStream : TextIO.outstream ref
  val withStream : TextIO.outstream -> ('a -> 'b) -> 'a -> 'b
end
\end{SML}
\subsubsection{Redirecting the Output}
It is possible to redirect the output of an instruction stream.
For example, the following statement
\begin{SML}
   val asm = makeStream []
\end{SML}
binds the output of \sml{asm} to \sml{AsmStream.asmOutStream}, which
by default is just \sml{TextIO.stdOut}.  On the other hand, the
statement
\begin{SML}
   val asm = AsmStream.withStream mystream makeStream []
\end{SML}
binds the output of asm to \sml{mystream}.

\subsubsection{More Details}

Assemblers are automatically generated by the 
\href{mlrisc-md.html}{MDGen} tool.  Some specific generated
assemblers are listed below:
\begin{enumerate}
 \item \mlrischref{sparc/emit/sparcAsm.sml}{Sparc}
 \item \mlrischref{hppa/emit/hppaAsm.sml}{Hppa}
 \item \mlrischref{alpha/emit/alphaAsm.sml}{Alpha}
 \item \mlrischref{ppc/emit/ppcAsm.sml}{Power PC}
 \item \mlrischref{x86/emit/x86Asm.sml}{X86}
\end{enumerate}
