You will test your SLIM programs using the Super Lean Instruction
Machine Emulator (SLIME).
The authors of our textbook have made SLIME available as this Java
Archive (jar) file:
SLIME.jar, which you should
download to your machine.
Note: Depending on your browser, you may get a warning about
downloading and executing files like this. In general, you may
want to avoid downloading jar files from sources you do not trust.
In order to run
SLIME.jar, Java
must be installed on your machine.
- You can determine if you have Java installed by opening a
command window on your machine and executing:
java -version
- If Java is not installed, you can get it by going to the
Oracle JDK Download Page. Download the
compressed folder appropriate for your operating system and extract
(uncompress) its contents. The java command is in the bin folder.
-
Linux and Mac users may have to
set or change the PATH system variable
- On some operating systems, you may be able to run a jar file
(such as SLIME.jar) simply by
double-clicking its file icon.
- Otherwise, you will need to open a terminal console window and execute
the command:
java -jar SLIME.jar
As the SLIME homepage describes, SLIME can be run either as:
- A Java applet within your browser, or
- A Java application launched from your desktop
Running SLIME as a Java applet within your browser requires you to
enter SLIM code directly into the text window labeled "
SLIME 1.1
applet," as shown to the right.
It is more convenient to
cut-and-paste code already written into the
SLIME applet.
NOTE: If cut-and-paste does not work in your browser,
you must modify your Java security policy as described in the SLIME
homepage.
After entering the code into the applet, load the code into SLIM by
clicking the
Load button.
Another way to run SLIME is as a Java application, independently of
your browser.
In this case, you manually launch SLIME from your desktop, as described
on the SLIME homepage.
NOTE for this to work, the Java Runtime Environment
(JRE) must be installed on your machine.
- You can determine if you have the JRE installed by opening a
command window on your machine and executing:
java -version
- If the JRE is not installed, you can get it by going to the
Oracle OpenJDK download page
Once the SLIME application is launched, click the
Load button
and you can choose a file with SLIM code to be loaded.
Upon running
SLIME.jar, two windows appear:
- A window titled "SLIME 1.1" showing SLIM's program
counter, registers, control buttons, etc.
- For controlling SLIM's execution and observing its state
- A smaller window titled "SLIM Console" with blank areas
- For entering input into SLIM and observing its output
This section describes using SLIME to run the
write-larger
program:
allocate-registers input-1, input-2
allocate-registers comparison, jump-target
read input-1
read input-2
sge comparison, input-1, input-2
li jump-target, input-2-larger
jeqz comparison, jump-target
write input-1
halt
input-2-larger: ; an instruction label, referring to the
write input-2 ; write input-2 instruction
halt
SLIME allows you to:
- Run SLIM programs
- Step through programs (to help debugging)
- Observe the state of registers
- Observe the state of memory
Clicking
Step will cause one SLIM instruction to be executed.
In our example, since the first instruction is
a
read,
Step causes the SLIM console to wait for input.
Here is the console after the user has entered
17:
After the user has entered 17 in the console, SLIME will increment the
PC (program counter) by one and highlight (but not execute) the next
instruction.
Note that register 0 contains the value 17:
If the user
Steps again and enters -25 into the console, SLIME's interface will
look like this:
To run the SLIM program without stepping through instructions, click
the
Start button.
In our example, the registers containing 17 (register 0) and -25
(register 1) are compared, and since 17 > -25, the contents of
register 0 are written to the console (instruction 5):
Processing then halts after instruction 6:
To run the program again (perhaps to try different input values), first
click
Reset, which will:
- Clear the registers
- Set the PC to 0
- Clear the instruction counter
To clear previous input and output values from the SLIM console,
click
Clear Console.
To quit SLIME, click Quit, which dismisses both windows.