Omron C28K Video Game Controller User Manual


 
!
122
case DM 05 and DM 04 are used to represent the intermediate 4 digits and
the 4 right digits respectively. DM 06 represents the leftmost digit, the 9th dig-
it.
If a carry is generated, SR 1904 (CY) is turned ON and the constant 0001 is
transferred to DM 06. If a carry is not generated SR 1904 remains OFF and
the constant 0000 is transferred to DM 06.
5-16-2 BCD SUBTRACT – SUB(31)
Mi : Minuend word (BCD)
IR, SR, DM, HR, TC, #
Su : Subtrahend word (BCD)
IR, SR, DM, HR, TC, #
Ladder Symbol
Operand Data Areas
R : Result word
IR, DM, HR
SUB(31)
Mi
Su
R
When the execution condition is OFF, SUB(31) is not executed and the next
instruction is moved to. When the execution condition is ON, SUB(31) sub-
tracts the contents of Su and CY from Mi and places the result in R. If the
result is negative, CY is set and the 10’s complement of the actual result is
placed in R. To convert the 10’s complement to the true result, subtract the
content of R from zero (see example below). This instruction will be executed
every cycle as long as the execution condition remains ON. If the instruction
is to be executed only once then it must be used in conjunction with
DIFU(13) or DIFD(14).
Mi – Su – CY CY R
ER: Mi and/or Su is not BCD.
CY: ON when the result is negative, i.e., when Mi is less than Su plus CY.
EQ: ON when the result is 0.
Caution Be sure to clear the carry flag with CLC(41) before executing SUB(31) if its previ-
ous status is not required, and check the status of CY after doing a subtraction
with SUB(31). If CY is ON as a result of executing SUB(31) (i.e., if the result is
negative), the result is output as the 10’s complement of the true answer. To con-
vert the output result to the true value, subtract the value in R from 0.
When 0002 is ON, the following diagram clears CY, subtracts the contents of
DM 01 and CY from the content of IR 10 and places the result in HR 2.
If CY is set by executing SUB(31), the result in HR 2 is subtracted from zero
(note that CLC(41) is again required to obtain an accurate result), the result
is placed back in HR 2, and HR 300 is turned ON to indicate a negative re-
sult.
Description
Flags
Example
BCD Calculations Section 5-16