3. Instructions
452
CS/CJ/NSJ Series Instructions Reference Manual (W474)
Application example
The following example shows how to take the square root of a 4-digit number and round off the result.
This program example calculates the square root of the 4-digit number in CIO 10, rounds off the result,
and writes it to CIO 11.
1
2
3
4
5
6
@BSET
@MOV
@ROOT
@MOV
@MOV
@MOVD
@MOVD
@INC
10
6 0 1 7
D101 D100
6 0 1 7 0 0 0 0
6017 0000
7756
D100
D101 D100
Square root computation
(Remainder eliminated)
D102
7 7 5 6
CIO 11 D103
0 0 7 7 5 6 0 0
CIO 11
0 0 7 8
In this case, the result is 78.
A ROOT instruction applies to 8-digit data, and
thus data memory D101 and D100 are used.
1. The source words (D101 and D100) are cleared
to 0000 0000.
2. The 4-digit number is moved to D101.
3. ROOT(072) calculates the square root of D101
and D100 and writes the result to D102.
4. D103 and the result word, CIO 11, are cleared
to 0000.
6. If the content of D103 is greater than 4900, CIO
11 is incremented by 1.
5. The result of the square root calculation is
divided by 100, with the integer portion written
to CIO 11 and the remainder going to D103.
0.00
D100
D101
10
D101
D100
D102
11
D103
11
D102
D102
D103
D103 11
The values after the decimal point
should be rounded.
60,170,000 = 7,756.932...