Wang 600 Programming Techniques

In general, any key that can be used in Run mode may be entered into a program and used to perform the same function there. Exceptions are the keys PRIME, SET P.C., VERIFY PROG, RECORD PROG, and STEP. These all directly affect the calculator and cannot be used in a program.

Unless otherwise directed by program codes, the execution of a program continues through the steps in numerical order.

Example program: convert Fahrenheit to Celsius

Here is a simple program to convert degrees Fahrenheit to degrees Celsius. The basic formula being used is:
C = (F - 32) * 5 / 9

The program will assume that the user entered the degrees F before pressing GO. The following program will perform the conversion:

STORE (left)
3
2
- (left)
5
×= (left)
9
÷= (left)
END PROG

Note, the above keys (except for END PROG) are the same ones that would be used to perform the conversion manually, using the Wang 600 as a simple calculator.

Place the calculator in Learn mode (or Learn and Print) and enter the above codes. If you used Learn and Print, or List Program after entering it, you should have the following listing on the printer:

 0000  06 15    ST15     
 0001  00 03     E3      
 0002  00 02     E2      
 0003  03 15     -15     
 0004  00 05     E5      
 0005  04 15     ×15     
 0006  00 09     E9      
 0007  05 15     ÷15     
 0008  09 14     *    EP 

Now go back to Run mode, press PRIME, enter a number of degrees Fahrenheit, and press GO. You should see in the display the number converted to degrees Celsius.

This program is included with the distribution. You should be able to load it using the tape drive. It is named "celsius.wng".

Changing Program execution Sequence

Branching (Goto) is accomplished with the SEARCH command. SEARCH is followed by an arbitrary code that corresponds to a previously MARK'ed step using the same code. For example, SEARCH 00 00 will cause the program to continue execution at step(s) after the MARK 00 00 in the program.

Subroutine calls are made by either the f(x) commands or through the extended command 15 07. f(x), and SHIFT f(x), cause a "call" to the step MARK f(x). For example, 10 00 will make a subroutine call to MARK 10 00. 15 07 (CALL) is followed by any code, and will make a subroutine call to MARK code. A subroutine ends with a RETURN code, which causes the program to resume at the step after the f(x) or CALL. Note, a complex subroutine may have multiple exit points, each with its own RETURN.

In addition, there are "Jump" codes that test some condition and then skip the next two program steps if that condition is true. Note, 2 programs steps is the number required for a SEARCH or CALL command. If less than 2 steps are required, the remaining may be filled with GO commands. The basic jump commands test the display, or the Program Error state.

JIF0Skip the next 2 steps if the display equals 0
JIF≠0Skip the next 2 steps if the display does not equal 0
JIF+Skip the next 2 steps if the display is positive (>=0)
JIFERRORSkip the next 2 steps if the Program Error condition is true. This also clears the error condition.

There are additional jump codes:

α JIF0Skip the next 2 steps if register 00 00 equals the display
α JIF+Skip the next 2 steps if register 00 00 is >= the display
α SINSkip the next 2 steps if register 00 00 is < the display

There are also "literal compare" jump codes:

I/O f(x)Skip the next 2 steps if register 00 00 is identical to the display ('x' is don't-care)
I/O SHIFT f(x)Skip the next 2 steps if register 00 00 is not identical to the display ('x' is don't-care)

Note, the "literal compare" jumps are rather esoteric. One possible use could be to compare blocks of program steps. The main difference being that the numeric comparisons always convert the display and register 00 00 to numbers, while the literal compare only compares the digits codes directly. In normal cases there would not be any difference.

There is also a variable-length, unconditional, jump code. INDIR 00 rr will add the contents of register 'rr' to the current Program Counter step. The integer and absolute value are used, and must be within the range 000 and 999.

This is a rather obscure code, but it might be used to implement software constructs such as CASE statements and Jump Vectors. For example, the following code will branch to (MARK) E0, E1, E2, ... based on the contents of the display (0.000000000, 1.000000000, 2.000000000, ...):

 0000  06 04    ST4
 0001  00 02     E2
 0002  04 04     ×4
 0003  00 01     E1
 0004  02 04     +4
 0005  15 11     D11
 0006  00 04     E4
 0007  08 00     *  S
 0008  00 00     E0
 0009  08 00     *  S
 0010  00 01     E1
 0011  08 00     *  S
 0012  00 02     E2
 ...etc for more "vectors"...

Note, the above code segment is not dependent on being placed at step 0000. For example, if the display contained 1.000000000 then at step 0002 register 04 would contain 2.000000000 and at step 0004 will contain 3.000000000. Finally, at step 0006 the contents of 04 is added to the current step (0006 + 3.0 = 0009) which results in the SEARCH E1 code path being taken.