Using Program Labels


A program label is an instruction that you can use to identify a particular location in a program. Typically, you use a label to mark the beginning of a sequence of instructions to which you plan to transfer program control.


Labeling a Program Segment

To place a label instruction in a program, use the key sequence:
[ 2nd ] [ LBL ] aa
where aa is any two alphanumeric characters. For example, [ 2nd ] [ LBL ] AA places the mnemonic "LBL AA" in a program at the current location of the program counter.

After you press [ 2nd ] [ LBL ], the calculator interprets your next keystrokes as alphanumeric characters. This eliminates the need for your to activate the alpha mode to enter the two characters of the label. You can use any combination of uppercase and lowercase letters, digits, and punctuation symbols in the label name.

Some examples of labels are shown below.

Label

Key Sequence

LBL fx[ 2nd ] [ LBL ] [ 2nd ] [ F ] [ 2nd ] [ X ]
LBL 10[ 2nd ] [ LBL ] [ 1 ] [ 0 ]
LBL Z1[ 2nd ] [ LBL ] [ 2nd ] [ Z ] [ 1 ]
LBL Aa[ 2nd ] [ LBL ] [ A ] [ 2nd ] [ A ]
LBL 0?[ 2nd ] [ LBL ] [ 0 ] [ 2nd ] [ ? ]


You can lable any part of a program; the presence of the label does not interfere with program execution or any calculations in progress in the program.

You can use as many labels as you need in a program. However, you should not use the same label more than once in the same program. If you repeat a label, any transfer to that label is always directed to the first occurrence of the label. (The calculator begins searching for a label at program address 0000 and will not find the additional occurrences of the label.) Refer to "Listing Program Labels" in this chapter for details on listing the labels used in program memory.

Why Use Labels?

The field of a transfer instruction must specify a transfer location. Although you can identify the transfer location by giving its step address, it is more flexible to use a label. A label provides you with a method of identifying a program location that is not dependent upon the numeric address of the location.

The step address of an instruction changes when you insert or delete instructions ahead of it. By using a label to identify a program location, you do not have to keep track of these changes. The relative location of the label remains constant, eliminating the need to correct any numeric transfer addresses each time you insert or delete other program instructions.

Consider a program that contains the segment shown below. If you insert a RCL B instruction before this segment, you change the address of all instructions that follow the inserted instruction.

Before Insertion

After Insertion

PC =

Mnemonic

PC =

Mnemonic

0130* PI =0130RCL B
0133PAU0132* PI =
0135PAU

Without the labels, you must change any transfer references to the * instruction originally located at 0130 to show that the new location of the instruction is 0132. If a program has many such references, correcting them is time-consuming and can cause mistakes.

With labels, you can insert an instruction without correcting any references.

Before Insertion

After Insertion

PC =

Mnemonic

PC =

Mnemonic

0130LBL AA0130RCL B
0133* PI =0132LBL AA
0136PAU0135* PI =
0138PAU

The segment still begins at the point marked by LBL AA. Any transfer to LBL AA now transfers to step 135 instead of step 133.


Back