Compilers (CS362 2002F)

Pseudo Assembly Language


Summary: In today's lab, you will explore PAL, the pseduo-assembly language that I've written (okay, started to write) as an intermediate language for your compilers.

Warning: Both PAL and this lab are under development. Both probably have many bugs. Let me know which ones you notice.

Collaboration: Feel free to work on this lab in pairs or trios.

Turning It In: Save your answers in a plain text file and submit it using the ECA.

Grading: I expect that you will gain more from doing this lab than from me grading this lab. I may simply scan through your answers to see if you had any particularly valuable insights.

Supporting Files:


1. Make copies of and

2. Make a copy of the pal library in a directory on your $CLASSPATH. For example, you could execute the following two instructions.

% cp -r /home/rebelsky/Web/Courses/CS362/2002F/Examples/pal .
% export CLASSPATH="`pwd`:$CLASSPATH"


PAL, the pseudo-assembly language, is a set of Java classes intended to provide a simple assembly-language-like intermediate code. PAL consists of a model of a computer, Computer, a number of Container subclasses that hold values, and a number of Instruction implementations that represent instructions.

The Computer class provides four key methods.

Each Container subclass provides four key procedures:

There are many kinds of containers.

Instructions provide one key method,

As you may have noted, a number of the methods take Computer objects as parameters. I've made that choice so that they can access or modify the state of the computer.

PAL provides an ever-growing set of instructions which you can identify by looking at the source code.

Note that the InstructionSequence instruction is a special instruction designed for building trees of instructions, as you would create while traversing a parse tree.


Exercise 1: PAL Basics

a. Scan through See if you can determine what it does.

b. Compile and execute Observe its output.

c. Why was the program able to use FWrite on t1? What was the output?

d. Turn off program tracing and execute the program again.

e. Update to count down from 5 to 1 (instead of up from 1 to 10).

Exercise 2: A Sum Program

a. Scan through As you can see, the program repeatedly reads values and shoves them on the stack. When 0 is entered, it repeatedly pops values off of the stack and adds them to the counter.

b. Run the program and enter three non-zero values followed by zero. Does it do what you expect?

c. Add an instruction to print the stack pointer at each step and rerun the program with three non-zero values. Does it do what you expect? When you're done observing the stack pointer, you can either keep or remove the line to print the stack pointer.

d. Run the program and enter seven non-zero values followed by zero. What does it do? WHy?

e. Run the program and enter five non-zero values followed by zero. What does it do? Why?

f. Run the program and enter four non-zero values followed by zero. What does it do? Why?

Exercise 3: Your Own PAL Program

Write a PAL program that reads three numbers, initial, step, and final, and counts (by printing results) from initial to final using increments of step.

Exercise 4: Extending PAL

Add new FMultiply and IMultiply instructions to PAL.



Monday, 18 November 2002 [Samuel A. Rebelsky]

  • Designed.

Tuesday, 19 November 2002 [Samuel A. Rebelsky]

  • Wrote.
  • Released.


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 10 08:53:34 2002.
The source to the document was last modified on Tue Nov 19 09:08:41 2002.
This document may be found at

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Glimmer Labs: The Grinnell Laboratory for Interactive Multimedia Experimentation & Research