Arithmetic Instructions

 

2] Arithmetic Instructions

            The instructions in this group are used to perform various arithmetic operations on 8/16 bit data. The instructions in this group affect conditional flags (CF, AF, PF, SF, OF) in flag register.     

     

1] ADD

                        Syntax –



 

            This instruction is perform addition of destination & Source and stored result in destination. The source can be 8/16 bit register, memory location or immediate data (number). Destination can be 8/16 bit register, memory location. This instruction affect all 6 conditional flags.

 Destination = Destination + Source

Example,        ADD AL,04H            ……(AL = AL + 04)

                        ADD AL,BL              ……(AL = AL + BL)

                        ADD AH,[2000]

                        ADD [4000],AX

1)     Program Title: - WALP to 44H & 57H in AL & BL register respectively, perform the addition & store the sum on memory location [2000]. DS = 0200H

Register & Memory Address Used: - AL, BL & [2000]

Data: - 44H, 57H & 0200H

Address

Op-code

Label

Mnemonic

Operand

Comments

 

 

 

MOV

AX,0200

Initialization of DS

 

 

 

MOV

DS,AX

 

 

 

 

MOV

AL,44H

;COPY 44H IN AL

 

 

 

MOV

BL,57H

;COPY 57H IN BL

 

 

 

ADD

AL,BL

;ADD CONTENTS OF BL WITH AL & RESULT SOTRED IN AL

 

 

 

MOV

[2000],AL

COPY CONTENTS OF AL ON MEMORY LOCATION [2000]

 

 

 

INT

03

STOP

 

Result:-

DS   : OFFSET : DATA

0200:  [2000]    : 9B

 

2)     Program Title: - WALP to 1122H in AX & 4455H in SI register, perform the addition & store 16 bit result of addition on memory location [3000]. DS = 0400H

Register & Memory Address Used: - AX, SI & [3000]

Data: - 1122H, 4455H & 0400H

Address

Op-code

Label

Mnemonic

Operand

Comments

 

 

 

MOV

AX,0400

Initialization of DS

 

 

 

MOV

DS,AX

 

 

 

 

MOV

AX,1122H

;COPY 1122H IN AX

 

 

 

MOV

SI,4455H

;COPY 4455H IN SI

 

 

 

ADD

AX,SI

;ADD CONTENTS OF AX WITH SI & RESULT SOTRED IN AX

 

 

 

MOV

[3000],AL

COPY CONTENTS OF AL ON MEMORY LOCATION [3000]

 

 

 

INT

03

STOP

 

Result:-

DS   : OFFSET : DATA

0400:  [3000]    : 77H

0400:  [3001]    : 55H

 

3)     Program Title: - WALP to 99H & 88H in AL & BL register respectively, perform the addition & store the result of sum on memory location [2000]. DS = 0200H

Register & Memory Address Used: - AL, BL & [2000]

Data: - 99H, 88H & 0200H

Address

Op-code

Label

Mnemonic

Operand

Comments

 

 

 

MOV

AX,0200

Initialisation of DS

 

 

 

MOV

DS,AX

 

 

 

 

MOV

AL,99H

;COPY 99H IN AL

 

 

 

MOV

BL,88H

;COPY 88H IN BL

 

 

 

ADD

AL,BL

;ADD CONTENTS OF BL WITH AL & RESULT SOTRED IN AL

 

 

 

MOV

[2000],AL

COPY CONTENTS OF AL ON MEMORY LOCATION [2000]

 

 

 

INT

03

STOP

 

Result:-

DS   : OFFSET : DATA

0200:  [2000]    : 21 H

 

2] ADC

                        Syntax –



            This instruction is perform addition of destination & Source plus Carry Flag (CF) and stored result in destination. The source can be 8/16 bit register, memory location or immediate data (number). Destination can be 8/16 bit register, memory location. This instruction affects all 6 conditional flags.

Destination = Destination + Source + CF

 

Example,        ADC AL,04H            ……(AL = AL + 04 + CF)

                        ADC AL,BL              ……(AL = AL + BL + CF)

                        ADC AH,[2000]

                        ADC [4000],AX

4)     Program Title: - WALP to 99H & 88H in AL & BL register respectively, perform the addition & store the 16 bit result of sum on memory location [2000] & [2001]. DS = 0200H

Register & Memory Address Used: - AL, BL, [2000] & [2001]

Data: - 99H, 88H & 0200H

Address

Op-code

Label

Mnemonic

Operand

Comments

 

 

 

MOV

AX,0200

Initialization of DS

 

 

 

MOV

DS,AX

 

 

 

 

MOV

AL,99H

;COPY 99H IN AL

 

 

 

MOV

CL,00H

;COPY 00H IN CL

 

 

 

MOV

BL,88H

;COPY 88H IN BL

 

 

 

ADD

AL,BL

;ADD CONTENTS OF BL WITH AL & RESULT SOTRED IN AL

 

 

 

ADC

CL,00H

;00H ADD WITH CONTENTS OF CL & CARRY FLAG (CF)

 

 

 

MOV

[2000],AL

COPY CONTENTS OF AL ON MEMORY LOCATION [2000]

 

 

 

MOV

[2001],CL

COPY CONTENTS OF CL ON MEMORY LOCATION [2001]

 

 

 

INT

03

STOP

 

Result:-

DS   : OFFSET : DATA

0200:  [2000]    : 21 H

0200:  [2001]    : 01 H

 


3) SUB

     Syntax: - SUB Destination, Source

This instruction subtracts operand from destination operand and stores result in destination operand. The source can be 8/16 bit register, memory location or immediate number. The destination can be 8/16 bit register or memory location. This instruction affects all 6 conditional flags.

For example

                  SUB AL, 04H

                  SUB AL, BL

                  SUB AL, [2000]

                  SUB AX, BX

                  SUB [2000], CL

                  SUB AL, [SI]

 

4)    SBB

Syntax:- SBB Destination, Source

            This instruction subtracts source operand from destination operand and also subtracts carry (borrow) flag from result. The result is stored in destination operand. The source can be 8/16 bit resister memory location or immediate number. The destination can be 8/16 bit resister or memory location. This instruction affects all conditional flags.

 

          For Example 

                            SBB AL,BL


5)      MUL

Syntax :- MUL Source

            This instruction is used to perform multiplication of data stored in al or ax register & source operand. The result of multiplication is stored in AL or AX. The source can be 8/16 bit register or memory location. (for 8/16 bit multiplication one number is in AL/AX & another number is given in source operand.) The multiplication of two 8 bit numbers can be of 16 bits. Therefore the result of multiplication is stored in AX register. Similarly the result of multiplication of two 16 bit numbers can be of 32 bits. Therefore for 16 bit multiplication the result in stored in AX and DX register. The LSW (least significant word) of result is stored in AX register & MSW (Most Significant Word) of result is stored in DX register. This instruction affects only carry flags.

            For example

MUL BL                     I.e. AX=AL*BL

MUL BX                    i.e. DX:AX=AX*BX

MUL [2000]    i.e. AX=AL*[1000]

 6)  DIV 

            Syntax :-  DIV Source

         This instruction is used to perform division of a 16 bit number stored in AX and 8 bit number specified in source operand OR a 32 bit number stored in DX:AX registers and 16 bit number specified in source operand. In 8086 only two division operations i.e. 16/8/ and 32/16 are allowed.

     For 16/8 division the result is stored in AX register. For 32/16 division the result is stored in DX: AX registers. The source can be 8/16 bit register or memory location. This instruction affects all conditional flags. For example

     

                DIV BL       i.e. AX= AL/BL

                DIV BX        i.e. DX: AX = DX: AX/BX

7) CMP

       Syntax :-   CMP Destination, Source

             This instruction is used to compare number in destination operand with number in source operand. The comparison is actually performed by subtracting source operand from destination operand. But the result of comparison is not stored anywhere. The source can be 8/16 bit register, memory location or immediate number. The destination can be 8/16 bit register or memory location. The result of comparison is reflected (shown) in 3 flags i.e. carry flag, sign flag and zero flag. Table below shows status of this 3 flags after compare instruction

 

                                              CF     SF     ZF

Destination =Source            0        0        1

Destination >Source            1        0        0

Destination <Source            1        1        0

 

The examples of this instruction are

CMP AL, 05H

CMP AL, BL

CMP AL, [1000]

CMP AX, BX


 

Post a Comment

0 Comments