Using DSZ Tests


A DSZ test combines two operations into a single instruction. First, it decrements the value in a specified data register. Then, it tests whether the value has reached zero. A DSZ test is particularly useful to limit the number of times a loop repeats.


Available DSZ Tests

When you press [ TESTS ], you can select one of two DSZ tests.
D_9Wf8v5
{ DSZ } - Decrement and skip if zero
[ INV ] { DSZ } - Decrement and execute if zero.

Rules Used in Decrementing

In a DSZ test, "decrement" means that the value in the data register approaches zero, based on the following rules.
  • If the stored value is greater than 1, the DSZ test subtracts 1 from the value.
  • If the stored value is less than -1, the DSZ test adds 1 to the value.
  • If the value is between -1 and 1, the DSZ test stores a zero in the register.

Performing a DSZ Test

To include a DSZ test in a program, use one of the following key sequences:
[ TESTS ] { DSZ } nnn or X
[ TESTS ] [ INV ] { DSZ } nnn or X

Decrement and Skip if Zero

The "decrement and skip if zero" test decrements the value in a specified data register and then tests if the register value equals zero. If the register value does equal zero, the program skips the instruction that immediately follows the DSZ test. If the register value does not equal zero, execution continues in normal sequential order.
dsz

Decrement and Execute if Zero

The "decrement and execute if zero" test decrements the value in a specified data register and then tests if the register value equals zero. If the register value does not equal zero, the program skips the instruction that imediately follows the INV DSZ test. If the register value does equal zero, execution continues in normal sequential order.
invdsz

Example

The DSZ tests offer you a convenient and accurate method of executing a program sequence a predetermined number of times. By using either DSZ or INV DSZ, you can control whether the instruction following the test is executed a specific number of times or skipped a specific number of times.

The following program illustrates the operation of a DSZ test in a loop. The program allows you to enter the initial register value for the DSZ test. It then displays the contents of that data register each time the loop executes.

PC =

Program Mnemonics

Comments

0000 STO CStores initial DSZ value
0002LBL LLBegins loop
0005 RCL CRecalls DSZ value
0007 PAUDisplays value
0008 DSZ CDecrements and tests C
0010 GTL LLC ≠ 0 - repeat loop
0013 HLTC = 0 - stop program



Running the Example

Enter 4 into the display and run the program.

Procedure

Press

Display

Display RUN menu[ RUN ]D_RZ2K7x
Enter count value4D_GMp1aJ
Run the program{ PGM }D_ZuYufl
D_rVGzRT
D_cVpnKx
D_gffVdR
Program halts when done.D_Uw2tbf

Notice that 0 is not displayed. When the data register is decremented to zero, the program exits the loop and stops the program.

The following shows what appears in the display if you run the program with a negative number and with a number that contains a fractional part.

Enter 4.3 into the display and run the program.

Procedure

Press

Display

Display RUN menu[ RUN ]D_RZ2K7x
Enter count value4 [ . ] 3D_6efqaH
Run the program{ PGM }D_rHRY0S
D_aVQe2k
D_3oVyMH
D_PDAk0r
D_e4e47S
Program halts when done.D_iN1V8V



Enter -4 into the display, and run the program.

Procedure

Press

Display

Display RUN menu[ RUN ]D_RZ2K7x
Enter count value4 [ +/- ]D_h5tHbc
Run the program{ PGM }D_QGqcuH
D_tlhNTg
D_qTtkeK
D_xTyg2A
Program halts when done.D_5NS6Di



Back