|
@@ -747,7 +747,7 @@ following grammar.
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
-\chapter{Integers and Variables}
|
|
|
+\chapter{Compiling Integers and Variables}
|
|
|
\label{ch:int-exp}
|
|
|
|
|
|
This chapter concerns the challenge of compiling a subset of Racket,
|
|
@@ -906,7 +906,7 @@ called \emph{registers}, and instructions may load and store values
|
|
|
into \emph{memory}. Memory is a mapping of 64-bit addresses to 64-bit
|
|
|
values. Figure~\ref{fig:x86-a} defines the syntax for the subset of
|
|
|
the x86-64 assembly language needed for this chapter. (We use the
|
|
|
-AT\&T syntax that is expected by the GNU assembler inside \key{gcc}.)
|
|
|
+AT\&T syntax expected by the GNU assembler inside \key{gcc}.)
|
|
|
|
|
|
An immediate value is written using the notation \key{\$}$n$ where $n$
|
|
|
is an integer.
|
|
@@ -915,23 +915,20 @@ A register is written with a \key{\%} followed by the register name,
|
|
|
such as \key{\%rax}.
|
|
|
%
|
|
|
An access to memory is specified using the syntax $n(\key{\%}r)$,
|
|
|
-which reads register $r$, obtaining address $a$, and then offsets the
|
|
|
-address by $n$ bytes (8 bits), producing the address $a + n$. The
|
|
|
-address is then used to either load or store to memory depending on
|
|
|
-whether it occurs as a source or destination argument of an
|
|
|
-instruction.
|
|
|
+which reads register $r$ and then offsets the address by $n$ bytes (8
|
|
|
+bits). The address is then used to either load or store to memory
|
|
|
+depending on whether it occurs as a source or destination argument of
|
|
|
+an instruction.
|
|
|
|
|
|
-An arithmetic instruction, such as $\key{addq}\,s\,d$, reads from the
|
|
|
+An arithmetic instruction, such as $\key{addq}\,s,\,d$, reads from the
|
|
|
source $s$ and destination $d$, applies the arithmetic operation, then
|
|
|
-write the result in $d$. So the \key{addq} instruction computes $d
|
|
|
-\gets d + s$.
|
|
|
+write the result in $d$.
|
|
|
%
|
|
|
The move instruction, $\key{movq}\,s\,d$ reads from $s$ and stores the
|
|
|
result in $d$.
|
|
|
%
|
|
|
The $\key{callq}\,\mathit{label}$ instruction executes the procedure
|
|
|
-specified by the label, which we shall use to implement
|
|
|
-\key{read}.
|
|
|
+specified by the label.
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
|
\fbox{
|
|
@@ -980,11 +977,11 @@ that the operating system can call it. The label \key{\_main:}
|
|
|
indicates the beginning of the \key{\_main} procedure which is where
|
|
|
the operating system starting executing this program. The instruction
|
|
|
\lstinline{movq $10, %rax} puts $10$ into register \key{rax}. The
|
|
|
- following instruction \lstinline{addq $32, %rax} adds $32$ to the
|
|
|
- $10$ in \key{rax} and puts the result, $42$, back into
|
|
|
- \key{rax}. The instruction \key{retq} finishes the \key{\_main}
|
|
|
- function by returning the integer in the \key{rax} register to the
|
|
|
- operating system.
|
|
|
+following instruction \lstinline{addq $32, %rax} adds $32$ to the
|
|
|
+$10$ in \key{rax} and puts the result, $42$, back into
|
|
|
+\key{rax}. The instruction \key{retq} finishes the \key{\_main}
|
|
|
+function by returning the integer in \key{rax} to the
|
|
|
+operating system.
|
|
|
|
|
|
|
|
|
\begin{wrapfigure}{r}{2.25in}
|