pc - Programmable calculator


pc [ expr ]


Pc is a programmable calculator. It provides simple or very sophisticated number crunching — from basic adding-machine work to complex mathematical expression evaluation.



Arithmetic Operators. +, -, / (division), * (multiplication), ^ (exponentiation), nested parenthetical ordering.


Relational Operators. =, >, <, <>, >=, <=, AND, OR, NOT.


Advanced Functions. SGN, INT, ABS, SQR, RND, LOG, EXP, COS, SIN, TAN, ATN.


String Functions. LEN, STR$, VAL, ASC, CHR$, LEFT$, RIGHT$, MID$.


User Defined Variables. Up to 32 pre-evaluated or constant variables.


Stack. Holds up to 32 values.


History. A 100-entry command history allows you to select one or more previous entries for additional processing. The history also maintains the result of each operation at each point in time.


Precision. Includes 38-digit floating point precision.

The functions adhere closely to the standard BASIC programming language syntax.

The Command Line

When invoked with the expr argument, pc evaluates the expression, displays the result, and exits. Example:

# pc 2 * 2 - 8 -4 # _

When invoked without an argument, pc enters a command mode, allowing you to issue multiple commands to do simple or complex calculations. This is the initial command line prompt:

pc [0] 1> _

The number in [ square ] brackets is the current result register. This register holds the value of the last operation that pc performed. The number before the ‘>’ character is the line number of the next entry to be added to the history buffer.

Entering any number or numeric expression at this prompt causes pc to evaluate it and change the result register accordingly:

pc [0] 1> 6502 + 65816 pc [72318] 2> _

If the command begins with an arithmetic operator (+, -, /, etc.), pc performs the operation on the value contained in the result register. For example:

pc [72318] 3> - 65816 pc [6502] 4> _

Spaces are optional within expressions. They are needed only to delimit pc commands from their arguments, if any.

Boolean Math

Boolean arithmetic is accomplished by entering Boolean expressions on the command line:

pc [6502] 5> "foo" > "bar" pc [1] 6> _

Any true expression sets the result register to one, while a false expression sets it to zero. Boolean operations against the result register are allowed by entering a relational operator as the first argument on the command line.


Use ( parentheses ) to enclose operations to be performed first. Operations buried deepest within parenthesis (that is, parentheses inside parentheses) are performed first.

Pc’s precedence rules are to collect and evaluate nested parenthetical expressions first, then perform multiplication and division (left to right), followed by addition and subtraction (left to right).


Pc recognizes the following commands:


(or q). Quits pc.


(or cl). Clears memory, including the stack and all variables. The result register is reset to 0.


(or hist). Displays a history of the previous commands entered and their results.


(or ?). Shows a list of the available commands.

do x[,y]

(or run). Tells pc to process history entries from x to y. If y is omitted, pc processes line x only. Intermediate results are shown after each entry is processed. All lines are processed, except for lines containing do (or run) commands.

set var=expr

(or let). Defines (or redefines) and sets the variable named var to the evaluated expression expr. The value of var is obtained by prefixing it with the character $. The result register is not affected.

define var=str

(or def). Defines (or redefines) the variable named var to the string str. The string contains an expression which is not evaluated until the variable is used later in an expression. The value of var is obtained by prefixing it with the character $. The result register is not affected.

print expr

Evaluates the expression expr and prints the result. The result register is not affected.


Lists the defined variables and their current values.

push [expr]

Pushes a value onto the stack. If no argument is given, the current value of the result register is pushed. If an expression argument is given, its value is pushed onto the stack. The result register is not affected.

pull [var]

(or pop). Pulls the last pushed value off the stack. If no argument is given, the value pulled off the stack is stored into the result register. If the name of a variable is given (whether previously defined or not), the value is stored in that variable, and the result register is not affected.


Displays the contents of the stack. The next item off the stack is the last one listed.

Constants and Keywords

Pc comes with a constant for pi (3.141592653) referenced by the keyword PI. In addition, the result register can be accessed in expressions by using the keyword RESULT. Example:

pc [1] 6> result * 3 * 3 * result pc [9] 7> _

Notice how the initial value of result is retained throughout the entire evaluation of the expression, resulting in 9. (1 * 3 * 3 * 1 = 9).

User Variables

You may define up to 32 variables for use in expressions. Variables are defined and initialized using the set (or let) and define (or def) commands.

Variables initialized with set have their expressions evaluated first, and the result is stored in the variable. That is to say, a variable defined with set will simply hold a number. Example:

pc [9] 8> set answer = asc("Life, the Universe, ...")-34 pc [9] 9> print $answer 42 pc [9] 10> _

Variables initialized with define retain their expressions as a constant value. The result of the expression is evaluated at calculation time when the variable is given in an expression. Here are two simple examples:

pc [9] 10> define faren = 1.8 * result + 32 pc [9] 11> define celsius = (result - 32) / 1.8 pc [9] 12> list $answer = 42 $faren = 1.8 * result + 32 $celsius = (result - 32) / 1.8 pc [9] 13> _

Unlike the variable answer, set in the previous example, faren and celsius retain their actual assignment rather than being evaluated. They also make use of the RESULT keyword so that their functions operate on the current value of the result register.

If the result register holds the value 9 degrees Celsius, then entering $faren on the command line will convert the value to its Fahrenheit equivalent:

pc [9] 13> $faren pc [48.2] 14> _

Conversely, entering $celsius changes the value back to Fahrenheit:

pc [48.2] 14> $celsius pc [9] 15> _

The Stack

The pc provides a 32-entry stack for temporary storage of numbers. You can push values onto the stack and pull them off in last-in, first-out (LIFO) order. Using the stack instead of declaring temporary variables can speed up multi-line computations.


Typical diagnostic messages from pc are:

“### syntax error”
Instructions given are improperly formatted or not recognized.

“### illegal quantity error”
A value used with a function is out of range. For example, passing a value greater than 255 to CHR$() causes this error.

“### overflow error”
A computation involved a number out of the range of the program. Pc can accept numbers in the range of 1E-38 to 1E+38.

“### division by zero error”
Self-explanatory. This is not allowed.

“### type mismatch error”
A value passed to a function is not of the appropriate type. This occurs, for example, when passing a string to a numeric function, e.g., SGN(“a”).

“### out of memory error”
The variable table is full.


Morgan Davis (