Skip to content
2 changes: 1 addition & 1 deletion xml/chapter4/section1/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function is_falsy(x) {
<JAVASCRIPTINLINE>x !== x</JAVASCRIPTINLINE> yields true is the value
<JAVASCRIPTINLINE>NaN</JAVASCRIPTINLINE> (<QUOTE>Not a Number</QUOTE>),
<INDEX>NaN, not a typo</INDEX>
which is considered to be a falsy number (also not a typo), along with~0.
which is considered to be a falsy number (also not a typo), along with<SPACE/>0.
The numerical value
<JAVASCRIPTINLINE>NaN</JAVASCRIPTINLINE> is the result of certain
arithmetic border cases such as
Expand Down
6 changes: 2 additions & 4 deletions xml/chapter5/chapter5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@
will describe processes in terms of the step-by-step
operation of a traditional computer. Such a computer, or
<INDEX>register machine</INDEX>
<EM>
register machine</EM>, sequentially executes
<EM>register machine</EM>, sequentially executes
<EM>instructions</EM> that
manipulate the contents of a fixed set of storage elements called
<INDEX>register(s)</INDEX>
<EM>
registers</EM>. A typical register-machine instruction applies a
<EM>registers</EM>. A typical register-machine instruction applies a
primitive operation to the contents of some registers and assigns the
result to another register. Our descriptions of processes executed by
register machines will look very much like <QUOTE>machine-language</QUOTE>
Expand Down
27 changes: 17 additions & 10 deletions xml/chapter5/section1/section1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<SECTIONCONTENT/>

<LABEL NAME="sec:designing-register-machines"/>

<INDEX>register machine<SUBINDEX>design of<OPEN/></SUBINDEX></INDEX>
<INDEX>register machine<SUBINDEX>data paths<OPEN/></SUBINDEX></INDEX>
<INDEX>register machine<SUBINDEX>controller<OPEN/></SUBINDEX></INDEX>
Expand All @@ -18,8 +19,9 @@
machine, let us examine Euclid<APOS/>s Algorithm, which is used to compute
<INDEX><USE>gcd</USE><SUBINDEX>register machine for<OPEN/></SUBINDEX></INDEX>
the greatest common divisor (GCD) of two integers. As we saw in
section<SPACE/><REF NAME="sec:gcd"/>,
<INDEX>Euclid<APOS/>s Algorithm</INDEX>
section<SPACE/><REF NAME="sec:gcd"/>, Euclid<APOS/>s Algorithm can be
Euclid<APOS/>s Algorithm can be
carried out by an iterative process, as specified by the following
<SPLITINLINE>
<SCHEME>procedure:</SCHEME>
Expand Down Expand Up @@ -70,10 +72,11 @@ function gcd(a, b) {
</TEXT>

<TEXT>
We can illustrate the registers and operations required for this
machine by using the
<INDEX>data paths for register machine<SUBINDEX>data-path diagram</SUBINDEX></INDEX>
<INDEX>register machine<SUBINDEX>data-path diagram</SUBINDEX></INDEX>
We can illustrate the registers and operations required for this
machine by using the data-path diagram shown in
data-path diagram shown in
figure<SPACE/><REF NAME="fig:gcd-machine"/>. In this
diagram, the registers (<SCHEMEINLINE>a</SCHEMEINLINE>,
<SCHEMEINLINE>b</SCHEMEINLINE>, and <SCHEMEINLINE>t</SCHEMEINLINE>) are
Expand Down Expand Up @@ -106,10 +109,10 @@ function gcd(a, b) {
constants to the box, and arrows connect the operation<APOS/>s output value
to registers. A test is represented by a circle containing a name for the
test. For example, our GCD machine has an operation that tests whether the
contents of register <SCHEMEINLINE>b</SCHEMEINLINE> is zero. A test also
has arrows from its input
contents of register <SCHEMEINLINE>b</SCHEMEINLINE> is zero. A
<INDEX>test operation in register machine</INDEX>
<INDEX>register machine<SUBINDEX>test operation</SUBINDEX></INDEX>
test also has arrows from its input
registers and constants, but it has no output
arrows; its value is used by the controller rather than by the data
paths. Overall, the data-path diagram shows the registers and
Expand All @@ -126,11 +129,12 @@ function gcd(a, b) {
</TEXT>

<TEXT>
<INDEX>register machine<SUBINDEX>controller diagram</SUBINDEX></INDEX>
<INDEX>controller for register machine<SUBINDEX>controller diagram</SUBINDEX></INDEX>
In order for the data paths to actually compute GCDs, the buttons must
be pushed in the correct sequence. We will describe this sequence in
terms of a controller diagram, as illustrated in
terms of a
<INDEX>register machine<SUBINDEX>controller diagram</SUBINDEX></INDEX>
<INDEX>controller for register machine<SUBINDEX>controller diagram</SUBINDEX></INDEX>
controller diagram, as illustrated in
figure<SPACE/><REF NAME="fig:gcd-controller"/>. The elements of the
controller diagram indicate how the data-path components should be operated.
The rectangular boxes in the controller diagram identify data-path buttons
Expand All @@ -151,18 +155,20 @@ function gcd(a, b) {
<SCHEMEINLINE>b</SCHEMEINLINE>. When the controller reaches
<SCHEMEINLINE>done</SCHEMEINLINE>, we will find the value of the GCD in
register <SCHEMEINLINE>a</SCHEMEINLINE>.
<INDEX><USE>gcd</USE><SUBINDEX>register machine for<CLOSE/></SUBINDEX></INDEX>
<FIGURE>
<FIGURE scale_factor="5" src="img_original/Fig5.2.std.svg"/>
<LABEL NAME="fig:gcd-controller"/>
<CAPTION>Controller for a GCD machine.</CAPTION>
</FIGURE>
</TEXT>

<INDEX><USE>gcd</USE><SUBINDEX>register machine for<CLOSE/></SUBINDEX></INDEX>

<EXERCISE>
<LABEL NAME="ex:iterative-fact"/>
Design a register machine to compute
<INDEX><USE>factorial</USE><SUBINDEX>register machine for (iterative)</SUBINDEX></INDEX>
Design a register machine to compute factorials using the iterative
factorials using the iterative
algorithm specified by the following
<SPLITINLINE>
<SCHEME>procedure.</SCHEME>
Expand Down Expand Up @@ -194,6 +200,7 @@ function factorial(n) {
</JAVASCRIPT>
</SNIPPET>
</EXERCISE>

<INDEX>data paths for register machine<CLOSE/></INDEX>
<INDEX>controller for register machine<CLOSE/></INDEX>
<INDEX>register machine<SUBINDEX>data paths<CLOSE/></SUBINDEX></INDEX>
Expand Down
67 changes: 48 additions & 19 deletions xml/chapter5/section1/subsection1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</NAME>

<LABEL NAME="sec:register-machine-language"/>

<INDEX>register machine<SUBINDEX>language for describing<OPEN/></SUBINDEX></INDEX>

<TEXT>
Expand Down Expand Up @@ -34,29 +35,31 @@
<TEXT>
We define the controller of a machine as a sequence of
<INDEX>register-machine language<SUBINDEX>instructions</SUBINDEX></INDEX>
<EM>
instructions</EM> together with
<EM>instructions</EM> together with
<INDEX>register-machine language<SUBINDEX>label</SUBINDEX></INDEX>
<EM>labels</EM> that identify
<INDEX>register-machine language<SUBINDEX>entry point</SUBINDEX></INDEX>
<EM>labels</EM> that identify <EM>entry
points</EM> in the sequence. An instruction is one of the following:
<EM>entry points</EM> in the sequence. An instruction is one of the following:
<UL>
<LI>
The name of a data-path button to push to assign a value to
a register. (This corresponds to a box in the controller diagram.)
<INDEX>register-machine language<SUBINDEX><USE>test</USE></SUBINDEX></INDEX>
</LI>
<LI>
A
<INDEX><USE>test</USE> (in register machine)</INDEX>
A <SCHEMEINLINE>test</SCHEMEINLINE> instruction, which performs a
<INDEX>register-machine language<SUBINDEX><USE>test</USE></SUBINDEX></INDEX>
<SCHEMEINLINE>test</SCHEMEINLINE>
instruction, which performs a
specified test.
</LI>
<LI>
A
<INDEX>register-machine language<SUBINDEX><USE>branch</USE></SUBINDEX></INDEX>
<INDEX><USE>branch</USE> (in register machine)</INDEX>
<INDEX>register-machine language<SUBINDEX><USE>label</USE></SUBINDEX></INDEX>
<INDEX><USE>label</USE> (in register machine)</INDEX>
A conditional branch (<SCHEMEINLINE>branch</SCHEMEINLINE> instruction)
conditional branch (<SCHEMEINLINE>branch</SCHEMEINLINE> instruction)
to a location indicated by a controller label, based on the result of
the previous test. (The test and branch together correspond to a
diamond in the controller diagram.) If the test is false, the
Expand All @@ -65,6 +68,7 @@
the label.
</LI>
<LI>
An
<SPLITINLINE>
<SCHEME>
<INDEX>register-machine language<SUBINDEX><ORDER>goto</ORDER><SCHEMEINLINE>goto</SCHEMEINLINE></SUBINDEX></INDEX>
Expand All @@ -75,7 +79,7 @@
<INDEX><USE>go_to</USE> (in register machine)</INDEX>
</JAVASCRIPT>
</SPLITINLINE>
An unconditional branch
unconditional branch
<SPLITINLINE>
<SCHEME>(<SCHEMEINLINE>goto</SCHEMEINLINE></SCHEME>
<JAVASCRIPT>(<JAVASCRIPTINLINE>go_to</JAVASCRIPTINLINE></JAVASCRIPT>
Expand Down Expand Up @@ -313,8 +317,9 @@ function controller_sequence(controller) {
</TEXT>

<EXERCISE>
Use the register-machine language to describe the
<INDEX><USE>factorial</USE><SUBINDEX>register machine for (iterative)</SUBINDEX></INDEX>
Use the register-machine language to describe the iterative factorial
iterative factorial
machine of exercise<SPACE/><REF NAME="ex:iterative-fact"/>.
<LABEL NAME="ex:iterative-fact-2"/>
</EXERCISE>
Expand Down Expand Up @@ -364,10 +369,12 @@ function controller_sequence(controller) {
</TEXT>

<TEXT>
<INDEX><USE>prompt</USE> operation in register machine</INDEX>
<SPLITINLINE>
<SCHEME><SCHEMEINLINE>Read</SCHEMEINLINE></SCHEME>
<JAVASCRIPT>The operation <JAVASCRIPTINLINE>prompt</JAVASCRIPTINLINE>
<JAVASCRIPT>
The operation
<INDEX><USE>prompt</USE> operation in register machine</INDEX>
<JAVASCRIPTINLINE>prompt</JAVASCRIPTINLINE>
</JAVASCRIPT>
</SPLITINLINE>
is like the operations we have been using in that it produces a value that
Expand All @@ -394,10 +401,12 @@ function controller_sequence(controller) {
</TEXT>

<TEXT>
<INDEX><USE>display</USE> operation in register machine</INDEX>
<SPLITINLINE>
<SCHEME><SCHEMEINLINE>Print</SCHEMEINLINE>,</SCHEME>
<JAVASCRIPT>The operation <JAVASCRIPTINLINE>display</JAVASCRIPTINLINE>,
<JAVASCRIPT>
The operation
<INDEX><USE>display</USE> operation in register machine</INDEX>
<JAVASCRIPTINLINE>display</JAVASCRIPTINLINE>,
</JAVASCRIPT>
</SPLITINLINE>
on the other hand, differs from the operations we have
Expand All @@ -410,9 +419,9 @@ function controller_sequence(controller) {
Arrows point to the action box from any inputs (registers or
constants). We also associate a button with the action. Pushing the
button makes the action happen. To make a controller push an action
button we use a new kind of instruction called
<INDEX>register-machine language<SUBINDEX><USE>perform</USE></SUBINDEX></INDEX>
<INDEX><USE>perform</USE> (in register machine)</INDEX>
button we use a new kind of instruction called
<SCHEMEINLINE>perform</SCHEMEINLINE>. Thus,
the action of printing the contents of register
<SCHEMEINLINE>a</SCHEMEINLINE> is represented
Expand All @@ -438,8 +447,25 @@ perform(list(op("display"), reg("a")))
</SPLITINLINE>
shows the data paths and controller for
the new GCD machine. Instead of having the machine stop after
printing the answer, we have made it start over, so that it repeatedly
reads a pair of numbers, computes their GCD, and prints the result.
<SPLITINLINE>
<SCHEME>
printing
</SCHEME>
<JAVASCRIPT>
displaying
</JAVASCRIPT>
</SPLITINLINE>
the answer, we have made it start over, so that it repeatedly
reads a pair of numbers, computes their GCD, and
<SPLITINLINE>
<SCHEME>
prints
</SCHEME>
<JAVASCRIPT>
displays
</JAVASCRIPT>
</SPLITINLINE>
the result.
This structure is like the driver loops we used in the interpreters of
chapter<SPACE/>4.
<!-- % (registers a b t) (operations read = rem print) -->
Expand Down Expand Up @@ -527,8 +553,11 @@ const gcd_with_prompt_controller =
</FIGURE>
</JAVASCRIPT>
</SPLIT>
<INDEX>register machine<SUBINDEX>language for describing<CLOSE/></SUBINDEX></INDEX>
<INDEX>actions, in register machine<CLOSE/></INDEX>
<INDEX>register machine<SUBINDEX>actions<CLOSE/></SUBINDEX></INDEX>
</TEXT>

<INDEX>register machine<SUBINDEX>language for describing<CLOSE/></SUBINDEX></INDEX>
<INDEX>actions, in register machine<CLOSE/></INDEX>
<INDEX>register machine<SUBINDEX>actions<CLOSE/></SUBINDEX></INDEX>


</SUBSECTION>
5 changes: 4 additions & 1 deletion xml/chapter5/section1/subsection2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ const gcd_elaborated_controller =
</TEXT>

<EXERCISE>
Design a machine to compute
<INDEX><USE>sqrt</USE><SUBINDEX>register machine for</SUBINDEX></INDEX>
Design a machine to compute square roots using Newton<APOS/>s method, as
square roots using Newton<APOS/>s method, as
described in section<SPACE/><REF NAME="sec:sqrt"/> and implemented with the following code in section<SPACE/><REF NAME="sec:block-structure"/>:
<SNIPPET>
<REQUIRES>square_definition</REQUIRES>
Expand Down Expand Up @@ -209,5 +210,7 @@ function sqrt(x) {
definition in the register-machine language.
<LABEL NAME="ex:sqrt-machine"/>
</EXERCISE>

<INDEX>abstraction<SUBINDEX><ORDER>register</ORDER>in register-machine design<CLOSE/></SUBINDEX></INDEX>

</SUBSECTION>
16 changes: 11 additions & 5 deletions xml/chapter5/section1/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</NAME>

<LABEL NAME="sec:subroutines"/>

<INDEX>register machine<SUBINDEX>subroutine<OPEN/></SUBINDEX></INDEX>
<INDEX>subroutine in register machine<OPEN/></INDEX>

Expand Down Expand Up @@ -310,16 +311,18 @@ after-gcd-2
</TEXT>

<TEXT>
<INDEX><USE>assign</USE> (in register machine)<SUBINDEX>storing label in register</SUBINDEX></INDEX>
<INDEX><USE>go_to</USE> (in register machine)<SUBINDEX>destination in register</SUBINDEX></INDEX>
To reflect this ability, we will extend the
<INDEX><USE>assign</USE> (in register machine)<SUBINDEX>storing label in register</SUBINDEX></INDEX>
<SCHEMEINLINE>assign</SCHEMEINLINE>
instruction of the register-machine language to allow a register to be
assigned as value a label from the controller sequence (as a special
kind of constant). We will also extend the
<SPLITINLINE>
<SCHEME><SCHEMEINLINE>goto</SCHEMEINLINE></SCHEME>
<JAVASCRIPT><JAVASCRIPTINLINE>go_to</JAVASCRIPTINLINE></JAVASCRIPT>
<JAVASCRIPT>
<INDEX><USE>go_to</USE> (in register machine)<SUBINDEX>destination in register</SUBINDEX></INDEX>
<JAVASCRIPTINLINE>go_to</JAVASCRIPTINLINE>
</JAVASCRIPT>
</SPLITINLINE>
instruction to allow execution to continue at the entry point described by
the contents of a register rather than only at an entry point described by
Expand All @@ -346,7 +349,10 @@ after-gcd-2
not know where to go when it is finished. The mechanism developed in the
next section to handle recursion also provides a better solution to this
problem of nested subroutine calls.
<INDEX>register machine<SUBINDEX>subroutine<CLOSE/></SUBINDEX></INDEX>
<INDEX>subroutine in register machine<CLOSE/></INDEX>
</TEXT>

<INDEX>register machine<SUBINDEX>subroutine<CLOSE/></SUBINDEX></INDEX>
<INDEX>subroutine in register machine<CLOSE/></INDEX>


</SUBSECTION>
Loading