boppi/doc/report-problems.tex

15 lines
1.3 KiB
TeX
Raw Normal View History

2017-07-21 09:38:24 +00:00
% Problems and solutions. Summary of problems you encountered and how you solved them (max. two
% pages).
\subsection{Function calls within parameters}
Each function call requires an AR. When new ARs are allocated at a static offset relative to the current AR, this may lead to problems with function calls of the form \verb|f(g(h))| or \verb|f(a, g(h))|: the AR of \verb|f| must not be overwritten during the call to \verb|g|. There are multiple solutions to this problem:
\begin{enumerate}
\item dynamically allocating the AR (requires a dynamic allocator)
\item generating different offsets for nested function calls (e.g. the AR of \verb|h| in \verb|f(g(h()))| must be allocated at \verb|ARP+f_AR+g_AR|)
\item allocating the AR after evaluating its parameters (requires a temporary storage for the parameters)
\end{enumerate}
The third option was chosen, namely by pushing each parameter value to the stack, then allocating the AR for the outer function call and popping the values into it.
\subsection{Register saves}
When calling a function, some registers must be saved by the caller or callee in order to not lose their value when executing the callee. The choice was made to use caller-saves and to keep track of all the registers that are required for future instructions.