Arithematic Instructions set
The 8086 provides many arithmetic operations : addition, subtraction, negation , multiplication and comparing two values.
The add instruction adds the contents of the source operand to the destination operand.
ADD AX, [5000H]
ADD [5000H], 0100H
Add with carry
This instruction performs the same operation as the add instruction, but adds the carry flag to the result.
The subtract instructiion subtracts the source operand from the destination operand and the result is left in the destination operand.
SUB AX, [5000H]
SUB [5000H], 0100H
SBB : Subtract with borrow
The subtract with borrow instruction subtracts the source operand and the borrow flag (CF) which may reflect the result of the previous calculations, from the destination operand.
SBB AX, [5000H]
SBB [5000H], 0100H
INC : Increment
This instruction increases the contents of the specified register or memory location by 1. Immediate data cannot be operand of this instruction.
DEC : Decrement
The decrement instruction subtract 1 from the contents of the specified register or memory location.
NEG : Negate
The negate instruction forms 2’s complement of the specified destination in the instruction. The destinatiopn can be a register or a memory location . This instruction can be implemented by inverting each bit and adding 1 to it.
AL= 0011 0101 35H Replace number in AL with its 2’s complement
AL = 1100 1011 = CBH
CMP : Compare
This instruction compares the source operand, which may be a register or a memory location, with a destination operand that may be a memory location
CMP AX, 0100H
CMP [5000H], 0100H
CMP BX, [SI]
CMP BX, CX
MUL : Unsigned multiplication byte or word
This instruction multiplies an unsigned byte or word by the contents of AL.
MUL BH ; (AX) (AL) * (AX)
MUL CH ; (DX)(AX) (AX) * (CX)
MUL WORD PTR [SI] ; (DX) (AX) (AX) * ([SI[)
IMUL : Signed multiplication
This instruction multiplies a signed byte in source operand by a signed byte in AL or a signed word in source operand by a signed word in AX.
CBW : Convert signed byte to word
This instruction copies the sign of a byte in AL to all the bits in AH. AH is then said to be sign extension of AL.
AX = 0000 0000 1001 1000 Convert signed byte in AL signed word in AX
Result in AX = 1111 1111 1001 1000
CWD : Convert signed word to double word
This instruction copies the sign of a byte in AL to all the bits in AH. AH is then said to be a signed extension of AL
Convert signed word in AX to signed double word in DX : AX
DX = 1111 1111 1111 1111
Result in AX = 1111 0000 1100 0001
DIV : Unsigned division
This instruction is used to divide the unsigned word by a byte or to divide an unsigned double word by a word.
DIV CL ; word in AX / byte in CL ,quotient im AL , remainder in AH.
DIV CX ; Double word in DX and AX / word in CX and Quotient in AX , remainder in DX.
AAA : ASCII adjust after addition
The AAA instruction is executed after an ADD instruction that adds two ASCII coded operand to give a byte of result in AL . The AAA instruction converts the resulting contents of AI to a unpacked decimal digit.
ADD CL,DL ; [CL] = 32H = ASCII for 2 , [DL] = 35H = ASCII for 5, Result [CL] = 67H
MOV AL, CL ; move ASCII result into AL since AAA adjust only [ AL]
AAA ; [AL] = 07, unpacked BCD for 7
AAS : ASCII adjust AL after subtraction
This instruction corrects the result in AL register after subtracting two unpacked ASCII operands. The result is in unpacked decimal format. THE procedure is similar to AAA instruction except for the subtraction of 06 from AL.
AAM : ASCII adjust after multiplication
This instruction after execution converts the product available in AL into unpacked BCD format.
MOV AL , 04H ; AL= 04H
MOV BL , 09 ; BL = 09
MUL BL ; AX = AL* BL ; AX= 24H
AAM ; AH= 03, AL=06
AAD : ASCII adjust before division
This instruction converts two unpacked BCD digits in AH and AL to the equivalent binary number in AL. This adjustment must be done before dividing the two unpacked BCD digits in AX by an unpacked BCD byte. IN the instruction sequence , this instruction appears before DIV instruction.
AX 05 08
AAD result in AL 00 3A; 58D= 3A h in AL
DAA : Decimal adjust accumulator
This instruction is used to convert the result of the addition of the two packed BCD numbers to a valid BCD number. The result has to be only in AL
AL = 53 CL = 29
ADD AL, CL ; AL (AL) + (CL)
AL 53 +29
DAA ;AL 7C + 06
DAS : Decimal adjust after subtraction
This instruction converts the result of the subtraction of two packed BCD numbers to a valid BCD number. This subtraction has to be AL only
AL = 75, BH= 46
SUB AL, BH ; AL 2F= (AL) – (BH)
DAS ; AL 29 (as F >9, F-6= 9)