City & Guilds Mnemonic Code
The City & Guilds Mnemonic Code and its associated City & Guilds Computer was a specification for an assembler language and a virtual computer system that ran it. It was introduced in 1964 by the City and Guilds of London Institute and used as the basis for a number of computer programming and administration courses. The computer model was deliberately very simple, and operational systems were implemented as interpreters on a number of mainframe computers like the ICL 1900 series and Elliot 900 family. An updated version was released in 1968. History
The City and Guilds of London Institute (C&G) has been offering a wide variety of vocational and apprenticeship programs since the late 19th century. In the early 1960s, the first computer systems were beginning to rapidly proliferate in large companies, and C&G decided to introduce a series of programs on computer operation and programming. The City & Guilds Mnemonic Code addressed the problem of widespread incompatibility across platforms by introducing a single new assembler language that could then be interpreted in a virtual machine on any sufficiently powerful platform. The system was deliberately simplified to make the number of machines that could run it as large as possible. It also added a number of features one would not normally associate with assembler, including the standard data format being floating point and including a number of features for advanced mathematics and string handling that would normally be expected in a high level language like BASIC. The first release was in 1964, and used in two courses, Basic and Advanced Certificates for Computer Personnel. The system was updated in 1968 as the Revised Mnemonic Code, at which time the Basic course became the Certificate in Computer Programming and Information Processing. Description
The Computer was an oddity in that its basic data type was the floating point number, as opposed to the majority of real-world machines which used binary integers, or for business-oriented machines of the era, binary coded decimal. In addition to the low-level commands found in most assemblers, like loading data from memory or bit shifting, C&G also included multiplication and division, as well as a number of more advanced features like exponents and trigonometric functions. A memory location could alternately hold one character. The Computer was defined to have a main memory of 1000 words. The first ten addresses could be used as index registers but also had special meanings. Location zero was permanently set to the value zero, whilst 1 was the accumulator. 4 held the return address during subroutine calls. In the revised edition, 5 was used with the  instruction and 6 and 7 were used to specify the format when converting from characters to numbers using the CNC instruction. The machine was an accumulator design. Most instructions took two operands pointing into the main memory, referred to as n and m. n was normally a 12-bit value 0 through 999, while m selected one of the registers, 0 through 9. The value in that register was added to n to produce a complete address. For instance, the ADD instruction read the two operands, added the value in the selected register m to the constant value n, and then accessed the value at the resulting memory location, referred to as C.

In the documentation, if the value in question was read from a memory location it was indicated in parens, so most instructions were of the form n+(m), meaning that the value in the register/memory location m was added to the constant value n. Addition performed the operation , meaning the value in register m was added to the constant value n, and then the value in the resulting memory location, (n+(m)), was added to the value already in the accumulator. The system was created before ASCII had been standardized, and, as was typical for machines of the era, used its own custom character set. This held 0 to 9 in locations 0 to 9, A to Z in 10 through 35, and then a number of symbols for a total of 64 characters. The system lacked any facility for including code comments. It also lacked symbolic labels, so if the program added or removed lines, the programmer had to manually update the locations of branches. Instructions
The instructions in the Mnemonic Code can be broken into three broad categories, basic math and logic operations that closely mirror most assembler languages, additional mathematical operations, and input/output operations. One curious addition is the "Q", for "query", which could be added to the front of any instruction. When Q was encountered, the interpreter would run the instruction and then output debugging information to the printer. The instructions, depending on the version, were stored internally in the format:

 FF [Q] nnn m

FF, the "order number", was the numerical instruction opcode. Q indicated the query function, and nnn and m were three-digit and one-digit values for n and m. Numbers were entered in decimal format. Basic operations
The system broke down its basic arithmetic and logical operations into several groups for organizational purposes. Unless otherwise specified, the lists are from the Elliot 903 documentation. Group 0, accumulator/memory operations:

Group 1, accumulator/constant operations, with a single operand holding an integer value. In the original specification only n was used, in the 1968 revision, m can be optionally supplied and its value added to the constant in n.

Group 2, store value:

Group 3, test and branch:

The Revised edition changed some of the codes and added new ones. The list in this section is from the ICL documentation:

The LOP instruction is used to implement loops; by placing the number of iterations in register 5, LOP will decrement the value each time and then jump back to the top of the loop. Extended math
Group 4 are a set of standard math functions:

Input/output
Group 5, 6 and 7 are the input/output instructions. There are significant differences between the two known versions, ICL and Elliot, but it is not clear whether these are differences due to the Elliot version being the earlier specification, or whether it is due to the machine lacking tape and disk support and thus simply removing instructions related to those devices. The result is a relatively limited set of functions:

In contrast, the ICL version, which corresponds to the 1968 specification, is much more flexible. Its Computer had a single input and single output channel that could be connected to different devices. There were five devices defined, 10 was the paper tape reader, 30 was the card reader, 50 was magnetic tape, 60 was a disk pack, and 80 was a printer. To use one of the devices, the ARD n, m or AWD n, m instruction was called, for read or write respectively, with the desired device number in (n+(m)). Once opened, the devices could be read and written using the various I/O instructions. These included separate instructions for numbers and characters, instructions to convert between the two, and various other instructions for particular operations like outputting a line feed or rewinding a tape. A key feature was the concept of a "block", a group of related data that was read all at once. This was normally used to read and write character strings in a single instruction. The block ended with the   character, known as the block character. Other instructions

Number formatting
As a major goal of the system was to read and write data to various real-world devices, the Code included a formatting system similar to printf format strings to ease the task of outputting readable text. The format is stored as a value in memory, at n+(m) for most instructions, or in locations 6 and 7 for the CNC instruction, which uses n+(m) to define the output location. There are four basic formats, all of which begin with a leading space and plus or minus sign:

Assembler directives
In addition to the machine instructions, the language also included a small number of directives:

(TITLE)  prints the following line to the output device
(STORE n)  sets the starting location of the following code. Several STOREs can be used in a single program
(WAIT)  stops execution and waits for a GO instruction from the operator
(EXECUTE n)  indicates the end of the program code and sets the initial program counter location when the program is run

Operating environment
In addition to the Mnemonic Code, the Computer also defined a basic operating environment, like the BASIC language. This included LOAD and SAVE, ON to redirect the input or output device, and GO to start execution. Example
This example, from Herbert, calculates and prints PI. Written for the Elliot 903, this uses the earlier  I/O command, which prints to the punch tape. (TITLE)
  SIMPLE TEST
 (STORE 12)
  LDAN 1
  ARC 16
  MLTN 4
  PNT 1,6
  JST
 (EXECUTE 12)

When run, with the  command, this program will produce:

 SIMPLE TEST
 3.141593

Notes

See Also
p-code machine - A similar educational virtual machine. References

Citations

Bibliography

External links
 Memories of a Programmer - Helen Young recounts early work on a C&G interpreter

 
Programming language implementation