Indirect Transfer of Program Control


Indirect addressing enables a transfer instruction to transfer control to a location specified by the contents of a data register.


Indirect GTL

To include an indirect GTL instruction in a program, use the key sequence [ 2nd ] [ GTL ] [ 2nd ] [ IND ] nnn or X. Indirect GTL transfers program control to the program label stored in register nnn or X.

For example, if the leftmost two characters in data register B are AA, the instruction sequence GTL IND B transfer program control to label AA.

Alpha characters can be stored in a data register by using:
  • The { STA } (store alpha message) function. Keep in mind that { STA } uses 10 data registers, although the indirect GTL instruction needs only the two leftmost characters of the first data register.
  • The STB (store byte) function. This function is described in Appendix A.
  • The STO function with the calculator in unformatted display mode. Unformatted display mode is desribed in Appendix A.

Indirect GTO

To include an indirect GTO instruction in a program, use the key sequence [ INV ] [ 2nd ] [ GTL ] [ 2nd ] [ IND ] nnn or X. Indirect GTO transfers program control to the step address stored in register nnn or X.

For example, if data register D contains 444, the instruction sequence GTO IND D transfer program control to program address 0444.

Indirect SBL

To include an indirect GTO instruction in a program, use the key sequence [ 2nd ] [ SBL ] [ 2nd ] [ IND ] nnn or X. Indirect SBL calls the subroutine specified by the label stored in register nnn or X.

For example, if the leftmost two characters in data register F are BB, the instruction sequence SBL IND F calls the subroutine labled BB.

Indirect SBR

To include an indirect SBR instruction in a program, use the key sequence [ INV ] [ 2nd ] [ SBL ] [ 2nd ] [ IND ] nnn or X. Indirect SBR calls the subroutine specified at the step address specified by the contents of register nnn or X.

For example, if data register D contains 444, the instruction sequence SBR IND D calls the subroutine at program address 0444.

Using Indirect Transfers from the Keyboard

Using indirect GTL or GTO as a keyboard command sets the program counter to the label or step address specified by the contents of the pointer register, but does not start execution of the program.

Using indirect SBL or SBR as a keyboard command starts program execution at the label or step address specified by the contents of the pointer register, but does not store a return address.

Example 1

The following program calculates the step address of one of three routines, based on a number you enter, and uses GTO IND to execute the routine.

If you use this method of indirect transfer:
  • The address of the first routine must be known to the program.
  • You must allocate an equal amount of memory for each of the routines to be executed. (Note the NOPs placed after the HLT instruction for routines 1 and 2.)

PC =

Program Mnemonics

Comments

0000 CLRClears calculator
0001 14 STO AStores length of routines
0005 49 STO BStores start of routines
0009 DFN F1:ENT@ENDefines F1
0016 `ROUTINE (1-3)?`Creates prompt
0030 HLTStops program
0031LBL ENLabels segment
0034 -1=Adjusts multiplier
0037 * RCL A + RCL B =Calculates routine address
0044 STO CStores routine address
0046 GTO IND CExecutes routine indirectly
0049 `ROUTINE ONE`Routine one message
0060 HLT NOP NOPEnd of routine
0063 `ROUTINE TWO`Routine two message
0074 HLT NOP NOPEnd of routine
0077 `ROUTINE THREE`Routine three message
0090 HLTEnd of routine



Running Example 1

When you run the program, you are prompted to identify the routine you want to execute by entering a number between 1 and 3. When you enter the number and press { ENT }, the program subtracts 1 from the number to produce a multiplier of 0, 1, or 2. The program then uses the multiplier to calculate the address of the routine and executes the routine by indirect transfer.

Procedure

Press

Display

Run the program4
[ RUN ]
{ PGM }
D_FpaCP0
Specify routine 22
{ ENT }
D_wXtxKD
D_IGOov5
Specify routine 11
{ ENT }
D_Pu4bGW
D_FqBXl7
Specify routine 33
{ ENT }
D_bj03Ho
D_J2mIyl
Specify nonexistent routine4
{ ENT }
D_Fg0FNs
D_AbdEvH
Clear the error[ CLEAR ]D_JZ7aeD

Note:

To avoid the error message or possible execution of the wrong instructions, you could use test instructions within the program to ensure the entered number is within the 1-3 limit before executing the indirect transfer.

Example 2

You may not want to allocate an equal amount of memory for each routine. You can overcome this limitation by creating an intermediate list of GTL instructions. The program indirectly transfers to a GTL instruction in this list, which transfers execution in turn to a final routine. The advantage of the intermediate list is that the entries in the list are all the same length. Thus, you can use the technique illustrated in Example 1 to address them indirectly. The final routines can be different lengths, as illustrated by this example.

PC =

Program Mnemonics

Comments

0000 CLRClears calculator
0001 3 STO AStores length of routines
0004 48 STO BStores start of routines
0008 DFN F1:ENT@ENDefines F1
0015 `ROUTINE (1-3)?`Creates prompt
0029 HLTStops program
0030LBL ENLabels segment
0033 -1=Adjusts multiplier
0036 * RCL A + RCL B =Calculates routine address
0043 STO CStores routine address
0045 GTO IND CExecutes routine indirectly
0048 GTL AATransfers to routine 1
0051 GTL BBTransfers to routine 2
0054 GTL CCTransfers to routine 3
0057LBL AALabels segment
0060 `ONE`Short alpha message
0063 HLTEnd of routine 1
0064LBL BBLabels segment
0067 1.0045*2.012=Longer routine
0080 HLTEnd of routine 2
0081LBL CCLabels segment
0084 CLRVery short routine
0085 HLTEnd of routine 3

Run the program and try the three options.


Back