Classic Computer Magazine Archive COMPUTE! ISSUE 9 / FEBRUARY 1981 / PAGE 124

Review

PASCAL On The Pet

A. J. Bruey
Jackson, MI.

The use of Pascal is becoming more widespread every month if the number of magazine articles and advertisements about Pascal and Pascal products can be used as an indication. Pascal began as a teaching language. It is recognized to be an excellent first language for programming students because the structured features of Pascal make it possible for the student to learn efficient programming techniques. Now more and more business applications written in Pascal are beginning to appear on the market.

I had been studying Pascal from a manual with no computer to try it on. Then Abacus Software (PO Box 7211, Grand Rapids, MI 49510) announced the availability of a PET and APPLE version of Tiny Pascal. This version is based on the Yuen/Chung series in the September-November, 1978 issues of Byte Magazine. The Abacus Software system is produced through a licensing agreement with SuperSoft of Champaign, Illinois.

The Pascal Package

The Pascal package contains three programs:

  1. A line editor for developing and maintaining Pascal source programs.
  2. A compiler for compiling the source code into p-code.
  3. An interpreter to interpret and execute the p-code.

The editor and compiler are written in BASIC and the interpreter is written in 6502 assembler. Source programs and p-code files can be saved on either disk or tape in the PET version. The APPLE version requires disk operation.

Writing a Pascal Program

First the Pascal source program is written using the line editor. The compiler is used to convert the source code to p-code. The p-code is then run interpretively using the interpret program. The p-code program executes much faster than a BASIC Program performing the same function.

Advantages of this system

Inexpensive. At $35.00 for the disk version and $40.00 for the tape system, it's a good buy for anyone who wants to try Pascal.

Structured constructs. This version contains all the structured features for which Pascal is noted:

FOR...DO
WHILE...DO
REPEAT...UNTIL
CASE
IF...THEN...ELSE

Simple to use. Excellent documentation including both the source code and p-code for two sample programs. Step-by-step operating instructions make it easy to learn.

Abacus Software provides excellent customer support.

Disadvantages

Like other "tiny" language implementations, this version is an integer-only implementation. The only data types are integer and integer array.

There are no built-in functions. None of the usual Pascal functions such as SQR (square) and SQRT (square root) are available.

Rather slow. In the limited testing that I've done, I've found that the compiler takes three to four seconds to compile each line of source code into p-code.

Poor I/O facilities. There is no provision for disk or tape input or output during program execution.

There is also no way to direct program output to a printer.

A Sample Program

1 : [SQRT - INTEGER SQUARE ROOT]
2 : CONST CR=13;
3 : VAR X, NUMBER, MEMORY, COUNT, A : INTEGER;
4 : FUNC SQRT (X);
5 : BEGIN
6 : MEMORY : =1;
7 : A : =0;
8 : WHILE X>=0 DO
9 :    BEGIN
10 :      X : =X-MEMORY;
11 :     A : =A+1;
12 :     MEMORY: =MEMORY +2;
13 :  END;
14 : SQRT :=A-1;
15 : END;
16 : BEGIN
17 :    NUMBER :=1;
18 :      WHILE NUMBER>0 DO
19 :         BEGIN
20 :           WRITE<'ENTER A NUMBER '>;
21 :           READ (NUMBER#);
22 :           COUNT :=SQRT (NUMBER);
23 :           WRITE <CR, 'SQUARE ROOT IS ',COUNT#,CR>;
24 :         END;
25 : END.

The listing shows a sample Pascal program that was developed and run under this system. It was the first Pascal program that I wrote and thus the coding is probably far from optimum. It is an integer square root routine based on the method described in my previous (November, 1979) MICRO article "Performing Math Functions in Machine Language". The reader may either refer to that article or may discover the algorithm for himself by following through the coding.

A brief description follows for those of you who are not familiar with Pascal.

Line 1: A remark line. Not executed.

Line 2: Defines the carriage return character. All constants must be defined in a CONST section.

Line 3: Declares all variables that will be used in the program. All variables must be declared in the VAR section.

Lines 4 to 15: This function is the actual square root routine. X is the dummy argument which is passed to the function from the calling statement in line 22.

Lines 16 to 25: This is the main section of the program. Line 20 prompts for an integer, line 22 calls the function, and line 23 displays the answer.

Recall that this is an integer Pascal. You will always get just the integer part of the answer. For example, you will (correctly) get 25 as the square root of 625, but you will also get 25 as the square root of all numbers from 626 to 675. To get more accuracy, you must develop multiple precision routines just as you would have to do in machine language.

The listing was printed using the line editor. Other functions of the editor are append, delete, list, change, replace, load, and save.

Conclusion

After weighing the advantages and disadvantages listed above and using the system for a few days, I have concluded that this program is well worth the price. It is quickly becoming one of my favorite software packges. Those of you who are not used to structured languages will find it interesting to solve program design problems without the use of a GOTO statement.