8086 Arithmetic Instructions

8086 Arithmetic Instructions:

8086 Arithmetic Instructions are follows

a) Addition Instructions :

  • ADD
  • ADC
  • INC
  • AAA
  • DAA

ADD/ADC Instruction : ADD destination, source / ADC destination, source.

These instructions add a number from source to a number from destination and put the result in the destination. The ADC, instruction also adds the status of carry flag into the result. The source may be an immediate number, a register, or a memory location. The source and the destination in an instruction cannot both be memory locations. The source and destination both must be a word or byte. If you want to add a byte to a word, you must copy the byte to a word location and fill the upper byte of the word with zeroes before adding.

Flags affected : AF, CF, OF, PF, SF, ZF.

INC Instruction : Increment destination.

The INC instruction adds 1 to the specified destination. The destination may be a register or memory location. The AF, OF, PF, SF and ZF flags are affected.

AAA Instruction : ASCII Adjust for Addition.

The numbers from 0-9 are represented as 30H-39H in ASCII code. When you want to add two decimal digits which are represented in ASCII code, it is necessary to mask upper nibble (3) from the code before addition. The 8086 Arithmetic Instructions allows you to add the ASCII codes for two decimal digits without masking off the “3” in the upper nibble of each digit. The AAA instruction can be used after addition to get the current result in unpacked BCD form.

DAA Instruction : Decimal Adjust Accumulator.

This instruction is used to make sure the result of adding two packed BCD numbers is adjusted to be a legal BCD number.

Instruction works as follows :

  1. If the value of the low-order four bits (D3-D0) in the AL is greater than 9 or if AF is set, the instruction adds 6 (06) to the low-order four bits.
  2. If the value of the high-order four bits (D7-D4) in the AL is greater than 9 or if carry flag is set, the instruction adds 6 (60) to the high-order four bits.

b) Subtraction Instructions:

  • SUB
  • SBB
  • DEC
  • NEG
  • CMP
  • AAS
  • DAS

SUB/SBB Instruction :

SUB destination, Source.

SBB destination, Source.

These instructions subtract the number in the source from the number in the desfinafion and put result in the desfinafion. The SBB, instruction also subtracts the status of carry flag from the result. The source may be an immediate number, a register, or a memory location. The destination maybe a register or a memory location. The source and the desfinafion both cannot be memory locafions. The source and destination both mustbeword or byte. If you want to subtract a byte from a word, you must copy the byte to a word location and fill the upper byte of the word with zeroes before subtracting.

Flags affected : AF, CF, OF, PF,SF,andZE.

DEC Instruction : Decrement destination.

The DEC instruction subtract 1 from the specified destination. The destination may be a register or a memory location. The AF, OF, PF, SF and ZF flags are affected.

NEG Instruction : Form 2’s complement.

This, instruction replaces the number in a destination with the 2’s complement of that number. The destination can be a register or a memory location. This instruction can be implemented by inverting each bit and adding 1 to it

The negate instruction updates the AF, CF, SF, PF, ZF and OF flags.

CMP Instruction : CMP destination, source.

This instruction compares a byte/word from the specified source with a byte/word from the specified destination. The source and destination both must be byte or word. The ‘source may be an immediate number, a register, or a memory location. The destination may be a register or a memory location. However the source and destination both can’t be memory locations. The comparison is done by subtracting the source byte or word from the destination byte or word. But the result is not stored in the destination. Source and destination remain unchanged, only flags are updated.

Flags : The AF, OF, SF, ZF, PF and CF are updated by the CMP instruction.

AAS Instruction : ASCII Adjust after subtraction.

The numbers from 0-9 are represented as 30-39 in ASCII code. When you want to subtract two decimal digits which are represented in ASCII code, it is necessary to mask upper nibble (3) from the code before subtraction. The 8086 Arithmetic Instructions allows you to subtract the ASCII codes for two decimal digits without masking off the “3” in the upper nibble of each digit. The AAS instruction can be .used after subtraction to get the current result in unpacked BCD form.

DAS Instruction : Decimal Adjust After Subtraction.

This instruction is used after subtracting two packed BCD numbers to make sure the result is correct packed BCD. Instruction works as follows :

  1. If the value of the low-order four bits (D3-D0) in the AL is greater than 9 o AF is set; the instruction subtracts 6 (06) from the low-order four bits.
  2. If the value of the high-order four bits (D7-D4) in the AL is greater than 9 or if carry flag is set, the instruction subtracts 6 (60) from the high-order four bits.

c) Multiplication Instructions:

  • MUL
  • IMUL
  • AAM

MUL Instruction : MUL source.

This instruction multiplies an unsigned byte from source and unsigned byte in AL register or unsigned word from source and unsigned word in AX register. The source can be a register or a memory location. When the byte is multiplied by the contents of AL, the result is stored in AX. The most significant byte is stored in AH and least significant byte is stored in AL. When a word is multiplied by the contents of AX, the most significant word of result is stored in DX and least significant word of result is stored in AX.

Flags : MUL instruction affect AF, PF, SF, and ZF flags.

IMUL Instruction :

This instruction multiplies a signed byte from some source and a signed byte in AL, or a signed word from some source and a signed word in AX. The source can be register or memory location. When a signed byte is multiplied by AL a signed result will be put in AX. When a signed word is multiplied by AX, the high-order word of the signed result is put in DX and the low-order word of the signed result is put in AX.

If the upper byte of a 16-bit result or the upper word of 32-bit result contains only copies of the sign bit (all 0’s or all 1’s), then the CF and the OF flags will both be 0’s. The AF, PF, SF, and ZF flags are undefined after IMUL.

To multiply a signed byte by a signed word it is necessary to move the byte into a word location and fill the upper byte of the word with copies of the sign bit. This can be done using CBW instruction.

AAM Instruction : BCD Adjust After Multiply.

After the two unpacked BCD digits are multiplied, the AAM instruction is used to adjust the product to two unpacked BCD digits in AX.

d) Division Instructions:

  • DIV
  • IDIV
  • AAD

DIV Instruction : DIV source

This instruction is used to divide an unsigned word by a byte or to divide an unsigned double word by a word.

When dividing a word by a byte, the word must be in AX register. After the division AL will contain an 8-bit quotient and AH will contain an 8-bit remainder. If an attempt is made to divide by 0 or the quotient is too large to fit in AL (greater than FFH), the 8086 Arithmetic Instructions will automatically execute a type 0 interrupt.

When a double word is divided by a word, the most significant word of the double word must be in DX and the least-significant word must be in AX. After the division AX will contain a 16-bit quotient and DX will contain a 16-bit remainder. Again, if an attempt is made to divide by 0 or the quotient is too large to fit in AX register (greater than FFFFH), the 8086 Arithmetic Instructions will do a type 0 interrupt. For DIV instruction source may be a register or memory location.

To divide a byte by a byte, it is necessary to put the dividend byte in AL and fill AH with all 0’s. Similarly, to divide a word by a word, it is necessary to put the dividend word in AX and fill DX with all 0’s.

Flags : All flags are undefined after a DIV instruction.

IDIV Instruction : IDIV source.

This instruction is used to divide a signed word by a signed byte, or to divide a signed double word (32-bits) by a signed word. Rest all is similar to DIV instruction.

AAD Instruction : Binary Adjust before division.

AAD converts two unpacked BCD digits in AH and AL to the equivalent binary number in AL. This adjustment must be made before dividing the two unpacked BCD digits in AX by an unpacked BCD byte. After the division AL will contain the unpacked BCD quotient and AH will contain the unpacked BCD remainder. The PF, SF and ZF are updated. The AF, CF and OF are undefined after AAD.

e) Sign Extension Instructions :

  • CBW
  • CWD

CBW Instruction :

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.

CWD Instruction : CBW affects no flag.

This instruction copies the sign bit of a word in AX to all the bits of the DX register. DX is then said to be sign extension of AX.

CWD affects no flag.

MORE RELATED ARTICLE

Leave a Reply

Your email address will not be published. Required fields are marked *

COPYRIGHT © 2014 TO 2018 EEEGUIDE.COM ALL RIGHTS RESERVED | HOME | SITEMAP | CONTACT US | ABOUT US | PRIVACY POLICY | Frontier Theme