# PL/M (Programming Language for Microcomputers)

Developer Gary Kildall at Digital Research 1972 {{#property:P856}} ALGOL, PL/I, XPL

PL/M is a high-level language designed for system and applications programming for the Intel microprocessor. It was was developed at Digital Research by Gary Kildall in 1972.

PL/M is no longer supported by Intel, but aftermarket tools like PL/M-to-C translators exist (see references [1] [2]).

## Advantages of Using the PL/M Language

PL/M programs are portable, which means that they are easily transferred from one microprocessor to another. When using PL/M, you need not be concerned with the instruction set of the target processor. Additionally, there is no need to be concerned with other details of the target processor, such as register allocation or assigning the proper number of bytes for each data item. The PL/M-386 compiler does these functions automatically. PL/M keywords and phrases are close to natural English, and many operations (including arithmetic and Boolean operations) can be combined into expressions. This enables the execution of a sequence of operations with just one program statement. Data types and data structures have functional attributes. For instance, in PL/M, the program can be written in terms of Boolean expressions, characters, and data structures, in addition to bytes, words, and integers.

Coding programs in a high-level language rather than assembly language involves thinking closer to the level used when planning the overall system design.

Following is a list of the advantages of using PL/M, and the applications for which PL/M is best suited:

• PL/M block structure and control constructs aid and encourage structured programming.
• PL/M has facilities for data structures such as structured arrays and pointer-based dynamic variables.
• PL/M is a typed language. The compiler does data type compatibility checking during compilation to help detect logic errors in programs.
• PL/M data structuring facilities and control statements are designed in a logically consistent way. Thus, PL/M is a good language for expressing algorithms for systems programming.
• PL/M is a standard language used for application development on Intel systems. PL/M programs are compatible across the Intel386 and Intel486 family of microprocessors.
• PL/M was designed for programmers (generally systems programmers) who need access to the microprocessor's features such as indirect addressing and direct I/O for optimum use of all system resources.

In comparison with other languages, PL/M has more features than BASIC and is a more general-purpose language than either FORTRAN (best suited for scientific applications) or COBOL (designed for business data processing). PL/M accesses the microprocessor hardware features more easily than C. Additionally, in comparison to C, PL/M offers the ability to nest procedures and the program structure is easier to maintain.

## The Structure of a PL/M Program

PL/M is a block-structured language; every statement in a program is part of at least one block. A block is a well-defined group of statements that begins with a DO statement or a procedure declaration and ends with an END statement.

A module is a labeled simple DO-block. A module must begin with a labeled DO statement and end with an END statement. Between the DO statement and the END statement other statements provide the definitions of data and processes that make up the program. These statements are said to be part of the block, contained within the block, or nested within the block. A module can contain other blocks but is never itself contained within another block.

Every PL/M program consists of one or more modules, separately compiled, each consisting of one or more blocks. The two kinds of blocks are DO-blocks and procedure definition blocks.

A procedure definition block is a set of statements beginning with a procedure declaration and ending with an END statement. Other declarations and executable statements can be placed between these points, and are used later when the procedure is actually invoked or called into execution. The definition block is a further declaration of everything the procedure will use and do.

## Overview of PL/M Statements

The two types of statements in PL/M are declarations and executable statements. All PL/M statements end with a semicolon (;).

### Declaration Statements

The following is a simple example of a declaration statement:


DECLARE WIDTH BYTE;

This statement introduces the identifier WIDTH and associates it with the contents of 1 byte (8 bits) of memory. Now, rather than having to know the memory address of this byte, you can refer to it by the name WIDTH.

A group of statements intended to perform a function (i.e., a subprogram or subroutine) can be given a name by declaring them to be a procedure:


ADDER_UPPER: PROCEDURE (BETA) BYTE;

The statements that define the procedure follow the semicolon. This block of PL/M statements is invoked from other points in the program, and may involve passing parameters to the program. When a procedure has finished executing, control is returned immediately to the main program. This capability is the major feature enabling modular program construction.

### Executable Statements

The following is an example of an executable statement:


CLEARANCE = WIDTH + 2;

The two identifiers, CLEARANCE and WIDTH, must be declared prior to this executable statement, which produces machine code to retrieve the WIDTH value from memory. Once the WIDTH value is obtained, 2 is added to it and the sum is stored in the memory location for CLEARANCE.

For most purposes, it is unnecessary to think in terms of memory locations when programming in PL/M. CLEARANCE and WIDTH are variables, and the assignment statement assigns the value of the expression WIDTH + 2 to the variable CLEARANCE. The compiler automatically generates all the machine code necessary to retrieve data from memory, to evaluate the expression retrieved, and to store the result in the proper location.

Following is the list of available executable statements:

• Assignment Statement
• CALL Statement
• CAUSE\$INTERRUPT Statement
• DISABLE Statement
• DO CASE Statement
• DO WHILE Statement
• ENABLE Statement
• END Statement
• Executable Functions
• GOTO Statement
• HALT Statement
• IF Statement
• Iterative DO Statement
• Nested IF Statement
• RETURN Statement
• Simple DO Statement

### Built-in Procedures and Variables

PL/M provides a variety of built-in procedures and variables. These include functions such as shifts and rotations, data type conversions, executable functions, block I/O, real math, and string manipulation.

### Overview of PL/M Expressions

A PL/M expression is made up of operands and operators, and resembles a conventional algebraic expression.

Operands include numeric constants (such as 3.78 or 105) and variables (as well as other types). The operators include + and - for addition and subtraction, * and / for multiplication and division, and MOD for modular arithmetic.

As in an algebraic expression, elements of a PL/M expression can be grouped with parentheses.

An expression is evaluated using unsigned binary arithmetic, signed integer arithmetic, and/or floating-point arithmetic, depending on the types of operands in the expression

### Input and Output

PL/M does not provide formatted I/O capabilities like those of FORTRAN, BASIC, or COBOL. However, PL/M does provide built-in functions for direct I/O that do not require operating system run-time support. The PL/M-386 compiler has built-in functions which allow for single-byte, half-word or word I/O, as well as for block I/O (for strings of bytes, half-words, or single-words).

## PL/M code example


FIND: PROCEDURE(PA,PB) BYTE;
DECLARE (PA,PB) BYTE;
/* FIND THE STRING IN SCRATCH STARTING AT PA AND ENDING AT PB */
(K, MATCH) BYTE;
J = BACK ;
MATCH = FALSE;
DO WHILE NOT MATCH AND (MAXM > J);
LAST,J = J + 1; /* START SCAN AT J */
K = PA ; /* ATTEMPT STRING MATCH AT K */
DO WHILE SCRATCH(K) = MEMORY(LAST) AND
NOT (MATCH := K = PB);
/* MATCHED ONE MORE CHARACTER */
K = K + 1; LAST = LAST + 1;
END;
END;
IF MATCH THEN /* MOVE STORAGE */
DO; LAST = LAST - 1; CALL MOVER;
END;
RETURN MATCH;
END FIND;

## Literature

1. Intel Corporation. PL/M-80 Programming Manual. Doc # 98-268B. (1976)
2. McCracken, Daniel D. A Guide to PL/M Programming for Microcomputer Applications. Pearson Addison-Wesley. (1978)