![](http://datasheet.mmic.net.cn/370000/UPD17134ACT-xxx_datasheet_16740627/UPD17134ACT-xxx_110.png)
CHAPTER 11 ARITHMETIC AND LOGIC UNIT (ALU)
91
11.3 ARITHMETIC OPERATIONS (ADDITION AND SUBTRACTION IN 4-BIT BINARY AND BCD)
As shown in Table 11-3, arithmetic operations consist of addition, subtraction, addition with carry, and subtraction
with borrow. These instructions are ADD, ADDC, SUB, and SUBC.
The ADD, ADDC, SUB, and SUBC instructions are further divided into addition and subtraction of the general
register and data memory and addition and subtraction of data memory and immediate data. When the operands
r and m are used, addition or subtraction is performed using the general register and data memory. When the operands
m and #n4 are used, addition or subtraction is performed using data memory and immediate data.
Arithmetic operations are affected by the status flip-flop and the program status word (PSWORD) in the system
register. The BCD flag in the program status word is used to specify whether arithmetic operations are to be performed
in 4-bit binary or in BCD. The CMP flag is used to specify whether or not the results of arithmetic operations are to
be stored.
11.3.1 to 11.3.4 explain the relationship between each command and the program status word.
Table 11-3. Types of Arithmetic Operations
11.3.1 Addition and Subtraction When CMP = 0 and BCD = 0
Addition and subtraction are performed in 4-bit binary and the result is stored in the general register or data memory.
When the result of the operation is greater than 1111B (carry generated) or less than 0000B (borrow generated),
the CY flag is set (1); otherwise it is reset (0).
When the result of the operation is 0000B, the Z flag is set (1) regardless of whether there is carry or borrow;
otherwise it is reset (0).
11.3.2 Addition and Subtraction When CMP = 1 and BCD = 0
Addition and subtraction are performed in 4-bit binary.
However, because the CMP flag is set (1), the result of the operation is not stored in either the general register
or data memory.
When there is a carry or borrow in the result of the operation, the CY flag is set (1); otherwise it is reset (0).
When the result of the operation is 0000B, the previous state of the Z flag is retained; otherwise it is reset (0).
General register and data memory
ADD r, m
Data memory and immediate data
ADD m, #n4
General register and data memory
ADDC r, m
Data memory and immediate data
ADDC m, #n4
General register and data memory
SUB r, m
Data memory and immediate data
SUB m, #n4
General register and data memory
SUBC r, m
Data memory and immediate data
SUBC m, #n4
Without carry ADD
With carry ADDC
Without borrow SUB
With borrow SUBC
Addition
Subtraction
Arithmetic
operation