P L 3 6 0 REFERENCE MANUAL Stanford University fetched from ftp://lindy.stanford.edu/pub/pl360.tar.gz and slightliy reformatted from ANSI carriage lineprinter control to ASCII characters and using form feed characters. This manual was written and formatted for a lineprinter with a wide carriage. Examples in appendix A are likely to get truncated in printing. The file pl360man.txt contains the pure text with form feed characters. File pl360man.pdf is a conveniently formatted version of that for easy viewing e.g. in a web browser, but has the problem of the truncated lines for the examples in appendix A. Choose wisely :-) CONTENTS SECTION 1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . . 1-1 SECTION 2. DEFINITION OF THE PL360 ENVIRONMENT 2.1 Terminology, Notation, and Basic Definitions . . . 2-1 2.1.1 The Processor . . . . . . . . . . . . . . . 2-1 2.1.2 Relationships . . . . . . . . . . . . . . . 2-2 2.1.3 The Program . . . . . . . . . . . . . . . . 2-2 2.1.4 Syntax . . . . . . . . . . . . . . . . . . 2-2 2.2 Identifiers and Basic Symbols . . . . . . . . . . 2-3 2.2.1 Identifiers . . . . . . . . . . . . . . . . 2-4 2.2.2 Basic Symbols . . . . . . . . . . . . . . . 2-4 2.2.3 Standard Identifiers . . . . . . . . . . . 2-5 SECTION 3. VALUES 3.1 Hexadecimal Values . . . . . . . . . . . . . . . . 3-1 3.2 Decimal Values . . . . . . . . . . . . . . . . . . 3-1 3.3 Numeric Values . . . . . . . . . . . . . . . . . . 3-2 3.4 String Values . . . . . . . . . . . . . . . . . . 3-2 SECTION 4. PROGRAM FORMAT 4.1 Block Structure . . . . . . . . . . . . . . . . . 4-1 4.2 Program Segmentation . . . . . . . . . . . . . . . 4-3 4.3 Data Segmentation . . . . . . . . . . . . . . . . 4-3 4.4 Main Program . . . . . . . . . . . . . . . . . . . 4-4 SECTION 5. DECLARATIONS 5.1 Register Synonym Declarations . . . . . . . . . . 5-1 5.2 Segment Base Declarations . . . . . . . . . . . . 5-1 5.3 Cell Declarations . . . . . . . . . . . . . . . . 5-2 5.4 Cell Designators . . . . . . . . . . . . . . . . . 5-3 5.5 Cell Synonym Declarations . . . . . . . . . . . . 5-4 5.6 EQUATE Declarations . . . . . . . . . . . . . . . 5-5 SECTION 6. STATEMENTS 6.1 Register Assignments . . . . . . . . . . . . . . . 6-1 6.2 Register Assignment Expressions . . . . . . . . . 6-2 6.3 Cell Assignments . . . . . . . . . . . . . . . . . 6-3 6.4 GOTO Statements and Labels . . . . . . . . . . . . 6-4 6.5 Conditions and Compound Conditions . . . . . . . . 6-4 6.6 IF Statements . . . . . . . . . . . . . . . . . . 6-6 6.7 WHILE Statements . . . . . . . . . . . . . . . . . 6-6 6.8 FOR Statements . . . . . . . . . . . . . . . . . . 6-7 6.9 CASE Statements . . . . . . . . . . . . . . . . . 6-7 SECTION 7. FUNCTIONS 7.1 Function Declarations . . . . . . . . . . . . . . 7-1 7.2 Function Statements . . . . . . . . . . . . . . . 7-1 SECTION 8. PROCEDURES 8.1 Procedure Declarations . . . . . . . . . . . . . . 8-1 8.2 Procedure Statements . . . . . . . . . . . . . . . 8-2 SECTION 9. THE RUN-TIME LIBRARY 9.1 Standard Procedures . . . . . . . . . . . . . . . . 9-1 9.2 Number Conversion Procedures . . . . . . . . . . . 9-2 9.3 Data Manipulation Procedures . . . . . . . . . . . 9-4 i SECTION 10. COMPILER CONTROL FACILITIES 10.1 Instructions to the Compiler . . . . . . . . . . . 10-1 10.1.1 Listing Control . . . . . . . . . . . . . 10-1 10.1.2 Listing Options . . . . . . . . . . . . . 10-1 10.1.3 Operating System Control . . . . . . . . . 10-2 10.1.4 Identification . . . . . . . . . . . . . . 10-2 10.1.5 Program Base Register Control . . . . . . 10-2 10.1.6 Object Deck Control . . . . . . . . . . . 10-3 10.1.7 Copy Facility . . . . . . . . . . . . . . 10-3 10.1.8 Conditional Compile Directives . . . . . . 10-3 10.2 Compiler Listing Output . . . . . . . . . . . . . 10-4 10.3 Error Messages of the Compiler . . . . . . . . . . 10-5 10.4 Compiler Object Program Output . . . . . . . . . . 10-6 SECTION 11. LINKAGE CONVENTIONS 11.1 Calling External Routines from PL360 . . . . . . . 11-1 11.2 Requesting Supervisor Services . . . . . . . . . . 11-2 11.3 Calling PL360 Procedures from External Routines . 11-2 SECTION 12. PL360 AS AN ORVYL LANGUAGE PROCESSOR 12.1 Using the PL360 Compiler with ORVYL . . . . . . . 12-1 12.2 Input/Output Subroutines for Interactive PL360 Programs . . . . . . . . . . . 12-3 APPENDIX A. EXAMPLE PROGRAMS AND LISTINGS Sample Program Demonstrating Extensions to PL360 . . . A-1 Right Triangle Problem . . . . . . . . . . . . . . . . A-6 Global Procedure TRTEST . . . . . . . . . . . . . . . A-9 ORVYL Program to Set Options . . . . . . . . . . . . . A-11 APPENDIX B. THE OBJECT CODE . . . . . . . . . . . . . . . . . . . B-1 APPENDIX C. COMPILER CONSTRUCTS . . . . . . . . . . . . . . . . . C-1 APPENDIX D. SYNTACTIC INDEX . . . . . . . . . . . . . . . . . . . D-1 APPENDIX E. SYNTACTIC ENTITIES . . . . . . . . . . . . . . . . . . E-1 TABLES Table 6.1 Allowable Cell and Register Type Combinations . . . . . 6-1 Table 6.2 Allowable Cell and Value Combinations . . . . . . . . . 6-3 Table 6.3 Condition Code States . . . . . . . . . . . . . . . . . 6-5 Table 7.1 Instruction Format . . . . . . . . . . . . . . . . . . . 7-2 Table B.1 Object Code Operators . . . . . . . . . . . . . . . . . B-1 Table C.1 2-Byte Instructions . . . . . . . . . . . . . . . . . . C-2 Table C.2 4-Byte Instructions . . . . . . . . . . . . . . . . . . C-3 ii REFERENCES [1] N. Wirth: PL360. "A Programming Language for the 360 Computers," JACM 15 (1968) 37. [2] SCIP/Academic Computing Services Program Libraries, Polya Hall Stanford University. [3] J. Eve: "PL360 Language Extensions," Internal Note, Computing Laboratory. University of Newcastle upon Tyne. [4] G. M. Amdahl, G. A. Blaauw, F. P. Brooks, Jr.: "Architecture of the IBM System/360," IBM Journal of Research and Development 8 (1964) 87. [5] G. A. Blaauw et al. "The structure of System/360," IBM Systems Journal 3 (1964) 119. [6] "IBM System/360 Principles of Operation," IBM A22-6821. [7] "IBM System/360 OS Assembler Language," IBM C28-6514. [8] MTS Vol. I, University of Michigan Computation Center, Ann Arbor. [9] "IBM System/360 Linkage Editor and Loader" IBM C28-6538. [10] "PL360 Programming Manual," University Computing Laboratory, University of Newcastle upon Tyne, Caremont Tower, Newcastle upon Tyne, NE1 7RU, England, 1970. [11] "IBM System/360 DOS System Control and System Service Programs," IBM C24-5036 [12] R. Fajman and J. Borgelt, "ORVYL User's Guide," Stanford University Computation Center, 1971. [13] "IBM System/360 Disk Operating System Supervisor and Input/Output Macros," IBM C24-5037. [14] N. Wirth: "Format of PL360 Programs," ALGOL W - Project Memo, Stanford University, Sept. 9, 1966. iii FOREWORD The intent of this manual is to provide a reference tool for programmers using PL360. Although it is not a textbook, it has been organized in such a way that each section introduces new material dependent on information covered in preceding sections. In that sense, it can serve as a self-teaching aid. Those readers not familiar with Bacus-Naur Form (BNF), may find the syntactic rules used to describe the language difficult to understand. However, the textual descriptions and examples associated with a set of syntactic rules should serve to clarify those rules. Also, the sample programs of Appendix A further clarify the language structure. Knowledge of the 360 architecture [4, 5 or 6] is a prerequisite for understanding the language definition and some familiarity with the 360 Assembly Language [7] and linkage editor [8] is assumed in the description of the object code produced by the compiler. In writing this manual, the authors have drawn heavily upon the (anonymous) PL360 Programming Manual published by the University of Newcastle upon Tyne, Computing Laboratory [10]. iv SECTION 1. INTRODUCTION PL360 is a programming language designed specifically for the IBM System/360 computers. It provides the facilities for a symbolic machine language but displays a structure similar to that of ALGOL. A formal description of an earlier version of the language has been published by Niklaus Wirth [1] who directed the development of the PL360 language and its compiler at the Computer Science Department of Stanford University. Although PL360 was originally designed for writing logically self-contained programs, subsequent extensions permit communication with separately compiled programs. An efficient one pass "in core" compiler, written by Niklaus Wirth, Joseph W. Wells, Jr. and Edwin Satterthwaite, Jr., which incorporates these extensions is available through the Stanford Program Library [2]. This compiler translates PL360 source code into object modules in the format required by several 360 operating systems (OS and MTS for example). The documentation issued with the compiler includes several amendments to the original language definition. Further extensions were carried out at the University of Newcastle by James Eve. These changes [3,10] were aimed primarily at relaxing the linkage constraints on separately compiled programs, enabling for example direct communication with programs using OS/360 type linkages. Michael Malcolm of the Stanford Computer Science Department made several modifications to the version of the compiler produced by James Eve. These extensions made it possible to run the compiler and compiled programs under DOS operating systems. Assembly language subroutines were also written for both OS and DOS to facilitate input-output with sequential tape and disk files. Dick Guertin of the Stanford Center for Information Processing extended the syntax of PL360, primarily to increase programming convenience. He has also written assembly language interfaces to allow interactive use of both the PL360 compiler and PL360 programs under the ORVYL time-sharing monitor at Stanford. Andrew Koening of Columbia University also contributed improvements to the compiler. The language definition and compiler description incorporating all changes are given in this manual. For a full discussion of the background underlying the development of PL360 and a description of the organization and development of the compiler together with some perceptive comments on the 360 architecture, reference must still be made to [1], where the aims of the language are summarized: ... it was decided to develop a tool which would: 1. allow full use of the facilities provided by the 360 hardware, 2. provide convenience in writing and correcting programs, and 3. encourage the user to write in a clear and comprehensible style. As a consequence of 3, it was felt that programs should not be able to modify themselves. The language should have the facilities necessary to express compiler and supervisor programs, and the programmer should be able to determine every detailed machine operation. 1-1 SECTION 2. DEFINITION OF THE PL360 ENVIRONMENT 2.1 Terminology, Notation, and Basic Definitions The language is defined in terms of a computer which is comprised of a number of processing units and a finite set of storage elements. Each of the storage elements holds a content, also called value. At any given time, certain significant relationships may exist between storage elements and values. These relationships may be recognized and altered, and new values may be created by the processing units. The actions taken by the processors are determined by a program. The set of possible programs form the language. A program is composed of, and can therefore be decomposed into elementary constructions according to the rules of a syntax, or grammar. To each elementary construction corresponds an elementary action specified as a semantic rule of the language. The action denoted by a program is defined as the sequence of elementary actions corresponding to the elementary constructions which are obtained when the program is decomposed (parsed) by reading from left to right. 2.1.1 The Processor At any time, the state of the processor is described by a sequence of bits called the program status word (PSW). The status word contains, among other information, a pointer to the next instruction to be executed, and a quantity which is called the condition code. Storage elements are classified into registers and core memory cells, simply called cells. Registers are divided into three types according to their size and the operations which can be performed on their values. The types of registers are: a. integer or logical (a sequence of 32 bits) b. real (a sequence of 32 bits) c. long real (a sequence of 64 bits) Cells are classified into five types according to their size and the type of value which they may contain. A cell may be structured or simple. The types of simple values and simple cells are: a. byte or character (a sequence of 8 bits = 1 byte) b. short integer (a sequence of 16 bits = 2 bytes, interpreted as an integer in two's complement binary notation) c. integer or logical (a sequence of 32 bits = 4 bytes, interpreted as an integer in two's complement binary notation) d. real (a sequence of 32 bits = 4 bytes, interpreted as a base-16 floating-point number) e. long real (a sequence of 64 bits = 8 bytes, interpreted as a base-16 floating-point number) The types integer and logical are treated as equivalent in the language, and consequently only one of them, namely integer, will be mentioned throughout this manual. Likewise, byte and character are equivalent and only byte is mentioned. 2-1 2.1.2 Relationships The most fundamental relationship is that which exists between a cell and its value. It is known as containment; the cell is said to contain the value. Another relationship exists between the cells which are the components of a structured cell, called an array, and the structured cell itself. It is known as subordination. Structured cells are regarded as containing the ordered set of the values of the component cells. A set of relationships between values is defined by monadic and dyadic functions or operations, which the processor is able to evaluate or perform. The relationships are defined by mappings between values (or pairs of values) known as the operands, and values known as the results of the evaluation. These mappings are not precisely defined in this manual; instead, see [6]. 2.1.3 The Program A program contains declarations and statements. Declarations serve to list the cells, registers, procedures, and other quantities which are involved in the algorithm described by the program, and to associate names, called identifiers, with them. Statements specify the operations to be performed on these quantities, to which they refer through the use of identifiers. A program is a sequence of tokens, which are basic symbols, strings or comments. Every token is itself a sequence of characters. The following conventions are used: a. Basic symbols constitute the basic vocabulary of the language (cf. 2.2.2). They are either single characters, or uppercase letter sequences. b. Strings are sequences of characters enclosed in quote marks i.e. "string" (cf. 3.4). c. Comments are sequences of characters (not containing a semicolon) preceded by the basic symbol COMMENT and followed by a semicolon (;). Comments may also be written as a sequence of characters between vertical bars (!). Thus, ! this is a comment ! It is understood that comments have no effect on the execution of a program. In order that a sequence of tokens be an executable program, it must be constructed according to the rules of the syntax. 2.1.4 Syntax A sequence of tokens constitutes an instance of a syntactic entity (or construct), if that entity can be derived from the sequence by one or more applications of syntatic substitution rules. In each such application, the sequence equal to the right side of the rule is replaced by the symbol which is its left side. 2-2 Syntactic entities (cf. Appendix D, E) are denoted by english words enclosed in brackets < and >. These words describe approximately the nature of the syntatic entity, and where these words are used elsewhere in the text, they refer to that syntactic entity. For reasons of notational convenience and brevity, the uppercase letters A, K, and T are also used in the denotation of syntactic entities. They stand as abbreviations for any of the following words (or pairs): A K T long real long real long real real real real integer integer integer short integer short integer byte Syntactic rules are of the form ::= & where is a syntactic entity (called the left side) and & is a finite sequence of tokens and syntactic entities (called the right side of the rule). The notation ::= &1 ! &2 ! ... ! &n is used as an abbreviation for the n syntactic rules ::= &1, ::= &2, ..., ::= &n If in the denotations of constituents of the rule the uppercase letters A, K, or T occur more than once, they must be replaced consistently, or possibly according to further rules given in the accompanying text. As an example, the syntactic rule ::= is an abbreviation for the set of rules ::= ::= ::= 2.2 Identifiers and Basic Symbols The implementation imposes the restriction that only the first 10 characters of identifiers are recognized as significant. Throughout this section, user defined identifiers are shown in lowercase letters to distinguish them from standard identifiers and basic symbols. In actual practice, all identifiers are constructed from uppercase letters. 2-3 2.2.1 Identifiers ::= A!B!C!D!E!F!G!H!I!J!K!L!M!N!O!P!Q!R!S!T!U!V!W!X!Y!Z ::= 0 ! 1 ! 2 ! 3 ! 4 ! 5 ! 6 ! 7 ! 8 ! 9 ::= ! ! ::= ::= ::= ::= ::= An identifier is a K-register, T-cell, procedure, function, or integer value identifier, if it has respectively been associated with a K-register, T-cell, procedure, function, or integer value (called a quantity) in one of the blocks surrounding its occurrence (cf. 4.1). This association is achieved by an appropriate declaration. The identifier is said to designate the associated quantity. If the same identifier is associated with more than one quantity, then the considered occurrence designates the quantity to which it was associated in the innermost block embracing the considered occurrence. In any one block, an identifier must be associated with exactly one quantity. In the parse of a program, that association determines which of the rules given above applies. Any processing computer and operating system can be considered to provide an environment in which the program is embedded, and in which some identifiers are permanently declared. Some identifiers are assumed to be known in every environment; they are called standard identifiers, and are listed in Section 2.2.3. 2.2.2 Basic Symbols Basic symbols which consist of uppercase letter sequences shown below are denoted by the same letter sequences without further distinction. Such letter sequences are called reserved words and cannot be used as identifiers. Embedded blanks are not allowed in reserved words, identifiers, and numbers. Adjacent reserved words, identifiers, and numbers must be separated by at least one blank or other non-alphanumeric. Otherwise, blanks may be used freely. The basic symbols are: + - * / ( ) = < > ^ , ; . : @ # _ " ' ! DO IF OF OR ABS AND END FOR NEG SYN XOR BASE BYTE CASE DATA ELSE GOTO LONG NULL REAL SHLA SHLL SHRA SHRL STEP THEN ARRAY BEGIN CLOSE DUMMY SHORT UNTIL WHILE COMMON EQUATE GLOBAL COMMENT INTEGER LOGICAL SEGMENT EXTERNAL FUNCTION REGISTER CHARACTER PROCEDURE 2-4 2.2.3 Standard Identifiers The following identifiers are predeclared in the language but may be redeclared due to block structure. Their predefined meanings are specified in Section 5, Section 7.1, or Section 9.1. MEM B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 F0 F2 F4 F6 F01 F23 F45 F67 BALR CLC CLI CVB CVD ED EDMK EX IC LA LH LM LTR MVC MVI MVN MVZ NC NI OC OI PACK RESET SET SLDA SLDL SPM SRDA SRDL STC STH STM SVC TEST TM TR TRT TS UNPK XC XI CARRY FALSE MIXED OFF ON OVERFLOW STRING TRUE CANCEL GET KLOSE OPEN PAGE PRINT PUNCH PUT READ WRITE 2-5 SECTION 3. VALUES 3.1 Hexadecimal Values Values may be expressed in hexadecimal notation. ::= ! A ! B ! C ! D ! E ! F ::= # ! A hexadecimal value denotes a sequence of bits. Each hexadecimal digit stands for a sequence of four bits defined as follows: 0 = 0000 4 = 0100 8 = 1000 C = 1100 1 = 0001 5 = 0101 9 = 1001 D = 1101 2 = 0010 6 = 0110 A = 1010 E = 1110 3 = 0011 7 = 0111 B = 1011 F = 1111 Note: If hexadecimal values are used in conjunction with arithmetic or logical operators in a program, they must be considered as a sequence of bits which constitute the computer's representation of the number on which the operator is applied. Hexadecimal values followed by the letter R or L may be used to denote numbers in unnormalized floating-point representation [4,5,6]. 3.2 Decimal Values ::= ! ::= S ::= . ! ::= ::= ! ' ! ' ::= ! R ::= L ! L ::= ! _ Integer, real, and long real numbers are represented in decimal notation. The latter two can be followed by a scale factor denoting an integral power of 10. Short integers are distinguished from integers by the letter S following the number. In order to denote a negative number, an unsigned number is preceded by the underscore symbol "_". (Note: the underscore is used so as not to confuse negative values with the subtract operator "-", which is never part of a number.) Note: A-number is an abbreviation for long real number, real number, short integer number and integer number as defined in section 2.1.4 as a notational convenience. 3-1 3.3 Numeric Values ::= X ::= ! S ::= ! ! ::= ! R ::= ! L Examples: byte values: 2X _5X short integer values: 10S #FF00S integer values: 0 #106C _1 size real values: 1.0 _3.14 2.7'8 #46000001R long real values: 0L 3.14159265359L #4E00000000000001L 3.4 String Values There are also string values, but these are not generally used in conjunction with arithmetic or logical operators. ::= " " ! X ::= ! ::= ! "" When a string is a character sequence enclosed in quote marks, the string is limited to a total of 255 characters. If a quote mark (") is to be a character of the sequence, it is represented by a pair of consecutive quote marks. When a string is a hexadecimal value ending in X, up to 16 hexadecimal digits may be specified. Each pair of hexadecimal digits represents one character. If the number of hexadecimal digits specified is odd, a hexadecimal 0 is prefixed to the specified value to make the total even. Examples: "ABC" denotes the sequence ABC "A""Z" denotes the sequence A"Z #C1C2C3X denotes the sequence ABC 3-2 SECTION 4. PROGRAM FORMAT Compiler input records consist of 80 characters. The first 72 characters of each record are processed as part of a PL360 program; characters 73 through 80 are listed but not otherwise processed. Character 72 of one record is considered to be immediately followed by character 1 of the next record. Character position 1 may contain any character except '$' or any other character (e.g., /) that would signal a compiler control statement or job control statement. 4.1 Block Structure ::= . ! GLOBAL ; . ! GLOBAL BASE ; . ::= END ::= ! ; !