previous | contents | next

TURNING COUSINS INTO SISTERS 367

combination needed to sequence through the table of addresses. It is a single one-word instruction.

The instruction corresponds to the basic loop of an interpreter. Consequently, there is no centralized interpreter: the interpreter is distributed throughout every one of the service routines.

Arguments to a service routine can also be placed in-line following the routine address. The routine picks up the arguments using the pointer register, each time advancing the pointer for the next use. For this, both the auto-increment and deferred auto-increment addressing modes are ideal.

For example, the following service routine copies onto the stack the value of an integer variable whose address follows the call:

Similarly, the following routine pops a value from the stack and stores it in the variable whose address follows the call:

Using the two primitives $PUSHV and $POPV, the FORTRAN assignment statement:

can be implemented by "compiling" code as follows: *

SPUSHV ; Address of $PUSHV routine

J ; Address of storage for J

SPOPV ; Address of $POPV routine

I ; Address of storage for I

The principal disadvantage of a normal interpreter is avoided by representing the address of a service routine in symbolic fashion as the name of a module to be obtained from a library of routines. Only those routines that are actually referred to are included in the program when it is linked for execution.

We complete this introduction by briefly illustrating how flow of control and changing modes is accomplished.

A simple transfer of control, e.g., the FORTRAN statement:

GOTO 100

can be compiled to:

$GOTO,. 100

using the service routine:

The implementation of the FORTRAN- computed GOTO statement is illustrated in Figure 1. Notice that the count of the number of labels is included in the arguments to the service routine. The service routine checks that the index value is in the correct range; if it is not, an error is reported and control continues in-line (no transfer takes place). In this example, register 1 (R1) is used as a temporary location within the service routine.

To enter threaded code mode when executing normal code, the following call is executed:

JSR R4,$POLSH

______________________-

*In subsequent examples, the arguments of a service routine will be written on the same line as the routine address. Thus, the above would appear as:
$PUSHV,J
$POPV,I
This is more compact and suggestive of conventional assembler notations; the effect is identical to the previous example.

previous | contents | next