As discussed in section 1.10,
the main interpreter loop decodes the first word of the interpreter
using the first byte as an operation code,
and places the second byte,
in register 3.
The subop may be used to index the display,
as a small constant,
or to indicate one of several relational operators.
In the cases where a constant is needed, but it
is not small enough to fit in the byte sub-operator,
a zero is placed there and the constant follows in the next word.
Zero is easily tested for,
as the instruction which places the
subop in r3 sets the condition code flags,
and this condition code is still available after the transfer
to an operation code sequence.
A construction like
is all that is needed to effect this packing of data.
This technique saves a great deal of space in the Pascal
Table 2.1 gives the codes used in the instruction descriptions
to indicate the kind of inline data expected by each instruction.
l | l
ci | aw(3.25i).
Table 2.1 \- Inline data type codes
An address offset is given in the word
following the instruction.
An index into the display, ready as an offset or a guaranteeably small integer,
is given in the sub-operation code.
A relational operator encoded as described
in section 2.3 is given in the subop.
A small integer is
placed in the subop, or in the next word
if it is zero or too large.
Variable length inline data.
A word value in the following word.
An inline constant string.
Before giving a list of the machine opcodes,
it is useful to note the naming conventions in the interpreter for typed
Machine instructions which have numeric operands use a simple and uniform
naming convention in which a suffix on the root operation name indicates
the type of operands expected.
These are given in Table 2.2.
Here the expression ``a above b'' means that `a' is on top of the
stack with `b' below it.
Short integers are 2 byte integers,
and long integers are 4 byte integers.
c s s
c s s
l l l
c ap-2 a.
Table 2.2 \- Operator Suffices
Unary operator suffices
Suffix Example Argument type
2 NEG2 Short integer
4 SQR4 Long integer
8 ABS8 Real
c s s
l l l
c ap-2 a.
Binary operator suffices
Suffix Example Argument type
2 ADD2 Two short integers
24 MUL24 Short above long integer
42 REL42 Long above short integer
4 DIV4 Two long integers
28 DVD28 Short integer above real
48 REL48 Long integer above real
82 SUB82 Real above short integer
84 MUL84 Real above long integer
c s s
l l l
c ap-2 a.
Suffix Example Argument types
T ADDT Sets
G RELG Strings
We now give the list of machine operations with a reference
to the appropriate sections and a short description of each.
The character `*' at the end of a name indicates that all
operations with the root prefix before the `*' are summarized by
the one entry.
c s s
lw(14) | lw(12) | lw(40)
lp-2 | a | l.
Table 2.3 \- Machine operations
Mnemonic Reference Description
This operator is used to halt execution immediately with an IOT process
It is used only for debugging
and is never generated by the translator
Corresponds to the Pascal procedure
.I halt ;
causes execution to terminate with a post-mortem backtrace as if a run-time
error had occurred.
Causes the second part of the block mark to be created, and
bytes of local variable space to be allocated and cleared to zero.
Stack overflow is detected here.
is the first line of the body of this section for error traceback,
and he inline string (length 8) the character representation of its name.
.SM BEG ,
and used to begin the main program when the ``p''
option is disabled so that the post-mortem backtrace will be inhibited.
Complementary to the operators
.SM BEG ,
exits the current block, calling the procedure
to flush buffers for and release any local files.
Restores the environment of the caller from the block mark.
If this is the end for the main program, all files are
the profile data file is written if necessary, and
which prints the statistics if desired (and does not return) is called.
Saves the current line number, return address, and active display entry pointer
in the first part of the block mark, then transfers to the entry point
given by the relative address
.I a ,
which is the beginning of a
bytes on the stack for, e.g., the return value of a
just before calling the function.
bytes off the stack.
Used, e.g., after a
returns to remove the arguments from the stack.
Transfer control to relative address
as a local
or part of a structured statement.
Set current line number to
For consistency, check that the expression stack is empty
as it should be (as this is the start of a statement.)
This consistency check will fail only if there is a bug in the
interpreter or the interpreter code has somehow been damaged.
Increment the statement count and if it exceeds the statement limit,
generate a fault.
Transfer conrol to address
which is in the block at level
of the display.
This is a non-local
Causes each block to be exited as if with
.SM END ,
flushing and freeing files with
until the current display entry is at level
Duplicate the one word integer on the top of
This is used mostly for constructing sets.
See section 2.11.
The interpreter conditional transfers all take place using this operator
which examines the Boolean value on the top of the stack.
If the value is
.I true ,
the subsequent code is executed,
otherwise control transfers to the specified address.
These take two arguments on the stack,
and the sub-operation code indicates which relational operation is to
be performed, coded as follows with `a' above `b' on the stack:
0 a = b
2 a <> b
4 a < b
6 a > b
8 a <= b
10 a >= b
Each operation does a number of tests to set the condition code
appropriately and then does an indexed branch based on the
sub-operation code to a test of the condition here specified,
pushing a Boolean value on the stack.
Consider the statement fragment:
\*bif\fR a = b \*bthen\fR
are integers this generates the following code:
IF \fIElse part offset\fR
\fI\&... Then part code ...\fR
The Boolean operators
.SM AND ,
.SM OR ,
manipulate values on the top of the stack.
All Boolean values are kept in single bytes in memory,
or in single words on the stack.
Zero represents a Boolean \fIfalse\fP, and one a Boolean \fItrue\fP.
The rvalue operators load values on the stack.
They take a block number as a subop and load the appropriate
number of bytes from that block at the offset specified
in the following word onto the stack. As an example, consider
.SM RV4 :
Here the interpreter first generates the source address in r0 by adding the
display entry to the offset in the next instruction word.
It then reserves a long integer space on the stack (4 bytes)
and moves the data from the source onto the stack.
The pseudo-operation ``return''
takes the interpreter back to the main interpreter loop.
Note that the sub-operation code is already in
r3 and multiplied by 2 to be immediately usable as a word index
into the display.
The constant operators load a value onto the stack from inline code.
Small integer values are condensed and loaded by the
operator, which is given by
Here note that little work was required as the required constant
had already been placed in register 3.
For longer constants, more work is required;
takes a length specification in the subop and can be used to load
strings and other variable length data onto the stack.
The assignment operators are similar to arithmetic and relational operators
in that they take two operands, both in the stack,
but the lengths given for them indicate
first the length of the value on the stack and then the length
of the target in memory.
The target address in memory is under the value to be stored.
Thus the statement
i := 1
is a full-length, 4 byte, integer,
will generate the code sequence
will load the address of
which is actually given as a block number in the subop and an
offest in the following word,
onto the stack, occupying a single word.
.SM CON1 ,
which is a single word instruction,
then loads the constant 1,
which is in its subop,
onto the stack.
Since there are not one byte constants on the stack,
this becomes a 2 byte, single word integer.
The interpreter then assigns a length 2 integer to a length 4 integer using
.SM AS24 \&.
The code sequence for
is given by:
Thus the interpreter gets the single word off the stack,
extends it to be a 4 byte integer in two registers,
gets the target address off the stack,
and finally stores the parts of the value in the target.
This is a typical use of the constant and assignment operators.
The most common operation performed by the interpreter
is the ``lvalue'' or ``address of'' operation.
It is given by:
It calculates an address in the block specified in the subop
by adding the associated display entry to the
offset which appears in the following word.
The offset operator is used in field names.
Thus to get the address of
would generate the sequence
loads the value of
given its block in the subop and offset in the following word,
and the interpreter then adds the offset of the field
in its record to get the correct address.
takes its argument in the subop if it is small enough.
The example above is incomplete, lacking a check for a
The code generated would, in fact, be
operation checks for a
pointer and generates the appropriate runtime error if it is.
For example, the statement
a[i] := 2.0
a short integer, such as a subrange ``1..1000'',
``array [1..1000] of real''
operation takes the address of
and places it on the stack.
The value of
is then placed on top of this on the stack.
We then perform an indexing of the array address by the
length 2 index (a length 4 index would use
.SM INX4 )
where the individual elements have a size of 8 bytes.
The code for
Here the index operation subtracts the constant value 1 from the
this being the low bound of the range of permissible subscripts.
If the result is negative,
or if the normalized subscript then exceeds 999, which
is the maximum permissible subscript if the first is numbered 0,
the interpreter generates a subscript error.
Otherwise, the interpreter multiplies the offset by 8 and adds it to the address
which is already on the stack for
.I a ,
to address ``a[i]''.
Multi-dimension subscripts are translated as a sequence of single subscriptings.
For indirect references through
parameters and pointers,
the interpreter has a set of indirection operators which convert a pointer
on the stack into a value on the stack from that address.
operators are necessary because of the possibility of different
The interpreter has a large number of arithmetic operators.
All operators produce results long enough to prevent overflow
unless the bounds of the base type are exceeded.
No overflow checking is done on arithmetic, but divide by zero
and mod by zero are detected.
The interpreter has a number of range checking operators.
The important distinction among these operators is between values whose
legal range begins at 0 and those which do not begin at 0, i.e. with
a subrange variable whose values range from 45 to 70.
For those which begin at 0, a simpler ``logical'' comparison against
the upper bound suffices.
For others, both the low and upper bounds must be checked independently,
requiring two comparisons.
The interpreter includes three operators for
statements which are used depending on the width of the
For each width, the structure of the case data is the same, and
is represented in the following figure.
case statement operators do a sequential search through the
case label values.
If they find the label value, they take the corresponding entry
from the transfer table and cause the interpreter to branch to the
If the specified label is not found, an error results.
operators take the number of cases as a subop
Three different operators are needed to handle single byte,
word, and double word case transfer table values.
For example, the
operator has the following code sequence:
Here the interpreter first computes the address of the beginning
of the case label value area by adding twice the number of case label
values to the address of the transfer table, since the transfer
table entries are full word, 2 byte, address offsets.
It then searches through the label values, and generates an ECASE
error if the label is not found.
If the label is found, we calculate the index of the entry in
the transfer table which is desired and then add that offset
to the interpreter location counter.
For the purpose of execution profiling the following operations
Causes the interpreter to allocate a count buffer
counters, each of which is a 4 byte integer,
and to clear the counters to 0.
The count buffer is placed within an image of the
file as described in the
.I "PXP Implementation Notes."
The contents of this buffer will be written to the file
when the program terminates.
Increments the counter specified by
Used at the entry point to procedures and functions,
combining a transfer to the entry point of the block with
an incrementing of its entry count.
The set operations
and the set relationals
The following operations are more interesting.
Takes the cardinality of a set of size
bytes on top of the stack, leaving a 2 byte integer count.
uses a table of 4-bit population counts to count set bits
in each 4-bit nibble of each byte in the set.
Constructs a set.
This operation requires a non-trivial amount of work,
checking bounds and setting individual bits or ranges of bits.
This operation sequence is very slow,
and motivates the presence of the operator
The arguments to
include the number of elements
in the constructed set,
the lower and upper bounds of the set,
and a pair of values on the stack for each range in the set, single
elements in constructed sets being duplicated with
to form degenerate ranges.
specifies the size of the set,
values the lower and upper bounds of the set.
The value on the stack is checked to be in the set on the stack,
and a Boolean value of
replaces the operands.
on a constructed set without constructing it.
The left operand of
is on top of the stack followed by the number of pairs in the
and then the pairs themselves, all as single word integers.
Pairs designate runs of values and single values are represented by
a degenerate pair with both value equal.
A typical situation for this operator to be generated is
\fBif\fR ch \fBin\fR ['+', '-', '*', '/']
\fBif\fR ch \fBin\fR ['a'..'z', '$', '_']
These situations are very common in Pascal, and
makes them run much faster in the interpreter,
as if they were written as an efficient series of
Other miscellaneous operators which are present in the interpreter
which causes termination if the Boolean value on the stack is not
.SM STOI ,
.SM STOD ,
.SM ITOD ,
which convert between different length arithmetic operands for
use in aligning the arguments in
calls, and with some untyped built-ins, such as
.SM COS \&.
Finally, if the program is run with the run-time testing disabled, there
are special operators for
and special indexing operators for arrays
which have individual element size which is a power of 2.
The code can run significantly faster using these operators.
has a large number of built-in procedures and functions.
The mathematical functions are taken from the standard
The linear congruential random number generator is described in
.I "Berkeley Pascal User Manual"
are included here but currently ignored.
One surprise is that the built-ins
are here and quite complex, functioning as a memory to memory
move with a number of semantic checks.
They do no ``unpacking'' or ``packing'' in the true sense, however,
as the interpreter supports no packed data types.