![](http://datasheet.mmic.net.cn/370000/UPD17120_datasheet_16743697/UPD17120_111.png)
CHAPTER 11 ARITHMETIC AND LOGIC UNIT
96
11.3.4 Addition and Subtraction When CMP=1 and BCD=1
BCD operations are performed.
The result is not stored in either the general register or data memory.
In other words, the operations specified by CMP=1 and BCD=1 are both performed at the same time.
Example
MOV
MOV
RPL, #0001B
PSW, #1010B
; Sets the BCD flag (BCD=1).
; Sets the CMP and Z flag (CMP=1, Z=1) and resets the CY flag
; (CY=0).
; <1>
; <2>
; <3>
SUB
SUBC
SUBC
M1, #0001B
M2, #0010B
M3, #0011B
By executing the instructions in steps numbered <1>, <2>, and <3>, the twelve bits in memory
locations M1, M2, and M3 and the immediate data (321) can be compared in decimal.
11.3.5 Cautions on Use of Arithmetic Operations
When performing arithmetic operations with the program status word (PSWORD), caution should be taken with
regard to the result of the operation being stored in the program status word.
Normally, the CY and Z flags in the program status word are set (1) or reset (0) according to the result of the
arithmetic operation being executed. However, when an arithmetic operation is performed on the program status
word itself, the result is stored in the program status word. This means that there is no way to determine if there
is a carry or borrow in the result of the operation nor if the result of the operation is zero.
However, when the CMP flag is set (1), results of arithmetic operations are not stored. Therefore, even in the
above case, the CY and Z flags will be properly set (1) or reset (0) according to the result of the operation.
11.4 LOGICAL OPERATIONS
As shown in Table 11-4, logical operations consist of logical OR, logical AND, and logical XOR. Accordingly, the
logical operation instructions are OR, AND, and XOR.
The OR, AND, and XOR instructions can be performed on either the general register and data memory, or on data
memory and immediate data. The operands of these instructions are specified in the same way as for arithmetic
operations ("r, m" or "m, #n4").
Logical operations are not affected by the BCD or CMP flags in the program status word (PSWORD). Logical
operations do not cause either the CY or Z flag in the program status word (PSWORD) to be set. However, when
the index enable flag (IXE) is set (1), index modification is performed using the index register.