\section{Calling Convention}

Programs and functions implementing this instruction set, should implement the following calling conventions. The register usage should be done as stated in table~\ref{tab:callcon}. If the callee should be given more than five parameters, other parameters should be passed over by the stack.

\begin{table}[ht]
	\centering
	\begin{tabular}{|c|c|c|} \hline
		\textbf{register} & \textbf{saved by} & \textbf{usage} \\ \hline
		r0       & caller   & return \\ \hline
		r1       & caller   & first parameter \\ \hline
		r2       & caller   & second parameter \\ \hline
		r3       & caller   & third parameter \\ \hline
		r4       & caller   & fourth parameter \\ \hline
		r5       & caller   & fifth parameter \\ \hline
		r6       & caller   & \\ \hline
		r7       & caller   & \\ \hline
		r8       & caller   & \\ \hline
		r9       & caller   & \\ \hline
		r10      & callee   & \\ \hline
		r11      & callee   & \\ \hline
		r12      & callee   & \\ \hline
		r13      & callee   & \\ \hline
		r14      & callee   & \\ \hline
		r15      & callee   & \\ \hline
	\end{tabular}
	\caption{Calling Convention}
	\label{tab:callcon}
\end{table}

\subsection{Assembler  Syntax}
\begin{itemize}
\item \textbf{Immediate s}: decimal \texttt{12345}, hex \texttt{0xabcde123},
binary \texttt{0b10101110}\\
If an immediate is to large for the given instruction the assembler terminates
with an error

\item \textbf{High and Low Half Word}: you can use the suffix \texttt{@hi} to
access the upper 16 bit of an immediate, or \texttt{@lo} to access the lower 16
bit.

\item \textbf{Memory access}: to access data on an address which is located in a
register, you have to write \texttt{0(rS)}. Alternatively you can specify
a signed displacement.

\item \textbf{Expressions}: Usual expressions like \texttt{+}, \texttt{-},
\texttt{*} or \texttt{<<} will be evaluated by the assembler, e.g. \texttt{ldw
r1, 0x20-8(r3)} is a valid instruction
\end{itemize}

\subsection{Directives}
In order to gain extra comfort, several directives are interpreted by the
assembler, a list is given in table~\ref{tab:asmdirs}.
\begin{table}[ht]
	\centering
	\begin{tabular}{|l|p{10cm}|} \hline
		\textbf{Name} & \textbf{Description} \\ \hline
		\texttt{.data} & subsequent data is desired for the data memory\\ \hline
		\texttt{.text} & subsequent code is desired for the instruction memory\\ \hline
		\verb+.include "file.s"+ & include a further file \\ \hline
		\texttt{.org \textit{addr}} & move \textit{forward} to a specific
		address in data or instruction memory, depending on the current
		section \\ \hline

		\texttt{.fill \textit{repeat}, \textit{size}, \textit{value}} & place a
		value of a specific size \texttt{\textit{repeat}}-times, while
		\texttt{\textit{repeat}} and \texttt{\texttt{size}} are optional.

		When one parameter is given, the value is placed at the current address.
		Note that a given value will be rounded up to a full byte, e.g.
		\texttt{0x123} occupy two bytes.

		When two parameters are given, the first equals \texttt{\textit{repeat}}
		and the second corresponds to \texttt{\textit{value}} \\ \hline

		\texttt{.define \textit{name}, \textit{value}} & define a constant. Note
		that a define isn't equal to a label\\ \hline

		\texttt{label: <instr/data>} & label an instruction or data. The label
		can be used as an alias for the address of this instruction in the
		instruction memory or as a reference in the data memory, depending on
		the current section\\ \hline
	\end{tabular}
	\caption{supported directives by the assembler}
	\label{tab:asmdirs}
\end{table}

