# Arithematic Instructions set

Posted By on September 15, 2014

ARITHMETIC INSTRUCTIONS

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.
Eg.

This instruction performs the same operation as the add instruction, but adds the carry flag to the result.
Eg.

SUB: Subtract
The subtract instructiion subtracts the source operand from the destination operand and the result is left in the destination operand.
Eg.

SUB AX,0100H
SUB AX,BX
SUB AX,[SI]
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.
Eg.

SBB AX,0100H
SBB AX,BX
SBB AX,[SI]
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.
Eg.
INC AX
INC [BX]
INC [5000H]

DEC : Decrement
The decrement instruction subtract 1 from the contents of the specified register or memory location.
Eg.
DEC AX
DEC [5000h]

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.
Eg
NEG AL
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
Eg.
CMP BX,0100H
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.
Eg.
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.
Eg.
IMUL BH
IMUL CX
IMUL [SI]

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.
Eg.
CBW
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
Eg,
CWD
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.
Eg
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.

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.
Eg.
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.
Eg.
MOV AL , 04H ; AL= 04H
MOV BL , 09 ; BL = 09
MUL BL ; AX = AL* BL ; AX= 24H
AAM ; AH= 03, AL=06

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.
Eg.
AX 05 08
AAD result in AL 00 3A;  58D= 3A h in AL

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
Eg.
AL = 53      CL = 29
ADD AL, CL       ;  AL (AL) + (CL)
AL      53 +29
AL 7C
DAA       ;AL  7C + 06
;AL 82

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
Eg.
AL = 75, BH= 46
SUB AL, BH                ; AL        2F= (AL) – (BH)
AF= 1
DAS                            ; AL   29  (as F >9, F-6= 9)

#### Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com