Print | Rate this content

HP 9G Calculator - Programming the Calculator

This document provides the fundamental information needed to program the HP 9G calculator.

Getting started

All programming takes place in the program mode of the calculator.

Program mode

Follow the steps below to get the HP 9G calculator into the program mode:

  1. Press the MODE key.

  2. Press the left or right arrow key (or the MODE key) until 3 PROG is underlined.

  3. Press ENTER .

    A shortcut to the program menu is to press MODE , then the number 3 .

    The program menu (shown in Figure 1) will be displayed.

    Figure 1: Program menu

The options in the program menu are:

  • 0 NEW: Use to create a new program.

  • 1 RUN: Use to execute a program.

  • 2 EDIT: Use to edit a program.

  • 3 DEL: Use to delete a program.

  • 4 TRACE: Use to trace a program.

  • 5 EXIT: Use to exit program mode.

To select an item from the program menu, follow these steps:

  1. Either press the number of the menu item, or use the arrows to move to the correct item.

  2. Press ENTER while the item is underlined.


Creating a new program

This section explains the program settings and gives the steps for creating a new program in the calculator.

Program settings

Program settings must be selected for each new program. When choosing NEW from the program menu, the program settings menu will be displayed (as shown in Figure 2). To select each setting from the menu, either press the number of the setting, or use the arrows to move to the correct setting, then press ENTER while the setting is underlined.

Figure 2: Program settings

Each program setting is described below:

  • Number of remaining steps : The program capacity is 400 steps. The number of remaining steps indicates the amount of storage space available for programs. This number will decrease as programs are input, and when steps are converted to memories.

  • Program type : This setting specifies the calculation mode the calculator will be in when executing the program. To perform binary, octal, or hexadecimal calculations or conversions, choose BaseN ; otherwise choose MAIN .

  • Program area : There are ten program areas for storing programs (P0-P9). If an area has a program stored in it, its number is displayed as a subscript (as in P1 ).

Creating the new program

Follow the steps below to create a new program in the calculator:

  1. In the program menu (shown in Figure 1), select NEW and then press ENTER .

  2. Choose the program settings. (See the Program settings section above for details).

    1. Select the program type and press ENTER .

    2. Select one of the ten program areas (P0123456789 ) and press ENTER .

  3. Enter the program's commands.

    • Any of the calculator's regular functions can be entered as commands.

    • To enter a program control instruction, press 2nd , INST , and make your selection. (See the Program control instructions section).

    • To enter a space, press ALPHA , then SPC .

  4. A semicolon (;) indicates the end of a command.

    To enter more than one command on a command line, separate them with a semicolon.

    For example:

    Line 1: INPUT A; C=0.5 x A; PRINT "C="C; END

    You can also place each command or group of commands on a separate line. No trailing semicolon is needed.

    For example:

    Line 1: INPUT A; C=0.5 x A ENTER

    Line 2: PRINT "C="C; END


Executing a program

After entering or editing a program, press CL/ESC to return to the program menu. Follow the steps below to run the program.

  1. Select RUN and press ENTER (or press PROG in MAIN mode).

  2. Select the relevant program area and press ENTER to begin executing the program.

  3. To re-execute the program, press ENTER while the program's final result is on the display.

  4. To abort the execution of a program, press CL/ESC . A confirmation message (shown in Figure 3) appears.

    Figure 3: Stop-confirmation message

  5. Press the right arrow to move the cursor to Y and then press ENTER .


Debugging a program

When a program displays an error message or produces unexpected results, there is an error in the program that needs to be corrected.

Error messages appear for approximately five seconds, and then the cursor blinks at the location of the error. To correct an error, in the program menu select EDIT .


Using the display result command

A command can be placed in a program in order to stop the program at that point and display the value of a variable at that stage of program execution. Follow the steps below:

  1. At the point in the program where you want to check the value of a variable, press the ALPHA key, then press the + key.

  2. Run the program. Execution is interrupted at the point where the was placed.

  3. Press 2nd , then VRCL to view the value of the corresponding memory variable (C in the example shown below).

  4. To resume program execution, press ENTER .


    Line 1: INPUT A; B=ln (A + 100)

    Line 2: C=13 x A;

    Line 3: D=51 / (A x B)

    Line 4: PRINT "D=", D; END


Deleting a program

To delete a program from the calculator, follow these steps:

  1. In the program menu, select DEL , and then press ENTER .

  2. Select from the following choices:

    • To erase a single program, select ONE , the program area to erase, and then press ENTER .

    • To erase all the programs, select ALL .

  3. A message will be displayed to confirm that you want to delete the program(s). (See Figure 4).

    Figure 4: Delete-confirmation message

  4. Press the right arrow to move the cursor to Y and then press ENTER .

  5. In the program menu, press EXIT to exit DEL mode.


Using the graph function in programs

Use the graph function in programs to graphically illustrate long or complex equations and to repeatedly overwrite graphs. All commands except trace and zoom can be included in programs. Range values can also be specified in the program.

The values in some graph commands must be separated by commas ( , ) as follows:

  • Range (Xmin, Xmax, Xscl, Ymin, Ymax, Yscl)

  • Factor (Xfact, Yfact)

  • Plot (Xpoint, Ypoint)


Using the program control instructions

Most of the programming commands for the HP 9g calculator can be accessed from the program control instructions (shown in Figure 5). To display these instructions, press 2nd , then INST .

Figure 5: Program control instructions menu

Each of these commands is explained below.

Clear screen command

  • CLS

    Clears the display on the screen.

Input and output commands

  • INPUT memory variable

    Makes the program pause for data input. memory variable =| appears on the display. Enter a value, then press ENTER . The value is assigned to the specified variable and the program resumes. When inputting more than one variable, separate them each with a semicolon (;).

  • PRINT "text" memory variable

    Prints the text specified inside the double quotation marks and the value of the specified memory variable.

Conditional branching

  • IF (condition) THEN {statement}

    If the condition is true, the THEN statement is executed.

  • IF (condition) THEN {statement}; ELSE {statement}

    If the condition is true, the THEN statement is executed, otherwise the ELSE statement is executed.

Jump commands

  • Lbl n

    An Lbl n command marks a destination point for a GOTO n jump command.Each label name (Lbl) must be unique (that is, not repeated in the same program area). The label suffix n must be an integer from 0 to 9.

  • GOTO n

    When an executing program encounters a GOTO n statement, execution jumps to Lbl n (where n is the same value as the n in the GOTO n statement).

    NOTE: The GOTO n command does not allow jumps between program areas. A GOTO n command only jumps to the corresponding label (Lbl) within the same program area. To jump between program areas, use the GOSUB PROG n command.

Mainroutine and subroutine

  • GOSUB PROG n ;

    A program can be written to jump between program areas, executing code from different program areas. The program from which other program areas are jumped to is the mainroutine, and an area jumped to is a subroutine. To cause a jump to a subroutine, enter PROG n where n is the number of the destination program area.

  • End

    Each program needs an END command to mark the end of the program. This is displayed automatically whenever a new program is created.

Increment and decrement

  • Post-fixed: Memory variable ++ or Memory variable - -

    Pre-fixed: ++ Memory variable or - - Memory variable

    A memory variable is increased or decreased by one. For standard memory variable, the ++ (increment) and - - (decrement) operators can be either post-fixed or pre-fixed. For array variables, the operators must be pre-fixed.

    With pre-fixed operators, the memory variable is computed before the expression is evaluated. With post-fixed operators, the memory variable is computed after the expression is evaluated.

For loop

  • FOR (start condition; continue condition; re-evaluation) {statements}

    A FOR loop is used for repeating a set of similar actions while a specified counter is between certain values.

Sleep command

  • SLEEP (time)

    A SLEEP command suspends program execution for a specified time (up to a maximum of 105 seconds). This is useful for displaying intermediate results before resuming execution of the program.

Swap command

  • SWAP (memory variable A, memory variable B)

    The SWAP command swaps the contents of two memory variables.

Relational operators

The relational operators that can be used in FOR loops and conditional branching are shown in the table below:

Equal to.
Less than.
Greater than.
Not equal to.
Less than or equal to.
Greater than or equal to.


Provide feedback

Please rate the information on this page to help us improve our content. Thank you!