GAL: GAL Assembly Language - User Manual
1. Introduction
GAL is a small programming language for a small machine: one accumulator, twenty-two instructions, and a front panel.
The web page is a working interpreter designed to run programs written in GAL. The instruction set is defined in section 5 below.
2. Writing a GAL Program
The format of instructions is:
[LABEL:] MNEMONIC [OPERAND]
Labels and mnemonics are not case sensitive, so HLT, hlt and Hlt are all the same thing. There should be one or more spaces between label and mnemonic, and between mnemonic and operand (if there is one).
Except for data (DAT) definitions, LABEL is optional. Every label declaration ends with a colon, including on DAT lines.
MNEMONIC must be specified – the only exception is that a line may consist of just a label, in which case the label refers to the instruction following.
Depending on the mnemonic, OPERAND may be optional, and where it is required may be:
- the name of a data cell
- a code label
- an immediate constant.
An immediate constant must be a whole number (an integer) optionally preceded by a + or - sign. An operand that begins with a digit, a plus sign or a minus sign is treated as an immediate constant and must be a valid whole number; anything else is taken to be the name of a data cell or label.
For a data cell, a label is required, and it may or may not have an operand. If it has an operand, this must be an immediate constant and this sets the data cell's initial value. If no initial value is specified, it will be set to zero.
Anything following a semicolon is treated as a comment and is ignored.
Enter the program with each instruction on a separate line. Whilst it is not necessary, horizontally lining up the mnemonics and operands helps when reading the program. Blank lines can also aid readability. Section 5 gives a list of available instructions.
3. Numbers
The machine considers everything as a number, so letters and symbols are stored as numbers. The sample program text2numbers can be used to find the number equivalent for any particular characters.
Numbers are whole numbers, positive or negative, limited only by the engine itself; arithmetic that overflows is an error.
All arithmetic is done in the Accumulator. Data can be loaded into the accumulator from a data cell or read from the input stream, operated upon, stored in a data cell, or printed.
Printing is the program's responsibility; to move to a new line, use LOD 10 followed by PRC, and to add a space, use LOD 32 plus PRC.
Note that ADD and SUB may use positive or negative constants and this may cause some confusion at first: ADD -4 has the same result as SUB 4 – both subtract 4 from the value in the accumulator.
4. Running a Program
GAL has an area to enter a program. By default, it loads a simple demo program. You may delete the program (on Windows, click inside the box, press Ctrl+A and then Delete) and type your own program, or you can choose to run one of the sample programs. You could copy and paste a program prepared in, say, Notepad if you wish. The program box is resizable if you want to see more of the program at a time.
When running a program, if it expects any input, this must be entered in the Input stream before pressing Run.
Any output, if there is any, will be shown in the Output box.
The panel shows the state of the accumulator and the program counter, and whether or not the program has terminated correctly. If the Halt light is amber it means the program has terminated correctly; if the light is red then it means an error has occurred.
If GAL has found an error, this will be shown below the panel. The error message gives the line number of the instruction in error and a clear indication of what is wrong.
Line numbers refer to the lines of the program exactly as entered – blank lines and comment lines count too.
5. The Instruction Set
CLR clear the accumulator
LOD load the accumulator from a cell or with a constant
ADD add a cell or constant to the accumulator
SUB subtract a cell or constant from the accumulator
INC add 1 to the accumulator
DEC subtract 1 from the accumulator
NEG negate the value in the accumulator
MUL multiply the accumulator by a cell or constant
DIV divide the accumulator by a cell or constant
MOD modulo divide the accumulator by a cell or constant
STO store the accumulator into a data cell
PRN output the accumulator as a number
PRC output the accumulator as a character
JMP jump to a code label
JEZ jump to a code label if the accumulator is zero
JNZ jump to a code label if the accumulator is not zero
JLZ jump to a code label if the accumulator is less than zero
JGZ jump to a code label if the accumulator is greater than zero
HLT stop execution
NOP do nothing
RDN read a number into the accumulator (error if no number remains)
RDC read the next character into the accumulator (0 when input ends)
DAT declare a data cell (label required), e.g. FOO: DAT 10
Last updated: 2026-10-19 11:55
