isa: named it Deep Thought
[calu.git] / 2_isa / callingconv.tex
1 \section{Calling Convention}
2
3 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.
4
5 \begin{table}[ht]
6         \centering
7         \begin{tabular}{|c|c|c|} \hline
8                 register & saved by & usage  \\ \hline
9                 r0       & caller   & return \\ \hline
10                 r1       & caller   & first parameter \\ \hline
11                 r2       & caller   & second parameter \\ \hline
12                 r3       & caller   & third parameter \\ \hline
13                 r4       & caller   & fourth parameter \\ \hline
14                 r5       & caller   & fifth parameter \\ \hline
15                 r6       & caller   & \\ \hline
16                 r7       & caller   & \\ \hline
17                 r8       & caller   & \\ \hline
18                 r9       & caller   & \\ \hline
19                 r10      & callee   & \\ \hline
20                 r11      & callee   & \\ \hline
21                 r12      & callee   & \\ \hline
22                 r13      & callee   & \\ \hline
23                 r14      & callee   & \\ \hline
24                 r15      & callee   & \\ \hline
25         \end{tabular}
26         \caption{Calling Convention}
27         \label{tab:callcon}
28 \end{table}
29
30 \subsection{Assembler  Syntax}
31 \begin{itemize}
32 \item \textbf{Immediate s}: decimal \texttt{12345}, hex \texttt{0xabcde123},
33 binary \texttt{0b10101110}\\
34 If an immediate is to large for the given instruction the assembler terminates
35 with an error
36
37 \item \textbf{High and Low Half Word}: you can use the suffix \texttt{@hi} to
38 access the upper 16 bit of an immediate, or \texttt{@lo} to access the lower 16
39 bit.
40
41 \item \textbf{Memory access}: to access data on an address which is located in a
42 register, you have to write \texttt{0(rS)}. Alternatively you can specify
43 a signed displacement.
44
45 \item \textbf{Expressions}: Usual expressions like \texttt{+}, \texttt{-},
46 \texttt{*} or \texttt{<<} will be evaluated by the assembler, e.g. \texttt{ldw
47 r1, 0x20-8(r3)} is a valid instruction
48 \end{itemize}
49
50 \subsubsection{Directives}
51 In order to gain extra comfort, several directives are interpreted by the
52 assembler, a list is given in table~\ref{tab:asmdirs}.
53 \begin{table}[ht]
54         \centering
55         \begin{tabular}{|l|p{10cm}|} \hline
56                 Name & Description \\ \hline
57                 \texttt{.data} & subsequent data is desired for the data memory\\ \hline
58                 \texttt{.text} & subsequent code is desired for the instruction memory\\ \hline
59                 \verb+.include "file.s"+ & include a further file \\ \hline
60                 \texttt{.define <name> <value>} & define a constant. Note that a define
61                 isn't equal to a label\\ \hline
62                 \texttt{label: <instr/data>} & label an instruction or data. The label
63                 can be used as an alias for the address of this instruction in the
64                 instruction memory or as a reference in the data memory, depending on
65                 the current section\\ \hline
66                 %TODO: those are maybe handy: .fill(
67                 %http://www.myri.com/scs/L3/doc/as_7.html#SEC85)
68         \end{tabular}
69         \caption{supported directives by the assembler}
70         \label{tab:asmdirs}
71 \end{table}
72