Mitsubishi Electronics FX2C Home Theater Server User Manual


 
FX Series Programmable Controlers Applied Instructions 5
5-28
5.3.4 DIV (FNC 23)
Operation 1:
(Applicable to all units)
The primar
y
source (S
1
) is divided b
y
the
secondar
y
source (S
2
). The result is stored in the
destination (D). Note the normal rules of al
g
ebra
appl
y
.
Points to note:
a) When operatin
g
the DIV instruction in 16bit mode, two 16 bit data sources are divided into
each other. The
y
produce two 16 bit results. The device identified as the destination address
is the lower of the two devices used to store the these results.
This stora
g
e device will actuall
y
contain a record of the number of whole times S
2
will divide
into S
1
(the quotient).
The second, followin
g
destination re
g
ister contains the remained left after the last whole
division (the remainder). Usin
g
the previous example with some test data:
51 (D0)
÷
10 (D2) = 5(D4) 1(D5)
This result is interpreted as 5 whole divisions with 1 left over (5
×
10 + 1 = 51).
b) When operatin
g
the DIV instruction in 32 bit mode, two 32 bit data sources are divided into
each other. The
y
produce two 32 bit results. The device identified as the destination address
is the lower of the two devices used to store the quotient and the followin
g
two devices are
used to store the remainder, i.e. if D30 was selected as the destination of 32 bit division
operation then D30, D31 would store the quotient and D32, D33 would store the remainder.
If the location of the destination device is smaller than the obtained result, then onl
y
the
portion of the result which directl
y
maps to the destination area will be written. If bit devices
are used as the destination area, no remainder value is calculated.
c) If the value of the source device S
2
is 0 (zero) then an operation error is executed and the
operation of the DIV instruction is cancelled.
Operation 2:
(Applicable units FX
(2C)
) This function is equivalent to FNC 123 EDIV. The
information re
g
ardin
g
‘Operation2:’ of the MUL instruction appl
y
similarl
y
to this second
operation of the DIV instruction (with the exception of a division bein
g
performed instead of a
multiplication). A
g
ain, onl
y
constants and double data words can be manipulated with onl
y
DDIV, DDIVP instruction formats bein
g
valid. Answers for an operation are stored
(completel
y
) in one pair of double (32 bits) data re
g
isters, i.e. answers are not split in to
quotient and remainder as in ‘Operation 1:’. The normal rules of al
g
ebra appl
y
to floatin
g
point division.
Mnemonic Function
Operands
Program steps
S1 S2 D
DIV
FNC 23
(Division)
Divides one
source value b
y
another the result
is stored in the
destination device
K, H, KnX, KnY, KnM, KnS,T,
C, D, V, Z
KnY, KnM, KnS,
T, C, D, Z(V)
DIV,DIVP:
7steps
DDIV,
DDIVP:
13 steps
See pa
g
e 4-46 for more
details re
g
ardin
g
floatin
g
point format.
Note: Z(V) ma
y
NOT
be used for
32 bit operation
When usin
g
M8023 to subtract floatin
g
point
data, onl
y
double word (32 bit) data re
g
isters
(D) or constants (K/H) ma
y
be used.used to
perform
X0
DIV D 0 D 2
[ S1 ] [ D ]
D 4
[ S2 ]