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.{ 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.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.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 C | Stores initial DSZ value |
0002 | LBL LL | Begins loop |
0005 | RCL C | Recalls DSZ value |
0007 | PAU | Displays value |
0008 | DSZ C | Decrements and tests C |
0010 | GTL LL | C ≠ 0 - repeat loop |
0013 | HLT | C = 0 - stop program |
Running the Example
Enter 4 into the display and run the program.Procedure | Press | Display |
---|---|---|
Display RUN menu | [ RUN ] | |
Enter count value | 4 | |
Run the program | { PGM } | |
Program halts when done. |
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 ] | |
Enter count value | 4 [ . ] 3 | |
Run the program | { PGM } | |
Program halts when done. |
Enter -4 into the display, and run the program.
Procedure | Press | Display |
---|---|---|
Display RUN menu | [ RUN ] | |
Enter count value | 4 [ +/- ] | |
Run the program | { PGM } | |
Program halts when done. |
☚ Back