Programming Considerations


This section contains reminders and some general information you should keep in mind while developing your own programs.


Setting Initial Conditions

Programs usually include an initialization routine to establish a known set of conditions. Such a routine may, for example, set calculator parameters and store initial values for the program.

Typically, the initialization routine resides at the beginning of the program and is executed only once.

Although the size and complexity of the routine depend on the complexity of the program, you should consider at least:
  • Setting default conditions ( [ HELP ] ). (Executing [ HELP ] in a program is identical to pressing [ HELP ] { YES } from the keyboard.)
  • Setting partitions for user memory ( [ 2nd ] [ PART ] ). This may not be necessary if you use [ HELP ].
  • Clearing any pending operations, clearing the display, and cancelling scientific notation ( [ CLEAR ] ). This is not necessary if you use [ HELP ].
  • Clearing (resetting) user flags 00-14 ( [ FLAGS ] { CLR } ).
  • Clearing data registers ( [ 2nd ] [ CMS ] ) or storing initial values in specfic registers.

Example

As an example of an initialization routine, the following program segment clears all data registers, selects the decimal number base, clears flags 00-14, and stores the value 12 in data register A.

PC=

Program Mnemonics

Comments


0000CMSClear data registers
0001DECSelect decimal format
0002CFClear flags 00-14
000312 STO AInitialize register A



AOS™ Considerations

As explained in the RPD-95 User's Guide, elements of an expression are not necessarily evaluated in the same sequence in which you enter them.

For example, the AOS feature evaluates the sequence RCL 001 + 3 × 6 as RCL 001 + ( 3 × 6 ). If you want the expression to be evaluated differently, such as ( RCL 001 + 3 ) × 6, include the parentheses in the program.

An immediate function operates only on the displayed value; it does not complete a pending operation before executing.

For example, if you attempt to evaluate the expression ( 2 × 3 )2 by entering 2 [ × ] 3 [ x2 ], the expression is instead evaluated as 2 × 32. To avoid this problem, enter the expression as either [ ( ] 2 [ × ] 3 [ ) ] [ x2 ] or 2 [ × ] 3 [ = ] [ x2 ].

Keep in mind that if you use [ = ] in a subroutine, it completes all pending operations, including any that were pending when the subroutine was called.

Angle-Unit Conversions

Before using a trigonometric function in a program, you must ensure that the appropriate angle unit has been selected. You can use the following table for setting angle units to a known condition from within a program.

Key Sequence

Sets Angle Mode To


[ INV ] [ 2nd ] [ DRG ]Degrees

[ INV ] [ 2nd ] [ DRG ]
[ 2nd ] [ DRG ]
Radians

[ INV ] [ 2nd ] [ DRG ]
[ 2nd ] [ DRG ]
[ 2nd ] [ DRG ]
Grads



Using Labels Correctly

Using program labels simplifies writing and modifying a program. When assigning labels, however, make sure to use a different label for each section of the program.

If you inadvertently assign the same label to two segments of a program, transfer instructions that refer to that label will always transfer control to the first occurrence of the label. You cannot transfer control to another segment that has the same label.

Avoiding Memory Conflicts

If your program stores an alpha message in memory, keep in mind that each message stored - even a short message - occupies 10 contiguous data registers. If you do not allow a sufficient number of registers for a message, it could conflict with other data.

For example, if you have stored a numeric value in data register 018, and then store an alpha message starting at register 015, the numeric value will be over by a portion of the message.

You should also keep in mind that the { QAD } and { CUB } selections of the EXTENDED FUNC menu use data registers. For information on the specific registers involved, refer to the "Math Operations" chapter in the RPD-95 User's Guide.

By planning specific locations for each numeric value and each alpha message, you can avoid such conflicts.

You do not need to avoid conflicts between data registers and the registers used for built-in statistical functions; statistical registers reside in a separate area of the RPD-95 memory.

Saving the t-Register Contents

A few of the calculator's functions, such as polar/rectangular conversions, leave a result in the t-register or expect an input value to be stored there. Each time your program executes such a function, the previous contents of the t-register are lost. If this causes a problem, you can save the t-register contents in a data register.

As an example, the following program segment saves the contents of the t-register in data register 005 without altering either the t-register or the display.

PC=

Program Mnemonics

Comments


0000x~tswap t-register into display register
0001STO 005Save t-register
0004x~tRestore display and t-register



Back