The arithmetic operation instruction of 886 can add, subtract, multiply and Divison binary or decimal (BCD code) numbers, and the data form of operands can be 8-bit or 16-bit unsigned numbers or signed numbers. For single operand instructions, immediate form is not allowed; For a two-operand instruction, only the source operation can use the immediate number, and one of the two operands must be in the register.
1. instruction format of addition instruction: addition ADD DST, SRC;; (DST)←(SRC)+(DST)
ADC with carry addition dst, src; (DST)←(SRC)+(DST)+CF
plus 1 INCOPR; (OPR)←(OPR)+1
Note: the operation results of these three instructions will affect the status flag bit, but the INC instruction will not affect the flag CF. Let's take the 8-digit addition operation as an example for a brief explanation. [Example 4.2] Because the operation result does not exceed the range of unsigned number of single byte, CF = ; The operation result is beyond the range of signed number of single byte, so of = 1; Other signs ZF=, SF=1. The above operations can be realized by two instructions: MOV AH, 1 ADD AH, 7FH
ADC instructions are mainly used for the addition of multi-byte or multi-precision data. For example, when two groups of four-byte (double-precision) numbers 1122 3344H and 5566 7788H are added, the single-byte addition instruction needs to perform four addition operations. During the operation, the carry generated by the low-byte operation is added to the high-byte by the ADC instruction, while the word addition instruction only needs to perform two addition operations, and of course, the carry generated by the low-word operation must also be processed by the ADC instruction. To use ADC instruction, the CF flag must be set to first. 2. subtraction instruction
instruction format:
subtraction SUB DST, src; (DST)←(DST)-(SRC)
carry subtraction SBB DST, src; (DST)←(DST)-(SRC)-CF
minus 1decopr; (OPR)←(OPR)-1
complement negopr; (opr) ← ffffh-(pr)+1
Compare CMP OPR1, opr2; (OPR1)-(OPR2)
SBB instruction is mainly used for the subtraction of multi-byte or multi-precision data; NEG instruction negates the operand and adds 1; CMP instruction performs SUBtraction operation similar to sub instruction, but it does not produce operation result. See Table 4.3 for the influence on flag bit. The operation results of these instructions all affect the status flag bit, but the DEC instruction does not affect the flag CF.
[Example 4.22]
The result of direct subtraction formula is: (46AH)=52FH, SF=, ZF=, CF=, OF=
The result of complement addition formula is: (46AH)=52FH, SF=, ZF.
it can be seen that the operation results in the two formulas are the same, but the influence on the flag CF is different, because it is a subtraction operation, and the correct result should be CF=. The operation result CF=1 is obtained by complement addition, which should be inverted and sent to CF. Table 4-3 Influence of CMP instruction on status flag bit
3. Multiplication instruction Multiplication operation is divided into unsigned number operation and signed number operation, each with corresponding instruction and using double operands. Multiply two 8-bit binary numbers and the product is a 16-bit binary number; Two 16-bit binary numbers are multiplied and the product is a 32-bit binary number. Instruction format:
unsigned number multiplication mulsrc; (AX)←(AL)×(SRC)8-digit multiplication
(DX, AX)←(AX)×(SRC)16-digit multiplication
signed number multiplication imulsrc; The operation is the same as above, but the operand is a signed number
Note:
When performing byte operation, the destination operand must be the accumulator AL, and the product is in the register AX; When performing a word operation, the destination operand must be the accumulator AX, and the product is in the registers DX and AX. Immediate addressing is not allowed for source operands.
the result OF multiplication instruction only affects the status flags CF and of, but has no effect on other status flags (the status is uncertain).
for MUL instruction, if the product (ah) of byte data multiplication is or the product (dx) of word data multiplication is , then CF=OF=, otherwise cf = of = 1; For the IMUL instruction, if the content of the product AH of byte data multiplication or the product DX of word data multiplication is the sign extension of the lower half, then CF=OF=, otherwise CF=OF=1.
4. Division instruction Division operation is divided into unsigned number operation and signed number operation, each with corresponding instruction and using double operands. When the divisor is an 8-bit or 16-bit binary number, the dividend is required to be a 16-bit or 32-bit binary number. Instruction format:
unsigned number division DIV SRC;; (al) ← (ax)/(src) quotient of division of 8-bit binary number
(ah) ← (ax)/(src) remainder of division of 8-bit binary number
or (AX)←(DX, Ax)/(src) quotient of 16-bit binary number division
(DX)←(DX, ax)/(src) remainder of 16-bit binary number division
signed number division IDIV SRC;; The operation is the same as above, but the operand is a signed number
Note:
When the divisor is byte data, the dividend must be placed in AX, and when the divisor is word data, the dividend must be placed in DX and AX.
the result of the division instruction operation has no definition of the status flag (the status is uncertain). However, if the divisor is or signed, when the result OF division exceeds the specified range, an interrupt of will be generated, regardless of the overflow flag of.
886/888 stipulates that the sign of the remainder of the operation result of the IDIV instruction is the same as the dividend.
in the signed number division operation, when the number of digits of the dividend is insufficient, it is necessary to expand the dividend to the required number of digits. 886/888 has a signed number extension instruction.
instruction format:
bytes are extended to the word CBW;; The sign bit in the register AL is extended to the register AH
word and to the double word CWD;; The two instructions of extending the sign bit in register AX to register DX
do not affect the flag bit.
5. Decimal adjustment instruction BCD code is a decimal number encoded by binary, also known as binary-decimal number. BCD code in 886/888 is divided into two forms: one is to represent a decimal number with four binary digits, which is called compressed BCD code; The second is to represent a decimal number with an eight-bit binary number, which is called uncompressed BCD code. Its lower four bits are BCD codes, and its upper four bits are meaningless. Because BCD code is a four-bit binary code, four-bit binary number * * * has 16 codes, only 1 of which are used in BCD code, and the other useless codes are called invalid codes. Errors will occur when BCD code operation results enter or skip invalid code areas. In order to get the correct results, adjustments must be made. 886/888 has two sets of decimal adjustment instructions for compressed BCD codes and uncompressed BCD codes, and their adjustment methods are slightly different.
(1) compress BCD code decimal adjustment instruction instruction format:
add decimal adjustment DAA;; (AL)← adjust the sum in AL to compressed BCD code format
subtract decimal adjustment DAS;; (AL)← Adjust the difference in AL to the compressed BCD code format < P > The adjustment method is: < P > If the lower 4 bits of the accumulator AL are greater than 9 or the auxiliary carry flag bit AF = 1, the accumulator AL will be corrected by adding 6H. If the upper 4 bits of the accumulator AL are greater than 9 or the carry flag Cy = 1, the accumulator AL is corrected by adding 6H. If the upper 4 bits of the accumulator AL are greater than or equal to 9 and the lower 4 bits are greater than 9, the accumulator AL will be corrected by adding 66H.
[Example 4.26] BCD code addition operation 59+68=127
In this example, the low four bits of the BCD code addition result make AF=1 and the high four bits are greater than 9, so 66H is added for correction.
note: the decimal adjustment instruction OF adding or subtracting compressed BCD code must be used after the ADD(ADC) or SUB(SBB) instruction, and the adjustment result has no influence on the flag of, but has influence on other status flag bits.
The subtraction decimal adjustment method is similar to the addition decimal adjustment, except that adding 6 is changed into subtracting 6.