Using Go To Label


The GTL (go to label) instruction transfers program control to the first instruction following a specified label.


Transferring Control To A Label

The normal order of program execution is from program step 000 to the end of the program. By including a GTL instruction in the program, you can transfer program control to any labeled location in the program. The program runs sequentially from the new location until another transfer instruction is executed or the program is stopped.

To enter the GTL instruction, use the key sequence

[ 2nd ] GTL aa

where aa corresponds to the label in the program.

The following instructions show how the GTL instruction affects the flow of program execution. In the first illustration, the GTL instruction causes the program to skip several instructions. In the second illustration, the GTL instruction causes the program to repeat several instructions. Program sequences such as the one in the second illustration are called loops.

Skip Instructions

GTL AA
.  |
.  |
.  |
LBL AA
.
.
HLT



Repeat Instructions

.
.
.
.
LBL ZZ
.  |
.  |
GTL ZZ


Example

A counting loop is a good way to illustrate a transer instruction. The following program uses a transfer instruction to repeat the key sequence + 2 = PAU. The PAU instruction is included in the program so that you can see the result of the + 2 = operation. The GTL AA instruction transfers control back to the beginning of the program, causing the sequence to be repeated endlessly.

By repeating the sequence, the GTL instruction creates a loop that counts by twos.

PC=

Program Mnemonics

Comments


0000LBL AALabels segment
0003 + 2 =Adds two
0006 PAUPauses for one second
0007 GTL AATransfers control to label AA


Because the program does not include a means to exit the loop, this type of loop is called an infinite loop. To stop an infinite loop, you must press [ HALT ] or [ BREAK ]. Methods for exiting a loop under program control are described in the next chapter.

Running the Example

Run the program.

Procedure

Press

Display

Clear the display[ CLEAR ]D_f81IQr
Run the program[ RUN ]
{ PGM }
D_QffoKJ
...D_Xn0ipt
Stop the program[ HALT ]D_dWhgrO



Back