GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing sicp.sourceacademy.org — 5.2 A Register-Machine Simulator - SICP Comparison Edition
SICP — Scheme/JS
Structure and Interpretation of Computer Programs — Comparison Edition
Permalink copied!
5.2 A Register-Machine Simulator
In order to gain a good understanding of the design of register machines, we must test the machines we design to see if they perform as expected. One way to test a design is to hand-simulate the operation of the controller, as in exercise 5.5. But this is extremely tedious for all but the simplest machines. In this section we construct a simulator for machines described in the register-machine language. The simulator is a Scheme JavaScript program with four interface procedures. functions. The first uses a description of a register machine to construct a model of the machine (a data structure whose parts correspond to the parts of the machine to be simulated), and the other three allow us to simulate the machine by manipulating the model:
As an example of how these procedures functions are used, we can define gcd-machine gcd_machine to be a model of the GCD machine of section 5.1.1 as follows:
To compute GCDs with this machine, we set the input registers, start the machine, and examine the result when the simulation terminates:
5.2 A Register-Machine Simulator
| ||||||||||||||||||||
| You are visitor 01402639 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |