The Forty-one calculator language
) is the language used to program
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...
The HP-41C series are programmable, expandable, continuous memory handheld RPN calculators made by Hewlett-Packard from 1979 to 1990. The original model, HP-41C, was the first of its kind to offer alphanumeric display capabilities...
range of expandable science/engineering calculators from Hewlett-Packard
Hewlett-Packard Company or HP is an American multinational information technology corporation headquartered in Palo Alto, California, USA that provides products, technologies, softwares, solutions and services to consumers, small- and medium-sized businesses and large enterprises, including...
As with most other calculator programming languages of the 1980s, a Focal program is a linear list of instructions. Each instruction (or step
) roughly correspond to a key (or key combination)
press, and thus correspond to what the user would do if he was to perform the computation himself on the calculator.
This paradigm made Focal programming relatively easy for the newcomer, but program maintenance could be a nightmare.
Add to that the use of GOTO
goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...
instructions—including going to a program step based on a value in a data register ("GTO IND"), a technique known as computed goto
—and you had all the ingredients for the dreaded spaghetti code
Spaghetti code is a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and...
Program steps are numbered starting from 1, but this numbering has no intrinsic meaning, and can change as new instructions are
added or removed in the middle of a program. A special instruction LBL is used to create a label, that can be used by the
user to invoke the program, or by the program itself, as target of a GTO (unconditional go-to) or XEQ (execute) instruction.
Here's a very simple Focal program :
001 LBL "DOUBLE"
- The LBL "DOUBLE" instruction is a label, indicating that the user can invoke the program by XEQ "DOUBLE". As this function can also be assigned to any key on the calculator's keyboard, this effectively adds a new function to the calculator.
- The next two steps correspond to what the function does, mainly multiply the X register by 2 (the HP-41 uses RPN
Reverse Polish notation is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as Postfix notation and is parenthesis-free as long as operator arities are fixed...
- The END instruction indicates the end of the program.
Note that contrary to many other programmable calculators, each Focal step could be stored in memory as more than one byte.
While the calculator memory could hold 2233 bytes of program code, no reported program actually reached this number of steps.