|
@@ -1425,7 +1425,7 @@ next example. Figure~\ref{fig:p1-x86} lists an x86 program that is
|
|
|
equivalent to \code{(+ 52 (- 10))}. This program uses a region of
|
|
|
memory called the \emph{procedure call stack} (or \emph{stack} for
|
|
|
short). \index{stack}\index{procedure call stack} The stack consists
|
|
|
-of a separate \emph{frame} for each procedure call.\index{frame} The
|
|
|
+of a separate \emph{frame}\index{frame} for each procedure call. The
|
|
|
memory layout for an individual frame is shown in
|
|
|
Figure~\ref{fig:frame}. The register \key{rsp} is called the
|
|
|
\emph{stack pointer}\index{stack pointer} and points to the item at
|
|
@@ -2356,9 +2356,9 @@ In the process of assigning variables to stack locations, it is
|
|
|
convenient to compute and store the size of the frame (in bytes) in
|
|
|
the $\itm{info}$ field of the \key{Program} node, with the key
|
|
|
\code{stack-space}, which will be needed later to generate the
|
|
|
-procedure conclusion. Some operating systems place restrictions on
|
|
|
-the frame size. For example, Mac OS X requires the frame size to be a
|
|
|
-multiple of 16 bytes.
|
|
|
+procedure conclusion. The x86-64 standard requires the frame size to
|
|
|
+be a multiple of 16 bytes.
|
|
|
+\index{frame}
|
|
|
|
|
|
\begin{exercise}
|
|
|
\normalfont Implement the \key{assign-homes} pass and test it on all
|
|
@@ -6897,13 +6897,14 @@ The register \code{rax} is for the return value of the function.
|
|
|
|
|
|
\index{prelude}\index{conclusion}
|
|
|
|
|
|
-Regarding (2) frames and the procedure call stack, recall from
|
|
|
-Section~\ref{sec:x86} that the stack grows down, with each function
|
|
|
-call using a chunk of space called a frame. The caller sets the stack
|
|
|
-pointer, register \code{rsp}, to the last data item in its frame. The
|
|
|
-callee must not change anything in the caller's frame, that is,
|
|
|
-anything that is at or above the stack pointer. The callee is free to
|
|
|
-use locations that are below the stack pointer.
|
|
|
+Regarding (2) frames \index{frame} and the procedure call stack
|
|
|
+\index{procedure call stack}, recall from Section~\ref{sec:x86} that
|
|
|
+the stack grows down, with each function call using a chunk of space
|
|
|
+called a frame. The caller sets the stack pointer, register
|
|
|
+\code{rsp}, to the last data item in its frame. The callee must not
|
|
|
+change anything in the caller's frame, that is, anything that is at or
|
|
|
+above the stack pointer. The callee is free to use locations that are
|
|
|
+below the stack pointer.
|
|
|
|
|
|
Recall that we are storing variables of vector type on the root stack.
|
|
|
So the prelude needs to move the root stack pointer \code{r15} up and
|
|
@@ -7031,6 +7032,7 @@ approach, a recursive function that only makes tail calls will only
|
|
|
use $O(1)$ stack space. Functional languages like Racket typically
|
|
|
rely heavily on recursive functions, so they typically guarantee that
|
|
|
all tail calls will be optimized in this way.
|
|
|
+\index{frame}
|
|
|
|
|
|
However, some care is needed with regards to argument passing in tail
|
|
|
calls. As mentioned above, for arguments beyond the sixth, the
|