![Omron CVM1D Operation Manual Download Page 252](http://html1.mh-extra.com/html/omron/cvm1d/cvm1d_operation-manual_742532252.webp)
247
Example
The following example shows how to use DIVL(77) to calculate the average of
100 four-digit numbers. These numbers are added and divided using the long
versions of the instructions so that the answer can be rounded to preserve accu-
racy. This example illustrates not only the use of DIVL(77), but also the use of
several other instructions and the use of indirect addressing.
The following words and bits are used in this program.
Bit/word
Application
CIO 000000
Controls execution of the program.
D00101 and D00102
Hold the result of the addition.
D00000
Points to the next word to be added.
A50005 through A50007
(Less Than, Equals, and
Greater Than Flags)
Control execution in combination with CMP(020) to
end addition and initiate division when the 100th
number has been added and to add 1 when rounding
up the result is required.
CIO 0200 and 0201
Hold the next values to be added.
D00103 through D00105
Hold the results of division (D00105 is remainder).
CIO 0010 through CIO 0012
CIO 0012 outputs the average and CIO 0010 and
0011 output the sum of the 100 numbers.
When CIO 000000 is ON in the following example, the first two lines in the pro-
gram clear words used in the remainder of the program. The remainder of the
instruction block from CMP(020) adds consecutive numbers indirectly ad-
dressed through D00000. The numbers are moved to CIO 0200 so that long
addition is possible (CIO 0201 is always zero).
When 100 numbers have been added, the CMP(020) instructions end the addi-
tion and start the division, rounding, and output procedure. The result is rounded
by incrementing D00103 when the remainder from the division is greater than
0049. Finally, XFER(040) is used to places the results in I/O words for output to
an external device, e.g., a display device.
BCD Calculation Instructions
Section 5-18
Summary of Contents for CVM1D
Page 462: ...SYSMAC CVM1D Duplex System Programmable Controllers Operation Manual Revised August 2001...
Page 463: ...iv...
Page 465: ...vi...