Survey Programs For Hp Calculators

The Museum of HP Calculators

The HP-67 and HP-97 have different shift keys so shift keys are generallynot shown below. Certain functions such as those involving printing and pausingand use of the indirect register (I) are also different. The HP-97 keys aregenerally shown with the HP-67 keys shown in [brackets].

Contents:

If you are familiar with basic survey calculations and COGO routines you will be able to solve problems with these programs even if you are not familiar with using HP calculators or RPN. Even though the HP35S and HP33S are both an Algebraic and an RPN mode calculator, these programs are written for RPN mode, and it is not recommended to switch. Pressing toggles the calculator into and out of Program-entry mode and appropriately turns the PRGM annunciator on and off. Keystrokes in Program-entry mode are stored as program lines in memory. Each instruction (command) or expression occupies one program line. In ALG mode, enter an expression directly in a program. Quickclose Updates and Evaluation programs Quickclose HP35S Survey Program version 1.1 to 1.2 update Version 1.2 rectifies a bug in area computations. The bug is apparent when an area is computed for an unclosed figure and where non-zero coordinates have been used at the start for the figure.

Features

  • 224 Lines of fully merged keystrokes (multi-keystroke steps require just one line)
  • 26 Registers (0-9, S0-S9, A-E, and I)
  • Label addressing with 20 Labels (0-9, A-E, a-e) Pressing A - E or f a - f e from the keyboard in run mode allows one-key access to 5 programs and two-key access to 5 more. Programs labeled 0-9 can be executed from the keyboard by pressing GSB 0-9 but these are more often used as internal labels.
  • 4 Flags (one set by digit entry)
  • Conditional and unconditional branching based on register values and flag settings.
  • Convenient insertion and deletion of program steps
  • Indirect addressing via the I register
  • ISZ and DSZ looping
  • Three levels of subroutines
  • Card reader/writer saves and loads programs and data under manual or program control.

Basic Programming

Entering And Running A Sample Program

A simple program is essentially just the keystrokes you would press to solvethe program manually. The calculator remembers a sequence of keys and executesthem in order at the touch of a key. In the simplest programs, the onlyadditional steps are a name (LBL) and an end (RTN.)

To enter a program slide the PRGM-RUN switch to PRGM. [W/PRGM-RUN on theHP-67.] Then press f CL PRGM to clear program memory and to set the calculatorto the beginning.

With the PRGM-RUN switch set to PRGM (program) the number you see on theleft side indicates the step number. As keystrokes are entered, their row/columncodes will be displayed on the right.(On the HP-97, keys on the right keypad are prefixed by a dash. For example,the x<>y key is shown as -41.) Step 000 is really just a placeholder.The first keys you press will go into step 001.

Enter the program below to compute the area the circle. The program beginswith LBL A which indicates that this program can be executed by pressingthe A key on the calculator. (Remember that prefix keys are not shown, forexample, you'll need to press f pi on an HP-97 and h pi on an HP-67.)

When the calculator encounters a RTN (Return) it halts execution unless itis in a subroutine in which case it returns to the caller. Programs can alsobe ended with R/S (Run/Stop) but RTN is more flexible because it allows yourprograms to be called as subroutines and makes the end of your program moreobvious because R/S can also be used to stop for data entry.

Now set the PRGM-RUN switch to RUN. To run the program key in a radius andpress A. After the display stops flashing the area is displayed. The programcan be run as many times as you like by entering new values and pressingA. For many simple programs, that's all you need to know!

Stopping, Interrupting and Entering Data

Many programs only require data to be entered at the beginning as the oneabove did. Remember that you can use the stack and store values in registersbefore execution. You can also enter R/S instructions into the program toallow additional data to be entered. The user can enter the data and thenpress R/S to resume. If you create a program that runs for too long (possiblydue to an infinite loop) you can stop it by pressing R/S and if necessary,resume it by pressing R/S again. If you press R/S in the middle of a program,you can see where the program is executing by pressing and holding SST (seebelow) or switching to PRGM mode.

Stepping And Editing programs

The following commands are used to edit or step through programs and arenot recordable. (Prefix keys are not shown.)

  • CL PRGM in PRGM mode clears the entire program memory by placing an R/S instruction in each step. Also sets the program counter to 000, sets the trig mode to DEGREES, display mode to FIX 2 and clears all flags.
  • SST steps one instruction ahead. In RUN mode the next instruction is displayed when the key is held down and then executed when it is released. The X register is then displayed making this instruction useful for debugging. It can also be used for moving forward without execution in PRGM mode.
  • BST backs up one instruction. This key may be used in RUN or PRGM mode but unlike SST, instructions are never executed.
  • DEL in PRGM mode deletes the instruction currently displayed and moves all following instructions up. Because the calculator addresses by labels rather than line numbers, this movement does not disturb program branches and subroutines.
  • GTO . nnn is used to move to the instruction at line nnn. This may be used in both PRGM and RUN mode. (No execution takes place in either mode.)

Entering an instruction causes the new instruction to be inserted after theinstruction displayed and all following instructions to be pushed down.

The following diagram when read from left to right shows the insertion ofa multiply after the ENTER. Start with the display showing the ENTER instruction.The x is inserted after the ENTER and the display moves down to show it.Reading right to left, with the display showing the x, pressing g DEL, deletesthe x, and leaves the display on the line above (ENTER.)

GTO lbl can be used in run mode to position the calculator tolbl. The calculator can then be switched to PRGM mode for editingat that label. Unlike the instructions above, this one is recordable so theposition of the PRGM-RUN switch must be properly set. (GSB lbl inRUN mode causes the program at lbl to be executed. In RUN mode, pressingGSB A and GSB f d are equivalent to pressing just A and f d respectively.)

RTN can be pressed in RUN mode to reset the program counter to 000.

Saving and Loading Programs & Data

Programs

To save a program to magnetic card, make sure the PRGM-RUN is switch setto PRGM [W/PGRM on the HP-67] and place a card (always label side up) inthe card reader/writer.

Half the program (or data) memory can be recorded on each side of a card.If the program is longer than 112 lines, the calculator displaysCrd after passing side 1 through to prompt you forside 2. Pass the card through again in the opposite direction (still labelside up.) You may cut off the corners of a magnetic card to prevent it frombeing overwritten. Cards can be marked with a permanent felt tip pen.

When programs are written, the calculator also records the states of theflags, trig mode and display format.

To load a program, make sure the PRGM-RUN switch is set to RUN and insertthe first side of the card. If the program is longer than 112 steps, thecalculator will display Crd to prompt you to insertthe second side. If the checksum does not match the one recorded on the card,the calculator will display Error. Press any keyto clear it and insert the same side again to retry. The registers and thestack are not changed when a program is written or read.

Data

Data can be saved to a magnetic card by making sure that the PRGM-RUN switchis set to RUN and pressing WRITE DATA [W/DATA] which causes the calculatorto prompt you by displaying Crd. Insert the cardand the calculator's primary registers R0-R9 and A-E are recorded on side1. If all secondary registers contain 0, this is noted also on side 1 andyou are finished. Otherwise, the calculator displaysCrd to prompt you to insert the other side to recordthe secondary registers.

To load the data, simply pass the card through the reader.(Crd will then be displayed if you need to passthe 2nd side through.) The calculator marks cards as containing programsor data so there is no need to specify the contents when reading the cards.Flag settings, display mode etc. are not recorded on data cards. Programmemory is not changed when data is written or read.

Merging Programs or Data

It is possible to merge some of the steps on a magnetic card with the currentprogram memory. To merge a magnetic card with the current memory, set thePRGM-RUN switch to RUN. Use GTO . nnn to set the calculator to the last stepof the loaded program that you want to preserve. Press MERGE and insert thecard. (If the second side must be loaded, the calculator will displayCrd.) Instructions after nnn will be replaced bythose in the same positions on the card.

It is also possible to merge some of the data on a data card with the currentdata memory. First store a number between 0 through 25 in the I register.This is the highest register you want to overwrite from the card.Press MERGE and insert the data card. Registers 0-(i) inclusive will be replacedby the values on the card in the same register positions.

Reading Cards Under Program Control

These instructions are recordable so it's possible to design programs thatuse PAUSE to read or merge data or programs during their operation. If sucha PAUSE is recorded into a program, you can insert the card as soon as theprogram begins -- the card will not be drawn into the reader until the runningprogram pauses. (If the data or program exceeds one side, the calculatorwill prompt you with Crd to insert the second sidebefore continuing. If the data or program is to be merged, a MERGE instructionshould be recorded before the PAUSE. (For data, I should be set appropriately.For a merged program, the program in memory will be overwritten immediatelyfollowing the PAUSE instruction.) Execution will resume after the card hasbeen read. If a card is not available to be read within the 1 second timeof the PAUSE, execution continues.

Because the F3 flag (see below) is set by data entry, you can write a loopthat PAUSEs and tests F3 and won't continue until a data card has been entered.For example:

Writing Data Under Program Control

To write data to a card in a program, just insert a WRITE DATA [W/DATA]instruction. The calculator will prompt the user with Crdor the user can place a card in the slot ahead of time which willbe drawn in and written when the WRITE DATA instruction is executed.

Programming Techniques

Addressing

The calculators use label addressing. Labels available are the upper caseletters A through E, the shifted labels f a through f e, and the digits 0through 9. The calculator always searches downward through program memoryfrom the current location. If there are multiple copies of a label it willexecute the first one it finds. After it gets to the end of memory it resumessearching from the beginning.

Jumps and Subroutines

  • GTO lbl branches to label lbl.
  • GSB lbl calls to a subroutine lbl that ends with RTN.
  • RTN returns from a subroutine. Subroutines can be nested up to three levels deep.

The program below calculates the volume of a cylinder by calling the firstexample as a subroutine. If you don't have the first example in memory, keyit in now after pressing CL PRGM:

Now add the cylinder program: (If you already have program A loaded startingat step 001, you can press GTO . 005 to position the calculator to the endin order to add the new program or press GTO . 000 to insert routine B beforeroutine A. You can also press GTO .100 to enter it at step 101 if you like-- Just be sure you don't insert the new code into the middle of the old.)

Now switch to RUN mode, type the cylinder length, press ENTER, then typethe cylinder radius and press B to display the volume. The program uses theradius in X and calls the subroutine A to determine the area of the circle.When the subroutine returns, the area is in X and the length is still inY so X and Y are multiplied to calculate the volume.

Conditional Tests and Flags

The calculators have instructions for comparing X to Y and X to 0. If thecomparison is true the calculator executes the next instruction. If thecomparison is false the calculator skips the next instruction.

The next instruction is most commonly a GTO or GSB like:

The calculators also have four flags F0-F3 that can be set and tested inprogram execution. A flag is set with the STF n [SF n] instruction. The flagis tested by the F? n instruction and if the flag is set the next instructionis executed. Otherwise the next instruction is skipped.

Flags 0 in 1 are command-cleared flags. Once set they can only be clearedwith the CLF n [CF n] instruction. Flags 2 and 3 are test-cleared flags thatcan be cleared by CLF n or by testing them with the F? n operation.

Flag 3 is also set by digit entry. When any digit on the keyboard is pressedit is set. It is also set when data is loaded into registers by magneticcard. The same label can be used to store or compute a value based on thestate of this flag. Programs such as Time Value of Money use this. Theseprograms use a fragment like:

All flags are cleared when the calculator is turned on or CL PRGM is pressed.

Indirect Addressing

The I register is used for indirect addressing. To store a number in I theSTO I [ST I on the HP-67] instruction is used. To recall the contents ofthe I register, use RCL I [RC I]. The I register can also be exchanged withthe X register with the X<>I instruction.

Given some number in I, it can be used to affect the following instructions:

  • STO (i): Store X in register indicated in I. STO *, -, +, รท (i) are also allowed. I can contain 0-25 allowing easy access to all registers (see below.)
  • RCL (i): Recall the register indicated in I.
  • GTO (i): Go to the label indicated in I.
  • GSB (i): Execute the subroutine labeled by I.
  • DSP (i): Display i digits after the decimal.
For STO and RCL, I map to register addresses as follows:
Reg.
Name
(i)
Value
Reg.
Name
(i)
Value
Reg.
Name
(i)
Value
0 0 S0 10 A 20
1 1 S1 11 B 21
2 2 S2 12 C 22
3 3 S3 13 D 23
3 4 S4 14 E 24
4 5 S5 15 I 25
5 6 S6 16
7 7 S7 17
8 8 S8 18
9 9 S9 19

See the looping constructs section below for an exampleof STO I and STO (i).

For GTO and GSB, I map to labels as follows:
Label (i)
Value
Label (i)
Value
0 0 A 10
1 1 B 11
2 2 C 12
3 3 D 13
3 4 E 14
4 5 f a 15
5 6 f b 16
7 7 f c 17
8 8 f d 18
9 9 f e 19

For example:

Would call the subroutine labeled B. That may look silly in such a trivialexample but consider the GSB (i) combined with a DSZ (see below) that callsseveral subroutines in a loop. Or consider an example where I is calculatedfrom some formula and/or user input.

Survey Programs For Hp Calculators Downloads

The I register can contain a non-integer number but only the integer partis used. The looping constructs shown below also use the I register.

Rapid Reverse Branching

GTO (i) and GSB (i) can also be used with a negative number in the I register.In this case, the calculator jumps (i) steps backwards from the current position.This can save a label and is faster than normal branching because the calculatordoesn't have to search. (Because the calculator always searches forward andwraps around, branching back a few steps is a relatively slow operation.)

Rapid Reverse branching can even be used to step forward by effectively steppingbackward beyond step 000. (If the value in I would branch to a negative step,simply add 224 to the negative step number to find the real step the calculatorwould execute next.)

The next example shows a program that simply counts up from zero and displayseach number. (Press R/S when you get tired of watching it.)

Looping Constructs

Two looping functions are available:

  • ISZ: increment I, skip if 0
  • DSZ: decrement I, skip if 0

These instructions increment or decrement I each time they're executed. Aslong as I is not equal to 0 the next instruction is executed. When I becomes0 the next instruction is skipped. The I register can contain a non-integernumber but only the integer part is used during the test (so n for -1 <n < 1 would be treated as zero.)

For example here is a program that takes the number in the X register decrementsit, pauses and loops until the I register goes to 0 (leaving 1 in the display.)

Survey Programs For Hp Calculators Drivers

Here's an example that combines looping and indirect addressing to storethe squares of 0-9 in registers 0-9.

The ISZ (i) and DSZ (i) instructions are similar except that they incrementor decrement the register pointed to by the value of the I register.

Input/Output

R/S can be used as an instruction or pressed from the keyboard. If a programis stopped, pressing R/S starts it. If the program is running, pressing R/Sstops it. An R/S can also be inserted into a program to allow the user toinput data.

Survey programs for hp calculators texas instruments

Survey Programs For Hp Calculators Software

For example the following program lets you key a percentage discount andcalculate the cumulative cost of various quantities of items from which thediscount has been subtracted. Slide the PRGM-RUN switch to PRGM, press CLPRGM if necessary*, and then press.

Slide the PRGM-RUN switch to RUN, key in a percent discount and then pressf a to initialize the program. Key in the first quantity and press A.

When the program stops key in the price for the first quantity and pressR/S to resume execution. The calculator will then display the running total.Key in additional quantities and prices as needed. (Pressing A after quantitiesand R/S after prices.) Alternately you could have written the program toexpect both values to be on the stack before the A key was pressed.

*Above it said 'press CL PRGM if necessary'. This program uses label A whichwas used in other examples. The calculators will allow you to use the samelabel again and this can be a useful feature but it can also lead to confusionas the calculators will always go to the next A downward in memory from thecurrent position. For example:

Would display 1, 2, 3, 1, 2, 3, 1,... on successive presses of A .

On both calculators the PAUSE instruction shows the X register for one second.Several instructions are printed on the HP-97 while they're displayed onthe HP-67. These instructions are automatically converted when cards producedon one are read on the other. These instructions are shown below:

HP-97
instruction

HP-97 Effect

Equivalent
HP-67
instruction

HP-67 Effect

PRINT x

Prints X register

-x-

Pauses for 5 seconds displaying X register.

PRINT Stack

Prints the Stack

STK

Displays each member of the stack in order T, Z, Y, X.

PRINT REG

Prints all primary registers (R0-9, A-E and I)

REG

Displays each primary register preceded by its address.

PRINT SPACE

Prints a blank line.

SPACE

None.

Advanced and Unusual Features

Registers S0-S9 are in the 'secondary' bank. They can be accessed via theI register (values 10-19) or they can be swapped with the primary bank byusing the P<>S Key.

On the HP-97 the printer switch can be set to:

  • MAN: prints only when you use a printing function
  • NORM: the calculator records data entry and operations so a calculation can be reconstructed but doesn't display intermediate results except when you press the PRINT x key.
  • TRACE: Like NORM but prints each intermediate result.

HP-97 users are encouraged to make heavy use of the Print Prgm function sinceprograms are listed alphanumerically. Each printed line shows the step number,keystrokes and row/column codes.

Survey Programs For Hp Calculators Ti-84

Goback to the HP-67/97
Go backto the software library
Go back to the main exhibit hall