2.  Operations

2.1.  Naming conventions and operation summary

      Table 2.1 outlines the opcode typing convention. The expression ``a above b'' means that `a' is on top of the stack with `b' below it. Table 2.3 describes each of the opcodes. The character `*' at the end of a name specifies that all operations with the root prefix before the `*' are summarized by one entry. Table 2.2 gives the codes used to describe the type inline data expected by each instruction.

box center; c s s c s s c c c n ap-2 a. Table 2.1 - Operator Suffixes = Unary operator suffixes Suffix Example Argument type 2 NEG2 Short integer (2 bytes) 4 SQR4 Long integer (4 bytes) 8 ABS8 Real (8 bytes) _ c s s c c c n ap-2 a. Binary operator suffixes 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 8 ADD8 Two reals _ c s s c c c n ap-2 a. Other Suffixes Suffix Example Argument types T ADDT Sets G RELG Strings

box center; c s c | c ci | aw(3.25i). Table 2.2 - Inline data type codes _ Code Description = a T{
An address offset is given in the word following the instruction. T} _ A T{ An address offset is given in the four bytes following the instruction. T} _ l T{ An index into the display is given in the sub-opcode. T} _ r T{ A relational operator is encoded in the sub-opcode. (see section 2.3) T} _ s T{ A small integer is placed in the sub-opcode, or in the next word if it is zero or too large. T} _ v T{ Variable length inline data. T} _ w T{ A word value in the following word. T} _ W T{ A long value in the following four bytes. T} _ " T{ An inline constant string. T}

box center; c s s lw(14) | lw(12) | lw(40) lp-2 | a | l. Table 2.3 - Machine operations _ Mnemonic Reference Description =

ABS* 2.7 Absolute value ADD* 2.7 Addition AND 2.4 Boolean and ARGC 2.14 Returns number of arguments to current process ARGV 2.14 Copy specified process argument into char array AS* 2.5 Assignment operators ASRT 2.12 Assert true to continue ATAN 2.13 Returns arctangent of argument BEG s,W,w," 2.2,1.8 Write second part of block mark, enter block BUFF 3.11 Specify buffering for file "output" CALL l,A 2.2,1.8 Procedure or function call CARD s 2.11 Cardinality of set CASEOP* 2.9 Case statements CHR* 2.15 Returns integer to ascii mapping of argument CLCK 2.14 Returns user time of program CON* v 2.5 Load constant operators COS 2.13 Returns cos of argument COUNT w 2.10 Count a statement count point CTTOT s,w,w 2.11 Construct set DATE 2.14 Copy date into char array DEFNAME 3.11 Attach file name for program statement files DISPOSE 2.15 Dispose of a heap allocation DIV* 2.7 Fixed division DVD* 2.7 Floating division END 2.2,1.8 End block execution EOF 3.10 Returns true if end of file EOLN 3.10 Returns true if end of line on input text file EXP 2.13 Returns exponential of argument EXPO 2.13 Returns machine representation of real exponent FILE 3.9 Push descriptor for active file FLUSH 3.11 Flush a file FNIL 3.7 Check file initialized, not eof, synced FOR* a 2.12 For statements GET 3.7 Get next record from a file GOTO l,A 2.2,1.8 Non-local goto statement HALT 2.2 Produce control flow backtrace IF a 2.3 Conditional transfer IN s,w,w 2.11 Set membership INCT 2.11 Membership in a constructed set IND* 2.6 Indirection operators INX* s,w,w 2.6 Subscripting (indexing) operator ITOD 2.12 Convert integer to real ITOS 2.12 Convert integer to short integer LINO s 2.2 Set line number, count statements LLIMIT 2.14 Set linelimit for output text file LLV l,W 2.6 Address of operator LN 2.13 Returns natural log of argument LRV* l,A 2.5 Right value (load) operators LV l,w 2.6 Address of operator MAX s,w 3.8 Maximum of top of stack and w MESSAGE 3.6 Write to terminal MIN s 3.8 Minimum of top of stack and s MOD* 2.7 Modulus MUL* 2.7 Multiplication NAM A 3.8 Convert enumerated type value to print format NEG* 2.7 Negation NEW s 2.15 Allocate a record on heap, set pointer to it NIL 2.6 Assert non-nil pointer NODUMP s,W,w," 2.2 BEG main program, suppress dump NOT 2.4 Boolean not ODD* 2.15 Returns true if argument is odd, false if even OFF s 2.5 Offset address, typically used for field reference OR 2.4 Boolean or PACK s,w,w,w 2.15 Convert and copy from unpacked to packed PAGE 3.8 Output a formfeed to a text file POP s 2.2,1.9 Pop (arguments) off stack PRED* 2.7 Returns predecessor of argument PUSH s 2.2,1.9 Clear space (for function result) PUT 3.8 Output a record to a file PXPBUF w 2.10 Initialize pxp count buffer RANDOM 2.13 Returns random number RANG* v 2.8 Subrange checking READ* 3.7 Read a record from a file REL* r 2.3 Relational test yielding Boolean result REMOVE 3.11 Remove a file RESET 3.11 Open file for input REWRITE 3.11 Open file for output ROUND 2.13 Returns TRUNC(argument + 0.5) RV* l,a 2.5 Right value (load) operators SCLCK 2.14 Returns system time of program SDUP 2.2 Duplicate top stack word SEED 2.13 Set random seed, return old seed SIN 2.13 Returns sin of argument SQR* 2.7 Squaring SQRT 2.13 Returns square root of argument STLIM 2.14 Set program statement limit STOD 2.12 Convert short integer to real STOI 2.12 Convert short to long integer SUB* 2.7 Subtraction SUCC* 2.7 Returns successor of argument TIME 2.14 Copy time into char array TRA a 2.2 Short control transfer (local branching) TRA4 A 2.2 Long control transfer TRACNT w,A 2.10 Count a procedure entry TRUNC 2.13 Returns integer part of argument UNDEF 2.15 Returns false UNIT* 3.10 Set active file UNPACK s,w,w,w 2.15 Convert and copy from packed to unpacked WCLCK 2.14 Returns current time stamp WRITEC 3.8 Character unformatted write WRITEF l 3.8 General formatted write WRITES l 3.8 String unformatted write WRITLN 3.8 Output a newline to a text file

2.2.  Basic control operations


BEG s,W,w,"

NODUMP s,W,w,"










2.3.  If and relational operators

IF a

REL* r

2.4.  Boolean operators

      The Boolean operators AND, OR, and NOT 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 false, and one a Boolean true.

2.5.  Right value, constant, and assignment operators

LRV* l,A
RV* l,a

CON* r


2.6.  Addressing operations

LV l,w




INX* s,w,w


2.7.  Arithmetic operators

      The interpreter has many arithmetic operators. All operators produce results long enough to prevent overflow unless the bounds of the base type are exceeded. The basic operators available are

Addition:	ADD*, SUCC*
Subtraction:	SUB*, PRED*
Multiplication:	MUL*, SQR*
Division:	DIV*, DVD*, MOD*
Unary:		NEG*, ABS*

2.8.  Range checking

      The interpreter has several range checking operators. The important distinction among these operators is between values whose legal range begins at zero and those that do not begin at zero, for example a subrange variable whose values range from 45 to 70. For those that begin at zero, a simpler ``logical'' comparison against the upper bound suffices. For others, both the low and upper bounds must be checked independently, requiring two comparisons. On the 11/780"" VAX 11/780 both checks are done using a single index instruction so the only gain is in reducing the inline data.

2.9.  Case operators

      The interpreter includes three operators for case statements that are used depending on the width of the case label type. For each width, the structure of the case data is the same, and is represented in figure 2.4.

center, box; cw(15). CASEOP _ No. of cases _

Case transfer table


Array of case label values

Figure 2.4 - Case data structure

      The CASEOP 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 specified statement. If the specified label is not found, an error results.

      The CASE operators take the number of cases as a sub-opcode if possible. Three different operators are needed to handle single byte, word, and long case transfer table values. For example, the CASEOP1 operator has the following code sequence:

	cvtbl	(lc)+,r0
	bneq	L1
	cvtwl	(lc)+,r0	#r0 has length of case table
	movaw	(lc)[r0],r2	#r2 has pointer to case labels
	movzwl	(sp)+,r3	#r3 has the element to find
	locc	r3,r0,(r2)	#r0 has index of located element
	beql	caserr	#element not found
	mnegl	r0,r0	#calculate new lc
	cvtwl	(r2)[r0],r1	#r1 has lc offset
	addl2	r1,lc
	jmp	(loop)
	movw	$ECASE,_perrno
	jbr	error

      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 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, the index of the corresponding entry in the transfer table is extracted and that offset is added to the interpreter location counter.

2.10.  Operations supporting pxp

      The following operations are defined to do execution profiling.




2.11.  Set operations

      The set operations: union ADDT, intersection MULT, element removal SUBT, and the set relationals RELT are straightforward. The following operations are more interesting.


CTTOT s,w,w

IN s,w,w


2.12.  Miscellaneous

      Other miscellaneous operators that are present in the interpreter are ASRT that causes the program to end if the Boolean value on the stack is not true, and STOI, STOD, ITOD, and ITOS that convert between different length arithmetic operands for use in aligning the arguments in procedure and function calls, and with some untyped built-ins, such as SIN and COS.

      Finally, if the program is run with the run-time testing disabled, there are special operators for for statements and special indexing operators for arrays that have individual element size that is a power of 2. The code can run significantly faster using these operators.

2.13.  Mathematical Functions

      The transcendental functions SIN, COS, ATAN, EXP, LN, SQRT, SEED, and RANDOM are taken from the standard UNIX mathematical package. These functions take double precision floating point values and return the same.

      The functions EXPO, TRUNC, and ROUND take a double precision floating point number. EXPO returns an integer representing the machine representation of its argument's exponent, TRUNC returns the integer part of its argument, and ROUND returns the rounded integer part of its argument.

2.14.  System functions and procedures





2.15.  Pascal procedures and functions

PACK s,w,w,w
UNPACK s,w,w,w