• Keine Ergebnisse gefunden

PASCAL TO ASSEMBLY LANGUAGE LINKAGES -- EXTERNAL PROCEDURES External procedures are prima~ily separately assembled assembly

Im Dokument 3 System 1 (Seite 170-181)

CNTX, CNTY, MOVE: INTEl

L. PVEC:=NEXTVEC;

3.3.3.2 PASCAL TO ASSEMBLY LANGUAGE LINKAGES -- EXTERNAL PROCEDURES External procedures are prima~ily separately assembled assembly

language procedures, $tored in a LIBRARY on disk. Host programs that require ext.rnal procedures must have them linked into the compiled code file. Typically the user w~ites external procedures in assembly

language, to handle low-level operations that Pascal is not designed to

p~Dvide. External assembl~ language procedures are also used for their

comp,aT'~·t;ive spe(~d in 'real time' applications.

A host program declares that a procedure is external in much the as~embly langu~ge procedure respects the Pascal exte~nal

declar~tion. The linker checks only that the number o~ words of

paramete~~ agree b~tw~en the Pascal and assembly language declarations.

For more info~mation see section 1.8 Linker and 1.9 Assembler(s).

The conventions of the surrounding sytem conce~ning register use anM tBlling spqu?nces must be ~estri~ted by write~s of ~ssembly

languclge ~'Dl.,ltin~::::.. ThElse conventions TOT' the PDP-l1 and l80/8080

implem~ntation~ ara given he~e.

First, fo~ the PDP-l1~ registers RO and Rl are available for

MOV PARAM(RS),LOCAL1(R5) ;Sample statement

Page 173

EXIT: MOV applications). The~e is no provision for handling inte~rupts'from the

device where a collected buffer is being written to disk. Support for continuous interupts would be mare complex, involving multiple buffers and exclusion mechanisims to assure that buffer switching would occur reliably. The ProJect intends eventually to provide synchronization

P~n~ '174

capabilities at the Pascal level~ so that inte~rupt handling can be accomplished with great~r convenience and safety.

. PROC

DATAFILE: File of DATABUFFER;

PROCE.DURE' DRCOLLECTi

3.3.2.3 ASSEMBl.Y LANGUAGE TO ASSEMBLY LANGUAGE LINKAGES

The third way in which separate routines may share data structures and subroutines is by linkage f~Dm assembly language to assp.mbly language. This is made possible through the use of the .DEF and . REF pseudo-ops provided in the UCSD assemblers. These generate

link information that allows two sepa~ately assembled procedures to be L(inked together. One possible use for this will be the linking of separate routines and drivers in constructing new UCSD interpreters.

The following are very abbreviated versions of two assembly

rA~AMCTER DISPLACEMENTS FROM R5 FRAME POINTER

v x

-4-COMPUTE W', HOMOGENEOUS COORD AND LEAVE IT ON STACK

ROUND:

. END

COr-1PUTE PSXPOS

NOW COMPUTE PSYPOS

CLEAN UP STAC~ AND RETURN

I ROUND REAL ON STACK TO INTEGER IF

<

0 THEN SUBTRACT O. 5 ELSE ADD O. 5~ THEN TRUCATE .

r h e: sec 0 ~ d r' 0 uti neT' e f e 1" en c e s t h ~ of 1 r s t l ' 0 uti n e a s us ell a s ttl e separately assembled DRAWLINE routine. MOVETO must be linked into LINETO befoTB the routine can be linked in as an external procedure to a PASCAL UNIT Dr PROGRAM .

. PROC LINETO,6 ; PAR/"tMETERS OCCUpy 6 WORDS

PROCEDURE LINETO(X, V, Z: REAL);

DRAWS A LINE FROM THE LAST POINT CONTAINED IN PSXPOS & PSYPOS TO THE NEW TRANSFORMED POINT GIVEN BY X, V, & Z ...

SAVEX - PSXPOSi SAVEY := PSYPOS;

t'lQVE"TfJ ( X, y. Z) ;

DR/\tl"Llr~E(.JUNJ.\~ PSBUFp ... ·, 20, 160+SAVEX, 120-~SAVEY,

PSXPOS-SAVEX. SAVEv-PSYPOS, l)j

· PURL Ie PSXPOS

· PUBL 1 C PSYPOS

· PUBt Ie PGHUFP

· PH I\JATE RANGE

.REF MOVE TO .Rt:F DRAWLINE

LINETO ENTRY POINT

MOV R5, -(SP) MOV SP, R5 Sr\VEX EQU --2 SAVEY EGU --4

X EQU 1.11

y EQU lC}

Z EGlJ 4

SAVEX "= PSXPOS; SAVEY

USE R5 AS STACK FRAME POINTER

PSYPOS;

Page 177

JSR PC,@#MOVETO DRAWLINE( ... ) i

JSR PC,@#ORAWLINE

; ALL DONE ... RETURN Jf'lP @RO

. END

For examples and mo~e information see section 1.9 ASSEM

***************** *****************

*

LONG INTEGERS

* *

SECTION 3.3.3

*

*~*~#************

*****************

A new addition to V.e.S.D. Pascal p~edecla~ed type INTEGER is the optional use of a length attribute (available only on LSI 11/PDP 11 based micros). This essentially constitutes a new t~pe and will, in the remainder of this document, be referred to as LONG INTEGER.

The LONG INTEGER is suit~ble for business, scientific or other applications in which the need for extended number length with complete accura~y is felt. This extension supports the four basic st3ndard INTEGER arithmetic operations (additiont subtraction, division and multiplication) as well as routines facilitating

conve~slon to strings and standard INTEGER~. Stl'ong t~pe checking is enforc.;\r.! throughout to reduce potential errors. Input/Output, in line declaration of constants and inclusion in $tructu~ed types are all fully $IJpported and are analogous to the usage of standard INTEGERs.

LONG INTEGERs are declared using the standard identifier INTEGER followed by a length attribute in squaTe brackets. This

length is an unsigned number, not larger than 36, denoting the minimum number of decimal digits repre5ent~ble by the LONG INTEGER. For

exan'lple, a variable called 'XI capable of storing at least an eight decimal digit signed number would be created by:

VAR X: INTEGER(8J;

Constants aTe defined in the normal manner:

CONST RYDBERG

=

10973731;

In the above exampl~ RYDBERG would be b~ default a LONG INTEGER and could be used anywhere a LONG INTEGER could be used.

In general LONG INTEGERs may be used an~where it is

synt~ctically correct to use REALs (nat fully implemented until II.Oi for now LONG INTEGERs are limited to aritmetic operationsl assignment

statementrj (biJt not as<:!ignment to a R~;;:AL)} TRUNC, and STR); howf!ve"f'

care must be taken to ensure that sufficient words have been allocated by thp derl~red length att~ibute for storage of the result of

assignment or arithmetic expression statements (see note in next subsection fo~ complete details). INTEGER expessions aTe implicitly

co~verted as required upon assignment tnJ or arithmetic operations with, a l..ONG INTEGER. The T"even"S~ i~ not true, UrH1T'y plus/minus is correctly handled.

Page 179

VAR

INTEGER j

L: INTEGER(NJj where N is an acceptable length S: REALi

1:= Li cOffinile time error; see TRUNC(L) below L:=-L; correctf with~he usual exception

L:.

=

I ~ ll!-UQ.Y,.Lf..fLl' ... !:Ji.U l ' = Si never acceRted

S:= Li will be implemented with II.O

Arithmetic operations which may be used in conjunction with LONG INTEGERs are any or allr'rom the set + .. -I*tDIV,una ... y

plus/minus. On assignment the length

0'

the LONG INTEGER is adjusted (during execution) to the decla~ed length attribute of the va~iable, th~refDre an interrupt (overflow) may result. An interrupt (overflow)

occu~s only wh~n t~e intermediate result exceeds the number of words

required to store (as a minimum) thirty-seven decimal digits, or when the final result is assigned to a variable with insufficient length attribute. (On the matter of the length attribute and what it

defines: a length attribute of 5 thru 9 may store up to and including 2147483647, length att~ibutes of 10 thru 14 may store thru

140737488355327, 15 thru 18 .. 9223372036854775807. It is left to the interested reader to compute any larger length att~ibute storage

capacities. Thus i t would be unwise to attempt to use a LONG INTEGER as a subrange. This range of length att~ibutes all having the same upper bound is a result of the allocation of a full word as the least amount of additional storagel 1. e. 5 th1"u 9 represent a two word

INTEGER, ) All of the standard relational operators may be used with mixed LONG INTEGER and INTEGER.

The function TRUNCCL), where 'L' is a LONG INTEGER, will convert 'L' to an INTEGER <i. e. TRUNC will accept a LONG INTEGER as well as a REAL as an argument). Interrupt (overflow) will result if L

is greater than MAXINT.

The procedure STR(L/S) converts the INTEGER or LONG INTEGER 'L ' , into a st~ing (complete with minus sign if needed) and places it in ttl (? STR lNG'S I . Ttl e fo I 1 oUJi ng program segment wi 11 provi de a

suitable dollar and cent routine:

STR(L,S); INSERT{'. '!SJLENGTH(S)~ei); WRITELN(S);

Where 'L' and ~Sl are appropriately declared. TRUNC and STR are the only two routines which cur~ently will accept LONG INTEGERs as parameters. An attempt to declare a LONG INTEGER in a parameter list will result in a compile time e~ror, which may be circumvented by

creating a type which is a LONG INTEGER. For example:

Page 180

TYPE LONG

=

INTEGER[1Bll

PRDCEDURE BIGNUMBERCBANKACCT LONG)i

The LONG INTEGER is stored as a multi-wordJ twos complement

bina~y numb~r. System and interp~eter ~outines do the I/O conversions as re~ui~ed. Maximum storage efficiency is aChieved by dynamic

expansion and cont.i'action of Ulor-d allocation as required. During LONG INTEGER operations the length is placed on the stack above the number itself, the d&clared length att~ibute need not be the same and can be lens than this length.

Jage 182

******************************* ***************

*

P5UEDO-MACHINE ARCHITECTURE

* *

Section 3.4

*

******************************* ***************

VeT'S ion 1. 5 Septembe-r 1978

The UCSD Pascal P-machine, designed specifically for the execution of Pascal programs on small machines, is an extensively

modified descendant

Or

the P-2 pseudo-machine from Zurich. It supports variable addl"essing, including strings. byte arrays, pac"ed fields, and

.jynamit: vaT'iables.; logical, integer, real .. and set top-of-stack arithmetic and comparisons; multi-element structure comparisons;

several types of branches; procedure/function calls and returns, including overla~able procedures; miscellaneous procedures used by

systems programs; and an I/O system.

This Sectionl to be used in conjunction with Section 3.5, describes the P-machine "hardwa'f'e, It communication with the operating

systeml exceptional condition handling, the instruction set, the lID system, and the bootloading process.

NOTE: nat all of the above will be included in the 1.5 rel!ase and will anl~_be available sometlme.later.

3.4.1 HAR D~·Jt~R E

The 1" e e xis t s no p h Y sic a l P -ma chi n e (yet!). The P -ma chi n e

e~ists only a~ interpreters written in assembly languages of actual

compute~s. However, this can and will be ignored in the following description.

The P-machine us~s 16-bit words, with two a-bit bytes peT

word. It ha~ s.everal registers and a user memory, in which aT'e kept a star.\( and a heap. All r~gisters are pointers to word-aligned

st~uctures! except IPC, which is a pointer to byte-aligned

instT'~JctiQns. The registers are:

SP : St a c k Poi n t e r i s a p 0 in t e r t o t h e top 0 T the e x e cut i on s t a c k . The

stack starts in high memory and grows toward low memory. It

contains code segment. and activation recordSJ and is used to pass parameters! retu~n function vdlue~J and as an opeT'and source for many instructions. The stack is extended by loads and procedure callsi and is cut ba,ck by ~toreSI procedure returns, and arithmetic operation'S.

NP: N~w Po inter is a poi nter to th e top of! the dynami c heap. The heap starts in law memory and grows upward toward the stack. It

contains all dynamic variables (see Jensen and Wirth, Chapter 10).

I t i s eo x t e It d e d b y the s tan d .a rd p r' 0 C e d u r' e I T1 e w', and i $ cut b a c k b Y

the 'standard procedure 'release',

Page 183

~TAB: Jump TABle pointer is a pointer to the procedure attribute table

of the currently executing procedure, (St~e S~~-:tion 3,5 .. -Figure 5. ) SEG: Segment Pointer points to the procedure dictionary of the segment

to which the currently executing procedure belongs. (See Section 3. 51 of i 9 liT' e 6. )

MP: Most recent Procedure is a pointer to the activation record of the currently executing procedu'!"e. (Se~ Sectton 3.5) -figuT'e 7. )

Variables local to the current procedure aT'e accessed by indexing off MP.

BASE: BASE Procedure is a pointer to the activation record of th~ mast recently invoked base procedure (lex level 0). Global (lex

le~el 0) variables are accessed by indexing Qf~ BASE.

Im Dokument 3 System 1 (Seite 170-181)