S-Pascal Review | Electron User - Everygamegoing

Electron User

By Acornsoft
Acorn Electron

Published in Electron User 2.06

S-Pascal is the latest in a series of programming languages from Acornsoft. It arose from investigations into possible developments resulting from the inclusion of data structuring facilities in an ALGOL-60 like language.

It was designed around 1970 mainly by Professor Niklaus Wirth working at the Institute for Informatics in Zurich, but also benefited by the inclusion of some of the ideas of C. A. R. Hoare who was also working on data structuring facilities in programming languages.

He published his language in 1971 and named it after the great seventeenth century French philosopher Blaise Pascal, who invented one of the earliest known calculators.

Two years later, in 1973, Hoare and Wirth attempted a formal definition of the language in response to user experience to shed light on areas of uncertainty. This led to a revision and extension of the original language.

As with all computer languages, Pascal was designed for a specific purpose. Niklaus Wirth's main objective was a language better suited to teaching programming than any existing language at the time. He was successful in his aims and it soon became popular as a teaching language.

Very quickly, user groups sprang up in several countries to exchange information and ideas on Pascal and the language was adopted by the University of California, San Diego in 1973/4 as their main teaching language. UCSD were responsible for a implementing Pascal for a wide range of computers.

One of the main reasons for Pascal catching on so quickly is that it is concise - the rules of grammar can be written down on just four or five pages.

Pascal is fairly simple to learn although complete beginners may have trouble initially as the knowledge required to write your first program is greater than for Basic.

Pascal is a highly structured language with a rigid format that the programmer is required to adhere to. Everything is laid out so neatly and logically that it is difficult to go wrong. It encourages a style of programming in which programs are built up step by step from small well defined procedures.

All programs start with the word 'program' followed by the name of the program. All the constants and variables used must be declared after the title, plus their type - for example, integer. Any procedures used are defined following the variables and constants and the action part of the program commences with 'begin' and finishes with 'end'.

Pascal programs are very readable, being almost self documenting and needing very few comments. The program flow is easy to follow and the structure clear; making alterations, improvements and debugging very simple.

Lisp is quite interesting, Forth is fast and powerful, Basic just a Mickey Mouse toy for kids - but Pascal is a real programmer's language and a delight to use. Pascal is a complied language, not an interpreted one like Basic which means that Pascal programs run many times faster than their Basic equivalents.

There are two popular ways of implementing Pascal, each with its own advantages. Either the text of the source code can be decompiled to pure machine code - which makes it very fast but specific to that machine - or it can be compiled to P-Code which is then interpreted when run, not unlike Forth.

This is slower but more easily transferred to other machines. Acornsoft's S-Pascal is not a full blown version but contains a subset of Pascal to teach the language and provide an introduction to structured programming. It is designed for people who know little or nothing about Pascal but are familiar with Basic. It allows short programs of up to 1.25k to be written, compiled and executed.

There are several important differences between this latest language from Acornsoft and the previous ones. The first is noticed immediately on opening the box - which is slightly larger than normal. Inside is the cassette and manual whereas with the other languages, the manual had to be purchased separately on top of the cassette. This makes S-PASCAL some seven pounds cheaper than the others.

The second difference is noticed when S-PASCAL is loaded and totally confused me at first - it wouldn't have if I'd read the instructions, but who does? When loading is complete, after about five minutes, the Electron is still in Basic. The loader can be listed and Basic programs typed in and run. I thought that it hadn't loaded and wondered where the Pascal program was.

S-Pascal is a compiler only - not an interpreter - so commands cannot be entered in direct mode. What you get are several new * commands to enable you to write, compile and run Pascal programs.

To type in a Pascal program *NEW is entered. Programs can be typed in, edited and listed as with Basic, but using lower case characters so as not to confuse the compiler when it is run with Basic keywords which are stored as tokens.

*COMPILE will activate the compiler producing code which is stored in a reserved area of memory. It can then be executed with *GO.

Pascal programmers will be disappointed with Acornsoft's S-Pascal as there are so many omissions compared to a full implementation and they will feel very restricted with the subset. However, this is only designed to be a simple, limited version to give people an insight into how Pascal works.

Most Pascal reserved words are present with procedures, functions and arrays being possible, and all the mathematical operators are available. However, hardly any of the predefined functions or procedures have been included such as SIN, COS and ABS.

Variables can be character, Boolean or integer, but not real, which explains why many of the functions are not available.

CALL has been added - not a standard Pascal word - to allow machine code routines and the operating system to be accessed from within Pascal.

Acornsoft have chosen to compile the source text directly to machine code instead of P-Code as with many implementations.

The code is placed at &1100 and there is enough room for about 2.5k. The source text can be saved in the same way as basic and the object code produced, saved with *SAVE.

Compiling the source text directly to machine code has several advantages over compiling to P-Code. After compiling, the compiler - actually a Basic program 11k long plus 4k workspace, residing at &1F00 - is no longer needed.

This means the object code can be *RUN on its own, or the compiler space used for a Basic program which calls the machine code, or high resolution graphics - for example Mode 0.

Instead of using a Basic compiler program, why not write in Pascal, a far superior language and compile that? A Pascal compiler is far more powerful than a Basic equivalent, with far fewer restrictions. Can a Basic compiler cope with multi-dimensional arrays, procedures and functions to which parameters are passed and that have local variables? Acornsoft's S-Pascal can.

The compiler uses a two pass assembly, printing the mnemonics and object code each time, and if the printer is enabled, it can be listed. Errors are spotted on the second pass and the appropriate line listed with an arrow pointing to the mistake, and a message is printed saying what the error number is and where it occurred in the line. The error can then be looked up in the manual or on the reference card supplied.

I was curious to find out just how fast Pascal was. How efficient is the machine code? So I wrote equivalent - or near enough - programs in Basic, Forth, Lisp, Pascal and assembly language. It simply involved setting a variable to zero, then going round a loop 30,000 times, incrementing the variable by one each time. The speed test results are shown below:

Assembler 1.4 seconds
S-Pascal 11.3 seconds
Forth 12.5 seconds
BASIC 34.9 seconds
Lisp 285.0 seconds

The test showed Pascal to be up to three times as fast as Basic and marginally faster than Forth, which is generally reckoned to be a fast language itself. The test also highlighted the incredible inefficiency of the code produced - Pascal taking some eight times longer than the specifically written machine code routine.

This is not a criticism of S-Pascal but is just a fact of life. Compilers cannot hope to be as efficient as a purpose written machine code program.

Acornsoft has achieved their main objective of producing a simple subset of Pascal for teaching the language and structured programming. The compiler is straightforward to use and the manual is short - 67 pages - but clear, and covers every aspect in detail.

The tape, and manual, contain seven demonstration programs showing what the system is capable of, which is quite a lot.

S-Pascal has a further function as a tool for writing short machine code routines which can be *RUN or called from within a Basic program. This is probably more useful to the experienced programmer.

Programmers are strongly recommended to look at S-Pascal - especially those writing so called 'spaghetti' programs full of GOTOs. It will improve their structure no end. If you already write structured programs, then learning Pascal will be a doddle.

S-Pascal is a welcome addition to the list of programming languages for the Electron, and if they even bring out a full blown version on a ROM Cartridge you can bet that I will be one of the first to get it.

Roland Waddilove

Other Acorn Electron Game Reviews By Roland Waddilove

  • Robotron 2084 Front Cover
    Robotron 2084
  • Tempest Front Cover
  • Bumble Bee Front Cover
    Bumble Bee
  • Elkman Front Cover
  • Joe Blade II Front Cover
    Joe Blade II
  • View Front Cover
  • Anarchy Zone Front Cover
    Anarchy Zone
  • Lisp Front Cover
  • Mouse Trap Front Cover
    Mouse Trap
  • House Of Horrors Front Cover
    House Of Horrors