next up previous
Next: D. THE LISP COMPILER Up: LISP 1.5 Programmer's Manual Previous: B. THE LISP INTERPRETER

C. THE LISP ASSEMBLY PROGRAM (LAP)

lap is a two-pass assembler. It was specifically designed for use by the new compiler, but it can also be used for defining functions in machine language, and for makin patches.

lap is an entirely internal assembler. Its input is in the form of an S-expression that remains in core memory during the entire assembly. No input tape is moved duru the assembly. lap does not produce binary output in the form of cards. It assembles directly into memory during the second pass.

Format

lap is a pseudo-function with two arguments. The first argument is the listing, the second argument is the initial symbol table. The value of lap is the final symbol table.

The first item of the listing is always the origin. All remaining items of the listing are either location symbols if they are atomic symbols other than NIL, or instructions if they are composite S-expressions or if they are NIL.

Origin

The origin informs the assembler where the assembly is to start, and whether it is to be made available as a LISP function. The origin must have one of the following formats.

1. If the origin is an octal or decimal number, then the assembly starts at that location.

2. If the origin is an atomic symbol other than NIL, then this symbol must have a permanent value (SYM) on its property list. The value of this SYM is a number speci tying the starting location.

3. If the origin is NIL, then the assembly will start in the first available location in binary program space. If the assembly is successfully completed, then the cell spec ifying the first unused location in binary program space is updated. If the assembly cannot fit in binary program space, an error diagnostic will be given.

4. If the origin is of the form (name type n), then the assembly is in binary program space as in the case above. When the assembly is completed, the indicator, type is placed on the property list of the atomic symbol name. Following the indicator is a pointer to a word containing TXL, the first location of the program just assembled in the address, and the number n in the decrement, type is usually either SUBR or FSUBR. n is the number of arguments which the subroutine expects.

Symbols

Atomic symbols appearing on the listing (except NIL or the first item on the listing) are treated as location symbols. The appearance of the symbol defines it as the location of the next instruction in the listing. During pass one, these symbols and their values are made into a pair list, and appended to the initial symbol table to form the final symbol table. This is used in pass two to evaluate the symbols when they occur in instructions. It is also the value of lap.

Symbols occurring on this table are defined only for the current assembly. The symbol table is discarded after each assembly.

Permanent symbols are defined by putting the indicator SYM followed by a pointer to a value on their property lists.

Instructions

Each instruction is a list of from zero to four fields. Each field is evaluated in the same manner; however, the fields are combined as follows.

1. The first field is taken as a full word.

2. The second field is reduced algebraically modulo $2^{15}$, and is OR'ed into the address part of the word. An arithmetic -1 is reduced to 77777Q.

3. The third field is shifted left 15 bits, and then OR'ed into the word. A tag of four is written "4". A tag of 2 in an instruction with indirect bits is written "602Q".

4. The fourth field is reduced modulo $2^{15}$ and is OR'ed into the decrement.

Fields

Fields are evaluated by testing for each of the following conditions in the order listed.

1. If the field is atomic.

a. The atomic symbol NIL has for its value the contents of the cell $ORG. During an assembly that is not in binary program space, this cell contains the starting address of the next assembly to go into binary program space.

b. The atomic symbol * has the current location as its value.

c. The symbol table is searched for an atomic symbol that is identical to the field.

d. If the field is a number, then its numerical value is used.

e. The property list of the atomic field is searched for either a SYM, a SUBR, or an FSUBR.

2. If the field is of the form (E a), then the value of the field is the complement of the address of the S-expression a. The expression a is protected so that it can never be collected by the garbage collector.

3. If the field is of the form (QUOTE a), then a literal quantity containing a in the decrement is created. It is the address of this quantity that is assembled. Quoted S-expressions are protected against being collected by the garbage collector. A new literal will not be created if it is equal to one that already exists.

4. If the field is of the form (SPECIAL x), then the value is the address of the SPECIAL cell on the property list of x. If one does not already exist, it will be created. The SPECIAL cell itself (but not the entire atom) is protected against garbage collection.

5. In all other cases, the field is assumed to be a list of subfields, and their sum is taken. The subfields must be of types 1-4 above.

Error Diagnostics

*L    I* Unable to determine origin. No assembly. 
*L    2* Out of binary program space. Second pass cancelled. 
*L    3* Undefined symbol. Assembly incomplete. 
*L    4* Type five field contains type five fields inside itself. 
         Assembly incomplete.

Opdefine

opdefine is a pseudo-function for defining new quantities for LAP. It puts a SYM on the property list of the symbol that is being defined. Its argument is a list of pairs. Each pair is a symbol and its numerical value. Note that these pairs are not "dotted" pairs.

Example

OPDEFINE ((     (CLA 500Q8) 
                (TRA 2Q9) 
                (LOAD 1000) 
                (OVBGN 7432Q) ))

The following op-codes are defined in the standard system:

AXT     PXA     SUB     TRA 
CLA     PXD     SXA     TSX 
LDQ     STD     SXD     TXH 
LXA     STO     TIX     TXI 
LXD     STQ     TLQ     TXL 
PAX     STR     TNX     TZE 
PDX     STZ     TNZ     XCA

Examples of the Use of LAP

Example 1: A LISP function

The predicate greater induces an arbitrary canonical order among atomic symbols.

LAP ( ( (GREATER SUBR 2) (TLQ (* 3)) (PXA 0 0) 
    (TRA 1 4) (CLA (QUOTE *T* ) ) (TRA 1 4) ) NIL)

Example 2: A patch

The instruction TSX 6204Q must be inserted after location 6217Q. 6217Q contains CLA 6243Q and this instruction must be moved to the patch.

LAP ( (6217Q (TRA NIL) )NIL) 
LAP ( (NIL (CLA A) (TSX 6204Q) (TRA B) ) 
    ( (A . 6243Q) (B . 6220Q) ) )


next up previous
Next: D. THE LISP COMPILER Up: LISP 1.5 Programmer's Manual Previous: B. THE LISP INTERPRETER