96
7/23/2019 Microprocessor 8086 MPA2 http://slidepdf.com/reader/full/microprocessor-8086-mpa2 1/96 Assembler & Microprocessor Emulator 1 8 86 Microprocessor 1. Assembler 2. Emulator An Assembler program is used to translate the assembly language mnemonics for instructions to the corresponding binary codes. On the first pass through the source program, the assembler determines the displacement of named data items, the offset of labels, etc. and puts this information in a symbol table. On the second pass through the source program, the assembler produces the binary code for each instruction and inserts the offsets, etc., that it calculated during the first pass. One such assembler is EMU8086- Assembler & Microprocessor Emulator 4.08 Dheeraj Suri

Microprocessor 8086 MPA2

  • Upload
    parvesh

  • View
    339

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 1/96

Assembler & Microprocessor Emulator

1

8 86 Microprocessor

1. Assembler

2. Emulator

• An Assembler program is used totranslate the assembly language

mnemonics for instructions to thecorresponding binary codes.

• On the first pass through the sourceprogram, the assembler determines thedisplacement of named data items, theoffset of labels, etc. and puts this

information in a symbol table.• On the second pass through the source

program, the assembler produces thebinary code for each instruction andinserts the offsets, etc., that itcalculated during the first pass.

• One such assembler is

EMU8086- Assembler & MicroprocessorEmulator 4.08

Dheeraj Suri

Page 2: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 2/96

Assembler & Microprocessor Emulator

2

8 86 Microprocessor

1. Assembler

2. Emulator

• Another way to run your program isthrough Emulator, such as EMU8086. An

Emulator is a mixture of hardware andSoftware.

• Hardware of Emulator is a multiwirecable which connects the host system tothe system being developed. A plug atthe end of the cable is plugged into the

prototype system in place of itsmicroprocessor. Through thisconnection the software of emulatorallows you to download your objectcode program into RAM in the systembeing tested and run it.

• Emulator allows you to run programs,

examine and change the contents ofregisters, examine and change thecontents of memory locations, andinsert breakpoints in the system.

EMU8086- Assembler & MicroprocessorEmulator 4.08

Dheeraj Suri

Page 3: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 3/96

Instruction Descriptions

3

8 86 Microprocessor

AAA –

ASCIIAdjust forAddition

Numerical data coming into computer froma terminal is usually in ASCII code.

In this code, the numbers 0 to 9 arerepresented by ASCII codes 30h to 39h.

The 8086 allows you to add the ASCII codes

for two decimal digits without masking offthe “3” in the upper nibble of each.After the addition, the AAA instruction isused to make sure the result is correctunpacked BCD.

Dheeraj Suri

ASCII stands for American Standard Code for Information Interchange.Computers can only understand numbers, so an ASCII code is the numerical

representation of a character such as 'a' or '@' or an action of some sort.

Page 4: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 4/96

Instruction Descriptions

4

8 86 Microprocessor

AAA –

ASCIIAdjust forAddition

Example:

Dheeraj Suri

The AAA instruction works only on AL Register. Flags Affected: AF, CF.

; Assume AL = 0011 0101, ASCII5

; BL = 0011 1001, ASCII 9

 ADD AL,BL ; Result: AL = 0110 1110 = 6Eh,which is incorrect BCD

 AAA ; Now AL = 00000100, unpackedBCD 4.CF = 1 indicates answer is14 decimal.

OR AL,30h ; Now AL = 0011 0100 = 34h,

The ASCII Code for 4

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

AF CF

Page 5: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 5/96

Flash Back – what is BCD ?

5

8 86 Microprocessor

BCD –

BinaryCodedDecimal

Binary-coded decimal (BCD) is a class ofbinary encodings of decimal numbers where

each decimal digit is represented by a fixednumber of bits, usually four or eight.

As most computers deal with data in 8-bit bytes,it is possible to use one of the following methodsto encode a BCD number:

Unpacked: each numeral is encoded into onebyte, with four bits representing the numeraland the remaining bits having no significance.

Packed: two numerals are encoded into a single

byte, with one numeral in the least significantnibble (bits 0 through 3) and the other numeralin the most significant nibble (bits 4 through 7).

Dheeraj Suri

Page 6: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 6/96

Flash Back – what is BCD ?

6

8 86 Microprocessor

BCD –

BinaryCodedDecimal

Example: encoding the decimal number 91D

Using unpacked BCD

Using packed BCD, the same number would fit

into a single byte.

Dheeraj Suri

Decimal 9 1

Binary 0000 1001 0000 0001

Decimal 9 1

Binary 1001 0001

Page 7: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 7/96

Instruction Descriptions

7

8 86 Microprocessor

AAD –

BCD-to-BinaryConvertbefore

Division

AAD converts two unpacked BCD digits inAH and AL to the equivalent binary number

in AL. The adjustment must be made beforedividing the two unpacked BCD digits in AXby an unpacked BCD byte. After thedivision, AL will contain the unpacked BCDquotient and AH will contain the unpacked

BCD remainder.Note: If an attempt is made to divide by 0,the 8086 will do a type 0 interrupt.

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

SF ZF PF

Page 8: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 8/96

Instruction Descriptions

8

8 86 Microprocessor

AAD –

BCD-to-BinaryConvertbefore

Division

Example:

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

SF ZF PF

;AX = 0607h unpacked BCD for 67

; decimal CH = 09h , now adjust to; binary

 AAD ; Result: AX = 0043 = 43h = 67 D

DIV CH  ; Divide AX by unpacked BCD in CH

; Quotient : AL = 07 unpacked BCD

;Remainder: AH = 04 unpacked BCD

; Flags undefined after DIV

Page 9: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 9/96

Instruction Descriptions

9

8 86 Microprocessor

AAM –

BCDAdjustafterMultiply

Before you can multiply two ASCII digits,you must first mask the upper 4 bits of

each. This leaves unpacked BCD (one BCDdigit per byte) in each byte. After twounpacked BCD digits are multiplied, theAAM instruction is used to adjust theproduct of two unpacked BCD digits in AX.

AAM instruction works only after themultiplication of two un-packed BCD bytes,and it works only on an operand in AL.

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated. But AF, CF, and OF are left undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

SF ZF PF

Page 10: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 10/96

Instruction Descriptions

10

8 86 Microprocessor

AAM –

BCDAdjustafterMultiply

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated. But AF, CF, and OF are left undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

SF ZF PF

; AL = 00000101 = unpacked BCD 5

; BH = 00001001 = unpacked BCD 9

MUL BH ; AL X BH ; result in AX; AX = 00000000 00101101 = 002D h

AAM ; AX = 00000100 00000101 = 0405 h

; which is an unpacked BCD for 45.

; if ASCII codes for the result aredesired,; the next instruction ought to be used.

OR AX,3030H

; Put 3 in upper nibble of each byte.

; AX = 00110100 00110101 = 3435 h

; which is ASCII code for 45.

Page 11: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 11/96

Instruction Descriptions

11

8 86 Microprocessor

AAS –

ASCIIAdjust forSubtraction

Numerical data coming into a computerfrom a terminal is usually in ASCII code. In

this code the numbers 0 to 9 arerepresented by the ASCII codes 30H to 39H.The 8086 allows you to subtract the ASCIIcodes for two decimal digits withoutmasking the “3” in the upper nibble of each.

The AAS instruction is then used to makesure the result is the correct unpacked BCD.

Dheeraj Suri

Flags affected : AF and CF are updated, but OF, PF, SF and ZF are left undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

AF CF

Page 12: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 12/96

Instruction Descriptions

12

8 86 Microprocessor

AAS –

ASCIIAdjust forSubtraction

Dheeraj Suri

Flags affected : AF and CF are updated, but OF, PF, SF and ZF are left undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

AF CF

; ASCII 9 – ASCII 5 (9 – 5)

; AL = 00111001 = 39 H = ASCII 9

; BL = 00110101 = 35 H = ASCII 5

SUBAL,BL

; Result: AL = 00000100 = BCD 04,CF = 0

AAS ; Result; AL = 00000100 = BCD 04

; and CF = 0; no borrow required

; ASCII 5 – ASCII 9 (5 – 9)

; Assume AL = 00110101 = 35h =

; ASCII 5 and BL = 00111001 = 39h= ASCII 9

Page 13: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 13/96

Instruction Descriptions

13

8 86 Microprocessor

AAS –

ASCIIAdjust forSubtraction

Dheeraj Suri

Flags affected : AF and CF are updated, but OF, PF, SF and ZF are left undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

AF CF

SUB AL, BL ; Result: AL = 11111100 = -4

; in 2’s complement and CF = 1

AAS ; Result: AL = 00000100 =BCD04

; and CF = 1; borrow needed

The AAS instruction leaves the correctunpacked BCD result in the low nibble of AL

and resets the upper nibble of AL to all 0’s. Ifone wants to send the result back to a CRTterminal, one can OR AL with 30H to producethe correct ASCII code for the result. TheAAS instruction works only on the ALregister.

Page 14: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 14/96

Instruction Descriptions

14

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

These instructions add a number from somesource to a number from some destination

and put the result in specified destination.The Add with Carry instruction, ADC, alsoadds the status of the carry flag into theresult. The source may be an immediatenumber, a register, or a memory location

specified by any one of the 24 addressingmodes. The destination may be a register ora memory location specified by any one ofthe 24 addressing modes. The source andthe destination in an instruction cannotboth be memory locations and they must be

of same type.

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

Page 15: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 15/96

Instruction Descriptions

15

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

If one wants to add a byte to a word, onemust copy the byte to a word location and

fill the upper byte of the word with 0’sbefore adding.Examples(CODING):

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

ADD AL, 74H ; Add immediate number 74H; to contents of AL. Result in; AL

ADC CL, BL ; Add contents of BL pluscarry; status to contents of CL

ADD DX, BX ; Add contents of BX tocontents; of DX

Page 16: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 16/96

Instruction Descriptions

16

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

Examples(CODING)(continued):

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

ADD DX, [SI] ; Add word from memory at

offset [SI] in DS to contentsof DX

ADC AL,PRICES[BX]

;ADD byte from effectiveaddress ;PRICES[BX] pluscarry status to ;contents of

ALADDPRICES[BX],AL

;Add contents of AL tocontents; of memory location ateffective; address PRICES[BX]

Page 17: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 17/96

Instruction Descriptions

17

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

Examples(NUMERICAL):

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

; Addition of unsigned

; numbers CL = 01110011 =; 115D + BL=01001111 =; 79D Result in CL

ADD CL, BL ; CL = 11000010 = 194D

; Addition of signed numbers

; CL = 01110011 = + 115 D

; +BL = 01001111 = + 79D

; Result in CL

ADD CL, BL ; CL = 11000010 = -62D –

incorrect because the resultis too large to fit in 7 bits.

Page 18: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 18/96

Instruction Descriptions

18

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

Flag results for signed addition, Example:

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

CF = 0 No Carry out of bit 7.

PF = 0 Result has odd parity.AF = 1 Carry was produced out of bit 3.

ZF = 0 Result in destination was not 0.

SF = 1 Copies most significant bit of result;indicates negative result if you are

adding signed numbers

OF = 1 Set to indicate that the result ofaddition was too large to fit in thelower 7 bits of the destination used torepresent the magnitude of a signed

number. In other words, the resultwas greater than +127D, so the resultoverflowed into the sign bit positionand -

Page 19: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 19/96

Instruction Descriptions

19

8 86 Microprocessor

ADC –

Add withCarry;ADD –Add

Flag results for signed addition, Example:

Dheeraj Suri

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

OF = 1 Incorrectly indicated that the result

was negative. If you are adding twosigned 16-bit values, the OF will beset if the magnitude of the result istoo large to fit in the lower 15 bits ofthe destination.

NOTE: PF is meaningful only for an 8-bit result. AF is set only by a carry out of bit 3. Therefore,the DAA instruction cannot be used after wordadditions to convert the result to correct BCD.

Page 20: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 20/96

Instruction Descriptions

20

8 86 Microprocessor

AND –

ANDcorresponding Bitsof Two

operands- ANDDestination,

Source

This instruction ANDs each bit in a sourcebyte or word with the same number bit in a

destination byte or word. The result is putin the specified destination. The contents ofthe specified source will not be changed.The result for each bit position will followthe truth table for a two-input AND gate. In

other words, a bit in the specifieddestination will be a 1 only if that bit is a 1in both the source and the destinationoperands. Therefore, a bit can bemasked(reset) by ANDing it with 0.

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated by AND. But CF and OF are both 0. AF isundefined.15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 SF ZF PF 0

Page 21: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 21/96

Instruction Descriptions

21

8 86 Microprocessor

AND –

ANDcorresponding Bitsof Two

operands- ANDDestination,

Source

The source operand can be an immediatenumber, the contents of a register, or the

contents of a memory location specified byone of the 24 addressing modes. Thedestination can be a register or a memorylocation. The source and the destinationcannot both be memory locations in thesame instruction. CF and OF are both 0 afterAND. PF, SF, and ZF are updated by AND. AFis undefined. Note that PF has meaning onlyfor an 8-bit operand.

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated by AND. But CF and OF are both 0. AF isundefined.15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 SF ZF PF 0

Page 22: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 22/96

Instruction Descriptions

22

8 86 Microprocessor

AND –

ANDcorresponding Bitsof Two

operands- ANDDestination,

Source

EXAMPLES(CODING):

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated by AND. But CF and OF are both 0. AF isundefined.15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 SF ZF PF 0

; AND word in DS at offset[SI]

; with word in CX register

ANDCX,[SI]

; Result in CX Register

AND BH, CL ; AND byte in CL with byte in BH

; Result in BH

; AND words in BX withimmediate

AND BX,00FFH

; 00FFH. Masks upper byte,leaves lower byte unchanged.

Page 23: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 23/96

Instruction Descriptions

23

8 86 Microprocessor

AND –

ANDcorresponding Bitsof Two

operands- ANDDestination,

Source

EXAMPLES(NUMERICAL):

Dheeraj Suri

Flags affected : PF, SF, and ZF are updated by AND. But CF and OF are both 0. AF isundefined.15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 SF ZF PF 0

; BX = 10110011 01011110

AND BX,00FFH

; Mask out upper 8 bits of BX

; Result: BX = 0000000001011110

; CF, OF, PF, SF, ZF = 0

Page 24: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 24/96

Instruction Descriptions

24

8 86 Microprocessor

CALL –

Call aprocedure

.

The CALL instruction is used to transferexecution to a sub-program or procedure.

There are two basic types of calls, near andfar . A near call is a call to a procedurewhich is in the same code segment as theCALL instruction. When the 8086 executes anear CALL instruction, it decrements thestack pointer by 2 and copies the offset ofthe next instruction after the CALL onto thestack. This offset saved on the stack isreferred to as return address, because thisis the address that execution will return toafter the procedure executes. A near CALL

instruction will also load the instructionpointer with the offset of the firstinstruction in the procedure. A RETinstruction at the end of the procedure -

Dheeraj Suri

Page 25: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 25/96

CALL – Call a procedure

25

8 86 Microprocessor

-- Will return execution of the instruction after the call bycopying the offset saved on the stack back to IP.

A far call is a call to a procedure which is in differentsegment from the one that contains the CALL instruction.When the 8086 executes a far call, it decrements thestack pointer by 2 and copies the contents of the CSregister to the stack. It then decrements the stack pointerby 2 again and copies the offset of the instruction afterthe CALL instruction to the stack. Finally it loads CS withthe segment base of the segment which contains theprocedure, and loads IP with the offset of the firstinstruction of the procedure in that segment. A RETinstruction at the end of the procedure will return

execution to the next instruction after the CALL byresorting the saved values of CS and IP from the stack.

Dheeraj Suri

Page 26: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 26/96

CALL – Call a procedure

26

8 86 Microprocessor

Examples:

Dheeraj Suri

CALL MULTO ; A direct within-segment (near or intra-

;segment) call. MULTO is the name of the;procedure. The assembler determines the;displacement of MULTO from the instruction;after the CALL and codes this displacement in;as part of the instruction.

Call BX ; An indirect within-segment near or intra-

segment

; call. BX contains the offset of the firstinstruction; of the procedure. Replaces the contents of IPwith contents of register BX.

CALL WORDPTR (BX)

; An indirect within-segment near or Intra-;segment call. Offset of first instruction of;procedure is in two memory addresses in DS.;Replaces contents IP with contents of word;memory location in DS pointed to by BX.

Page 27: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 27/96

CALL – Call a procedure

27

8 86 Microprocessor

Examples(continued):

Dheeraj Suri

CALL SMART-

DIVIDE

;A direct call to another segment – far or

;intersegment call. SMART-DIVIDE is the name;of the procedure. The procedure must be;declared far with SMART_DIVIDE PROC FAR;at its start. The Assembler will determine the;code segment base for the segment which;contains the procedure and the offset of the

;start of the procedure. It will put these values;in as part of the instruction code.

CALLDWORDPTR[BX]

; An indirect call to another segment – far or;intersegment call. New Values for CS and IP;are fetched from four memory locations in DS.;The new value for CS is fetched from [BX] and;[BX+1]; the new IP is fetched from [BX+2];and [BX+3].

Page 28: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 28/96

Instruction Descriptions

28

8 86 Microprocessor

CBW-

ConvertSignedByte toSigned

Word

This instruction copies the sign of a byte inAL to all the bits in AH. AH is then said to be

the sign extension of AL. The CBW operationmust be done before a signed byte in AL canbe divided by another signed byte with theIDIV instruction. CBW affects no flags

Dheeraj Suri

Flags affected : No Flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Page 29: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 29/96

Instruction Descriptions

29

8 86 Microprocessor

CBW-

ConvertSignedByte toSigned

Word

Example:

More examples are illustrated in the IDIVinstruction in the future slides.

Dheeraj Suri

Flags affected : No Flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

;AX = 00000000 10011011 = -155 D

CBW ;Convert signed byte in AL to signed; word in AX

;Result: AX = 11111111 10011011 =; -155 D

Page 30: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 30/96

Instruction Descriptions

30

8 86 Microprocessor

CLC –

Clear theCarryFlag (CF)

This instruction resets the carry flag to 0.No other flags are affected.

Example:

CLC

Dheeraj Suri

Flags affected : CF. No other Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CF

8 86 Microprocessor

Page 31: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 31/96

Instruction Descriptions

31

CLD –

ClearDirectionFlag

This instruction resets the direction flag to0. No other flags are affected. If the

direction flag is reset, SI and DI willautomatically be incremented when one ofthe string instructions, such as MOVS,CMPS, or SCAS, executes.Example:

Dheeraj Suri

Flags affected : DF. No other Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DF

CLD ;Clear direction flag so that string; pointers auto-increment after; each string operation

8 86 Microprocessor

Page 32: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 32/96

Instruction Descriptions

32

CLI –

ClearInterruptFlag

This instruction resets the interrupt flag to0. No other flags are affected. If the

interrupt flag is reset, the 8086 will notrespond to an interrupt signal on its INTRinput. The CLI instruction, however, has noeffect on the non-maskable interrupt input,NMI.

Dheeraj Suri

Flags affected : IF. No other Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF

i i i8 86 Microprocessor

Page 33: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 33/96

Instruction Descriptions

33

CMC –

Complement theCarryFlag

If the Carry flag (CF) is a 0 before thisinstruction, it will be set to a 1 after the

instruction. If the carry flag is 1 before thisinstruction, it will be reset to 0 after theinstruction executes. Obviously CMC affectsonly the Carry Flag.Example:

CMC  ; Invert the carry flag.

Dheeraj Suri

Flags affected : CF. No other Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CF

I i D i i8 86 Microprocessor

Page 34: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 34/96

Instruction Descriptions

34

CMP –

CompareByte orWord –CMP

Destination,Source

Compares a byte/word from the specified sourcewith a byte/word from the specified destination.The source can be a an immediate number, aregister, or a memory location. The destinationcan be a register or a memory location. Thesource and destination cannot both be memorylocations in the same instruction. Thecomparison is actually done by subtracting the

source byte or word from the destination byte orword. The source and the destination are notchanged, but the flags are set to indicate theresults of comparison. AF, OF,SF, ZF, PF, and CFare updated by the CMP instruction.

Dheeraj Suri

Flags affected : AF, OF, SF, ZF, PF and CF are updated. Rest flags are unaffected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

I t ti D i ti8 86 Microprocessor

Page 35: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 35/96

Instruction Descriptions

35

CMP –

CompareByte orWord –CMP

Destination,Source

For the instruction CMP CX, BX ; CF, ZF, and SFwill be left as follows:

Dheeraj Suri

Flags affected : AF, OF, SF, ZF, PF and CF are updated. Rest flags are unaffected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

CF ZF SFCX =BX

0 1 0 ; Result ofsubtraction; is 0

CX >

BX

0 0 0 ;No borrow required,

so; CF = 0

CX <BX

1 0 1 ; Subtraction; required; borrow, so CF = 1

I t ti D i ti8 86 Microprocessor

Page 36: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 36/96

Instruction Descriptions

36

CMP –

CompareByte orWord –CMP

Destination,Source

Example:

Dheeraj Suri

Flags affected : AF, OF, SF, ZF, PF and CF are updated. Rest flags are unaffected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

CMP

AL,01H

; Compare immediate number

; 01H with byte in ALCMP BH,CL

; Compare byte in CL with bytein; BH

CMP CX,

TEMP_MIN

; Compare word in DS at

; displacement TEMP_MIN withword; in CX

CMPTEMP_MAX, CX

;Compare CS with word in DS at; displacement TEMP_MAX

I t ti D i ti8 86 Microprocessor

Page 37: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 37/96

Instruction Descriptions

37

CMP –

CompareByte orWord –CMP

Destination,Source

Example:

Note: The Compare instructions are often usedwith the conditional Jump instruction. ForExample:

Dheeraj Suri

Flags affected : AF, OF, SF, ZF, PF and CF are updated. Rest flags are unaffected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

CMP

PRICES[BX],49H

; Compare immediate 49H

; with byte at offset [BX] in; array PRICES

CMP BX, CX

JAE TARGET ; Jump to target if BX is aboveor; equal to CX

I t ti D i ti8 86 Microprocessor

Page 38: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 38/96

Instruction Descriptions

38

CMPS/CM

PSB/CMPSW –CompareString

Bytes orStringWords

The CMPS instruction can be used tocompare a byte/word in one string with a

byte/word in another string. SI is used tohold the offset of a byte or word in thesource string, and DI is used to hold theoffset of a byte or word in the other string.The comparison is done by subtracting thebyte or word pointed to by DI from the byteor word pointed to by SI. The AF, CF, OF, PF,SF and ZF flags are affected by thecomparison, but neither operand is affected.

---- contd.

Dheeraj Suri

Flags affected : AF,CF,OF,PF,SF and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

Inst ction Desc iptions8 86 Microprocessor

Page 39: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 39/96

Instruction Descriptions

39

CMPS/CM

PSB/CMPSW –CompareString

Bytes orStringWords

After the comparison, SI and DI willautomatically be incremented or decremented topoint to the next elements in the two strings. Ifthe direction flag has previously been set to a 1with an STD instruction, then SI and DI willautomatically be decremented by 1 for a bytestring or by 2 for word string. If the directionflag has been previously set to 0 with a CLDinstruction, SI and DI will automatically beincremented after the compare. They will beincremented by 1 for byte strings and by 2 for

word strings. The string pointed to by DI must

be in the extra segment, the string pointed to bySI must be in the data segment.

Dheeraj Suri

Flags affected : AF,CF,OF,PF,SF and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

Instruction Descriptions8 86 Microprocessor

Page 40: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 40/96

Instruction Descriptions

40

CMPS/CM

PSB/CMPSW –CompareString

Bytes orStringWords

The CMPS instruction can be used with a REPE,or REPNE prefix to compare all the elements of astring. Example:

Dheeraj Suri

Flags affected : AF,CF,OF,PF,SF and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

MOV SI, OFFSETFIRST_STRING

; Point SI at the; source string

MOV DI, OFFSETSECOND_STRING

; Point DI at destination; string

CLD ; DF cleared, so SI & DI; would auto increment; after compare

MOV CX,100 ; Put number of string; elements in CX

REPE CMPSB ; Repeat the comparison of

; string bytes until end of; string or until compared; bytes are not equal

Instruction Descriptions8 86 Microprocessor

Page 41: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 41/96

Instruction Descriptions

41

CMPS/CM

PSB/CMPSW –CompareString

Bytes orStringWords

-- NOTE:CX functions as a counter which the REPE prefixwill cause to be decremented after eachcompare. The B attached to the CMPS tells theassembler that the strings are of type byte. Ifyou want to tell the assembler that strings are oftype word, write the instruction as CMPSW. TheREPE CMPSW instruction will cause the pointersin SI and DI to be incremented by 2 after eachcompare if the direction flag is cleared ordecremented by 2 if the direction flag is set.

Dheeraj Suri

Flags affected : AF,CF,OF,PF,SF and ZF are updated.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF CF

Instruction Descriptions8 86 Microprocessor

Page 42: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 42/96

Instruction Descriptions

42

CWD –

ConvertSignedWord tosigned

doubleword

CWD copies the sign bit of a word in AX toall the bits of the DX register. In other

words, it extends the sign of AX into all ofDX. The CWD operation must be donebefore a signed word in AX can be dividedby another signed word with the IDIVinstruction. CWD affects no flags.Example: --- contd.

Dheeraj Suri

Flags affected : No Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 43: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 43/96

Instruction Descriptions

43

CWD –

ConvertSignedWord tosigned

doubleword

Example:

Dheeraj Suri

Flags affected : No Flags are Affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

; DX = 00000000 00000000

; AX= 11110000 11000111; = -3897 decimal

CWD ; Convert signed word in AX to; signed double word in DX:AX

; Result: DX = 11111111

11111111; AX = 11110000 11000111; = -3897 decimal

Instruction Descriptions8 86 Microprocessor

Page 44: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 44/96

Instruction Descriptions

44

DAA –

DecimalAdjust ALafter BCDAddition

This instruction is used to make sure theresult of adding two packed BCD numbers is

adjusted to be a legal BCD number. Theresult of addition must be in AL for DAA towork correctly. If the lower nibble in ALafter addition is greater than 9 or AF wasset by the addition, then the DAAinstruction will add 6 to the lower nibble inAL. If the result in the upper nibble is nowgreater than 9 or if the carry flag was set bythe addition or correction, then the DAAinstruction will add 60H to AL

Dheeraj Suri

Flags affected : DAA instruction updates AF, CF, PF, and ZF. OF is undefined afterthe DAA instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX ZF AF PF CF

Instruction Descriptions8 86 Microprocessor

Page 45: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 45/96

Instruction Descriptions

45

DAA –

DecimalAdjust ALafter BCDAddition

Examples:

Dheeraj Suri

Flags affected : DAA instruction updates AF, CF, PF, and ZF. OF is undefined afterthe DAA instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX ZF AF PF CF

; AL = 0101 1001 = 59 BCD

; BL = 0011 0101 = 35 BCD

ADD AL,BL ;AL = 1000 1110 = 8EH

DAA ; Add 0110 because 1110 > 9

;AL = 1001 0100 = 94 BCD

;AL= 1000 1000 = 88 BCD;BL = 0100 1001 =49 BCD

ADD AL,BL ;AL = 1101 0001, AF = 1

DAA ;Add 0110 because AF = 1

;AL = 1101 0111 = D7h

Instruction Descriptions8 86 Microprocessor

Page 46: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 46/96

Instruction Descriptions

46

DAA –

DecimalAdjust ALafter BCDAddition

Examples: (continued).

A decimal up-counter can be implementusing the DAA instruction, the code shownin next slide.

Dheeraj Suri

Flags affected : DAA instruction updates AF, CF, PF, and ZF. OF is undefined afterthe DAA instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX ZF AF PF CF

; 1101 > 9 so add 0110 0000

; AL = 0011 0111 = 37 BCD, CF = 1

Instruction Descriptions8 86 Microprocessor

Page 47: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 47/96

Instruction Descriptions

47

DAA –

DecimalAdjust ALafter BCDAddition

Examples: (continued).

Dheeraj Suri

Flags affected : DAA instruction updates AF, CF, PF, and ZF. OF is undefined afterthe DAA instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX ZF AF PF CF

MOV

COUNT,00h

;Initialize count in memory

; location to 0; Other instruction here

MOV AL,COUNT

;Bring count into AL to work on

ADD AL,01h ; Can also count up by 2, by 3. or; by some other number using the; ADD instruction

DAA ;Decimal adjust the result

MOVCOUNT,AL

;Put decimal result back in; memory

Instruction Descriptions8 86 Microprocessor

Page 48: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 48/96

Instruction Descriptions

48

DAS –

DecimalAdjustafter BCDSubtracti

on

This instruction is used after subtractingtwo packed BCD numbers to make sure the

result is correct packed BCD. The result ofsubtraction must be in AL for DAS to workcorrectly. If the lower nibble in AL aftersubtraction is greater than 9 or the AF wasset by the subtraction, then DAS wouldsubtract 6 from the lower nibble of AL.If the result in the upper nibble is nowgreater than 9 or if the carry flag was set,the DAS instruction will subtract 60 fromAL. Examples in the next slide.

Dheeraj Suri

Flags affected : DAS instruction updates AF, CF, SF, PF, and ZF. OF is undefinedafter the DAS instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX SF ZF AF PF CF

Instruction Descriptions8 86 Microprocessor

Page 49: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 49/96

Instruction Descriptions

49

DAS –

DecimalAdjustafter BCDSubtracti

on

Examples:

Dheeraj Suri

Flags affected : DAS instruction updates AF, CF, SF, PF, and ZF. OF is undefinedafter the DAS instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX SF ZF AF PF CF

;AL = 1000 0110 = 86 BCD

;BH = 0101 0111 = 57 BCD

SUB AL, BH ; AL = 0010 1111 = 2Fh , CF = 0

DAS ; Lower nibble of the result is 1111

; so DAS automatically subtracts; 0000 0110 to give AL = 00101001

; = 29BCD

; AL = 0100 1001 = 49 BCD

; BH = 0111 0010 = 72 BCD

SUB AL,BH ; AL = 11010111 = D7h, CF = 1

Instruction Descriptions8 86 Microprocessor

Page 50: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 50/96

Instruction Descriptions

50

DAS –

DecimalAdjustafter BCDSubtracti

on

Examples:

A decimal down counter can be implementedusing a DAS instruction, as shown in the nextslide.

Dheeraj Suri

Flags affected : DAS instruction updates AF, CF, SF, PF, and ZF. OF is undefinedafter the DAS instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX SF ZF AF PF CF

DAS ; Subtracts 0110 0000 (-60h)

; because 1101 in the upper nibble; > 9

; AL = 0111 0111 = 77 BCD , CF = 1

; CF = 1 means borrow was needed

Instruction Descriptions8 86 Microprocessor

Page 51: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 51/96

Instruction Descriptions

51

DAS –

DecimalAdjustafter BCDSubtracti

on

Examples:

Dheeraj Suri

Flags affected : DAS instruction updates AF, CF, SF, PF, and ZF. OF is undefinedafter the DAS instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX SF ZF AF PF CF

MOV AL,COUNT

; Bring count into AL to work on

SUB AL, 01h ;Decrement. Can also count down

;by 2,3 etc., using SUB instruction

DAS ;Keep results in BCD format

MOV COUNT,

AL

; Put new count back in memory

Instruction Descriptions8 86 Microprocessor

Page 52: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 52/96

Instruction Descriptions

52

DEC –DecrementDestinationRegister orMemory –DEC

Destination

This instruction subtracts 1 from thedestination word or byte. The destinationcan be a register or a memory location

specified by any one of the 24 memoryaddressing modes. This instruction does notaffect the CF. That means if an 8-bitdestination containing 00h or a 16-bitdestination containing 0000h is

decremented, the result will be FFh orFFFFh with no carry (borrow).

Dheeraj Suri

Flags affected : AF, OF, PF, SF, and ZF are updated, but CF is not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF

Instruction Descriptions8 86 Microprocessor

Page 53: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 53/96

Instruction Descriptions

53

DEC –DecrementDestinationRegister orMemory –DEC

Destination

Examples:

Dheeraj Suri

Flags affected : AF, OF, PF, SF, and ZF are updated, but CF is not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF

DEC CL ; Subtract 1 from contents of; CL register

DEC BP ; Subtract 1 from contents of BP; register

DEC BYTEPTR[BX]

; Subtract 1 from byte at offset[BX] in DS. The BYTE PTR directiveis necessary to tell the; assembler to put in the correct

; code for decrementing a byte in; memory, rather than; decrementing a word. The; instruction essentially says,; “Decrement the byte in memory; pointed to by the offset in BX”

Instruction Descriptions8 86 Microprocessor

Page 54: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 54/96

p

54

DEC –DecrementDestinationRegister orMemory –DEC

Destination

Examples(continued):

Dheeraj Suri

Flags affected : AF, OF, PF, SF, and ZF are updated, but CF is not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF SF ZF AF PF

DEC WORDPTR[BP]

;Subtract 1 from a word at offset; [BP] in SS. The WORD PTR

; directive tells the assembler to; put in the code for decrementing; a word pointed to by the; contents of BP. An offset in BP; will be added to the SS register; contents to produce the physical; address

DECTOMATO_CAN _COUNT

;Subtract 1 from byte or word; named TOMATO_CAN_COUNT inDS.

Instruction Descriptions8 86 Microprocessor

Page 55: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 55/96

Instruction Descriptions

55

DIV –UnsignedDivide –DIV source

This instruction is used to divide an unsigned word bya byte or to divide an unsigned doubleword (32 bits)by a word.When a word is divided by a byte, the word must be inthe AX register. The divisor can be a register or in amemory location. After the division, AL will contain an8-bit result (quotient), and AH will contain a 8-bitremainder.When a double-word is divided by a word, theMSW(Most significant Word) of the doubleword must

be in DX, and the LSW of the doubleword must be inAX. After the result, AX will contain the 16-bitresult(quotient), and DX will contain 16-bit remainder.If one wants to divide a byte by a byte, one must firstput the dividend byte in AL and fill AH with all 0’s. TheSUB AH,AH instruction is a quick way to do this.

Dheeraj Suri

Flags affected : The CF, OF, SF, ZF, AF, and PF flags are undefined.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

Instruction Descriptions8 86 Microprocessor

Page 56: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 56/96

p

56

DIV –UnsignedDivide –DIV source

Examples(syntax):

Dheeraj Suri

Flags affected : The CF, OF, SF, ZF, AF, and PF flags are undefined

DIV BL ;Divide word in AX by byte in BL.;Quotient in AL, remainder in AH

DIV CX ;Divide doubleword in DX and AX; by word in CX. Quotient in AX,Remainder in DX.

DIVSCALE[BX]

;AX/(byte at effective addressSCALE[BX] if SCALE[BX] is of type

byte or (DX and AX)/(word ateffective address SCALE[BX]) ifSCALE[BX] is of type word.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

Instruction Descriptions8 86 Microprocessor

Page 57: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 57/96

p

57

DIV –UnsignedDivide –DIV source

Examples(Numerical):

Dheeraj Suri

Flags affected : The CF, OF, SF, ZF, AF, and PF flags are undefined

;AX = 37D7h = 14,295 D;BH = 97h = 151 D

DIV BH ; AX/BH, AL = quotient = 5Eh =94D, AH = remainder = 65h =101D

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

Instruction Descriptions8 86 Microprocessor

Page 58: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 58/96

p

58

ESC –Escape

This instruction is used to pass instructions to aco-processor, such as the 8087 math processorwhich shares the address and data bus with

8086. Instructions for the co-processor arerepresented by a 6-bit code embedded in theescape instruction. As the 8086 fetchesinstruction bytes, the co-processor also catchesthese bytes from the data bus and puts them inits queue.

Dheeraj Suri

Instruction Descriptions8 86 Microprocessor

Page 59: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 59/96

p

59

HLT – HaltProcessing

The HLT instruction will cause the 8086 to stopfetching and executing instructions. The 8086will enter a halt state. The only ways to get the

processor out of the halt state are with aninterrupt signal on the INTR pin, an interruptsignal on the NMI pin, or a reset signal on theRESET input.

Dheeraj Suri

Instruction Descriptions8 86 Microprocessor

Page 60: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 60/96

p

60

IDIV –Divide by

signed byteor word –IDIVsource

This instruction is used to divide a signed wordby a signed byte, or to divide a signeddoubleword (32bits) by a signed word.

When dividing a signed word by a signed byte,the world must be in the AX register. The divisorcan be in an 8-bit register or a memory location.After the division, AL will contain the signedresult (quotient), and AH will contain the signedremainder. The sign of the remainder will be the

same as the sign of the dividend. If an attempt ismade to divide by 0, the quotient is greater than127 (7Fh), or the quotient is less than -127(81h), the 8086 will automatically do a type 0interrupt.If one wants to divide a signed byte by a signed

byte, one must first put the dividend byte in ALand fill AH with copies of the sign bit from AL. Inother words, if AL is +ve, then AH should befilled with all 0’s . If AL is –ve (sign bit = 1)..

Dheeraj Suri

Instruction Descriptions8 86 Microprocessor

Page 61: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 61/96

p

61

IDIV –Divide by

SignedByte orWord –IDIV

source

--- then AH should be filled with all 1’s. The8086 convert byte to world instruction, CBW,does this by copying the sign bit of AL to all bits

of AH. AH is then said to contain the “signextension of AL”.Likewise, if one wants to divide a signed word bya signed word, one must put the dividend wordin AX and extend the sign of AX to all bits of DX.The 8086 Convert Word to Double word

instruction, CWD, will copy the sign bit of AX toall bits of DX.

Dheeraj Suri

Flags affected : All flags are undefined after a IDIV.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX XX XX XX XX XX XX XX XX

Instruction Descriptions8 86 Microprocessor

Page 62: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 62/96

62

IDIV –Divide by

SignedByte orWord –IDIV

source

Examples(Coding):

Dheeraj Suri

Flags affected : All flags are undefined after a IDIV.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX XX XX XX XX XX XX XX XX

IDIV BL ; Signed word in AX/signed byte; in BL

IDIV BP ; Signed double-word in DX andAX/signed word

IDIV BYTEPTR[BX]

; AX/byte at offset [BX] in DS

MOV AL,DIVIDEND

; position byte dividend

CBW ; Extend sign of AL into AH

IDIVDIVISOR 

; Divide by byte divisor

Instruction Descriptions8 86 Microprocessor

Page 63: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 63/96

63

IDIV –Divide by

SignedByte orWord –IDIV

source

Examples(Numerical):

Note: The quotient is negative because positiveWas divided by negative. The remainder has same sign as dividend(positive)

Dheeraj Suri

Flags affected : All flags are undefined after a IDIV.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX XX XX XX XX XX XX XX XX

; A signed word divided by a; signed byte

; AX = 00000011 10101011=03ABh = 39 D; BL = 11010011 = D3h = -2Dh= -45 decimal

IDIV BL ; Quotient: AL = Ech = -14h = -20

decimal; Remainder: AH = 27h = + 39D

Instruction Descriptions8 86 Microprocessor

Page 64: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 64/96

64

IDIV –Divide by

SignedByte orWord –IDIV

source

Examples(Numerical)- contd.:

Note: Although the quotient is actually closer to 13 (12.66667) than to12, the 8086 truncates it to 12 rather than rounding it to 13. If you wantto round the quotient, you can compare the magnitude of the remainderwith (divisor/2) and add 1 to the quotient if the remainder is greater

than (divisor/2). Note that the sign of the remainder is the same as the sign of the dividend (negative).

Dheeraj Suri

Flags affected : All flags are undefined after a IDIV.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

XX XX XX XX XX XX XX XX XX

; A signed byte divided by asigned byte

; AX = 11011010= - 26h = -38 D; CH = 00000011 = +3h = +3D

CBW ; Extend sign of AL through AH

; AX = 11111111 11011010

IDIV CH ; Divide AX by CH

; AL = 11110100 = -0Ch = -12 D

; AH = 11111110 = -2h = -2D

Instruction Descriptions8 86 Microprocessor

Page 65: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 65/96

65

IMUL –Multiply

SignedNumbers –IMULSource

This instruction multiplies a signed byte from some source times asigned byte in AL or a signed word from some source times a signed wordin AX. The source can be another register or a memory location specifiedby any one of the 24 addressing modes (memory addressing). When abyte from some source is multiplied by AL, the signed result will be put in

AX. A 16-bit destination is required because the result of multiplying two8-bit numbers can be as large as 16-bits. When a word from some sourceis multiplied by AX, the result can be as large as 32 bits. The higher orderword of signed result is put in DX, and lower order word is put in AX. Ifthe magnitude of the product doesn’t require all bits of destination, theunused bits will be filled with copies of sign bit. If the upper byte of a 16-bit result or the upper word of a 32-bit result contains only copies of thesign bit (all 0’s or all 1’s ) , then CF and OF will be both 0. if the upperbyte of a 16-bit result or the upper word of a 32-bit result contains part

of the product, CF and OF will both be 1. One can use the status of theflags to determine whether upper byte or word of the product needs to bekept. One can use the status of these flags to determine whether upperbyte or word of the product needs to be kept.If one wants to multiply a signed byte by a signed word, one must firstmove the byte into a word location and fill the upper byte of the word

with copies of the sign bit. If one moves the byte into AL, one can use the8086 convert byte to word instruction, CBW, to do this.

Dheeraj Suri

Flags affected : CF and OF are updated. AF, PF, SF and ZF are undefined after IMUL

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF CF

Instruction Descriptions8 86 Microprocessor

Page 66: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 66/96

66

IMUL –Multiply

SignedNumbers –IMULSource

Examples (Coding):

Dheeraj Suri

Flags affected : CF and OF are updated. AF, PF, SF and ZF are undefined after IMUL

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF CF

IMUL BH ; Signed byte in AL times; signed byte in BH. Result in AX.

IMUL AX ; AX times AX, result in DX and; AX

; Multiplying a signed byte by a; signed word

MOV CX,MULTIPLIER 

; Load signed word in CX

MOV AL,MULTIPLICAND

; Load signed byte in AL

CBW ; Extend sign of AL into AH

IMUL CX ; Result in DX and AX

Instruction Descriptions8 86 Microprocessor

Page 67: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 67/96

67

IMUL –Multiply

SignedNumbers –IMULSource

Examples (Numerical):

Dheeraj Suri

Flags affected : CF and OF are updated. AF, PF, SF and ZF are undefined after IMUL

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF CF

; 69 X 14

; AL = 01000101 = 69 Decimal; BL = 00001110 = 14 Decimal

IMUL BL ; AX = 03C6h = +966 decimal; MSB = 0, positive result; magnitude in true form. SF = 0,; CF, OF = 1; -28’ 59

; AL = 11100100 = -28 decimal; BL = 00111011 = +59 decimal

IMUL BL ; AX = F89Ch = -1652 decimal; MSB = 1, negative resultmagnitude, in 2’s compliment; SF, CF, OF = 1

Instruction Descriptions8 86 Microprocessor

Page 68: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 68/96

68

IN – Copydata from a

port – INAccumulator, Port

The IN instruction will copy data from a port to the ALor AX register. If an 8-bit port is read, the data will goto AL. If a 16-bit port is read, the data will go to AX.The IN instruction has two possible formats, fixed port

and variable port.For the fixed port type, the 8-bit address of a port isspecified directly in the instruction. Examples:

Dheeraj Suri

Flags affected : The IN instruction do not change any flags.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IN AL, 0C8h ;Input a byte from port 0C8h to; AL

IN AX, 34h ; Input a word from port 34h to AXA_TO_D EQU4Ah

IN AX,A_TO_D

; Input a word from port 4Ah to; AX

Instruction Descriptions8 86 Microprocessor

Page 69: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 69/96

69

IN – Copydata from a

port – INAccumulator, Port

For the variable-port-type IN instruction, the portaddress is loaded into the DX register before the INinstruction. Since DX is a 16-bit register, the portaddress can be any number between 0000h and FFFFh.

Therefore, up to 65,536 ports are addressable in thismode. Examples:

Dheeraj Suri

Flags affected : The IN instruction do not change any flags.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

MOV DX,0FF78h

; Initialize DX to point to port

IN AL, DX ; Input a byte from 8-bit port

; 0FF78h to AL

IN AX, DX ; Input a word from 16-bit port; 0FF78h to AX

Instruction Descriptions8 86 Microprocessor

Page 70: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 70/96

70

INC –Increment-

INCdestination

The INC instruction adds 1 to a specifiedregister or to a memory location specified inany one of the 24 addressing modes

(memory). Examples:

Note: Carry flag is not affected. This means that if an 8-bit destination containing FFh ora 16-bit destination containing FFFFh is incremented, the result will be all 0’s with noCarry

Dheeraj Suri

Flags affected : AF, OF, PF, SF, and ZF are affected. CF is not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF DF IF TF SF ZF AF PF

INC BL ; Add 1 to contents of BL; register

INC CX ; Add 1 to contents of CX

register

Instruction Descriptions8 86 Microprocessor

Page 71: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 71/96

71

INT –Interrupt

ProgramExecution –

INT Type

The Term Type in this instruction formatrefers to a number between 0 and 255which identifies the interrupt. When an

8086 executes an INT instruction, it will:1. Decrement the SP by 2 and push the

flags onto stack.2. Decrement the SP by 2 and push

contents of CS onto the stack.

3. Decrement the stack pointer by 2 andpush the offset of the next instructionafter the INT number instruction on tothe stack

4. Contd. On next slide.

Dheeraj Suri

Flags affected : IF and TF are affected. Other flags are not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

Instruction Descriptions8 86 Microprocessor

Page 72: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 72/96

72

INT –Interrupt

ProgramExecution –

INT Type

4. Get a new value for IP from an absolutememory address of 4 times the typespecified in the instruction.

5. Get a new value for CS from an absolutememory address of 4 times the typespecified in the instruction plus 2.6. Reset both IF and TF. Other flags are notaffected. Examples:

Dheeraj Suri

Flags affected : IF and TF are affected. Other flags are not affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

INT 35 ; New IP from 0008Ch, new CS from0008Eh

INT 3 ; This is a special form which hasthe single-byte code of CCh. Manysystems use this as a break-pointinstruction. New IP from 0000Ch,new CS from 0000Eh

Instruction Descriptions8 86 Microprocessor

Page 73: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 73/96

73

INTO-Interrupt

on

Overflow

If the overflow flag (OF) is set, this instruction willcause the 8086 to do an indirect far call to a procedureyou write to handle the overflow condition. Beforedoing the call, the 8086 will:

1. Decrement the stack pointer by 2 and push theflags onto stack.

2. Decrement the stack pointer, by 2 and push CSonto the stack.

3. Decrement the SP by 2 and push the offset of thenext instruction after the INTO instruction onto the

stack.4. Reset TF and IF. Other flags are not affected. Todo the call, the 8086 will read a new value for IPfrom address 00010h and a new value of CS fromaddress 00012h.

Dheeraj Suri

Flags affected :

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IF TF

INTO ; Call interrupt procedure if OF = 1

Instruction Descriptions8 86 Microprocessor

Page 74: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 74/96

74

IRET –Interrupt

Return

When the 8086 responds to an interrupt signalor to an interrupt instruction, it pushes the flags,the current value of CS, and the current value of

IP onto the stack. It then loads CS and IP withthe starting address of the procedure which onewrites for the response to that interrupt. TheIRET instruction is used at the end of theinterrupt service procedure to return executionto the interrupted program. To do this return,

the 8086 copies the saved value of IP from thestack to IP, the stored value of CS from the stackto CS, and the stored value of the flags back tothe flag register. Flags will have the values theyhad before the interrupt, so any flag settingsfrom the procedure will be lost unless they are

specifically saved in some way.

Note: The RET instruction should not normally be used to return from interrupt procedures because it doesnot copy the flags from the stack back to the flagregister.

Dheeraj Suri

Instruction Descriptions8 86 Microprocessor

Page 75: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 75/96

75

JA/JNBE

– Jump ifAbove/Jump if Notbelow or

Equal

The terms above and below are used whenreferring to the magnitude of unsigned numbers.The number 0111 is above the number 0010. If,

after a compare or some other instruction whichaffects flags, the zero flag and the carry flag areboth 0, this instruction will cause execution to

 jump to a label given in the instruction. If CF andZF are not both 0, the instruction will have noeffect on program execution. The destination

label for the jump must be in the range of -128bytes to +127 bytes from the address of theinstruction after the JA. JA/JNBE affects noflags.

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 76: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 76/96

76

JA/JNBE

– Jump ifAbove/Jump if Notbelow or

Equal

Examples:

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP AX, 4371h ; Compare by subtracting 4371h; from AX

JA RUN_PRESS ; Jump to label RUN_PRESS ifAX is; above 4371h

CMP AX, 4371h ; Compare (AX – 4371h)

JNBERUN_PRESS

; jump to label RUN_PRESS ifAX; not below or equal to 4371h

Instruction Descriptions8 86 Microprocessor

Page 77: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 77/96

77

JAE/JNB/

JNC –Jump ifAbove orEqual/Ju

mp if Notbelow/Jump if NoCarry

The three mnemonics represent the sameinstruction. The terms above and below are usedwhen referring to the magnitude of unsigned

numbers. The number 0111 is above the number0010. If, after a compare or some otherinstruction which affects flags, the carry flag is0, this instruction will cause execution to jumpto a label given in the instruction. If CF is 1, theinstruction will have no effect on the program

execution. The destination label for the jumpmust be in the range of -128 bytes to +127 bytesfrom the address of the instruction after the JAE.JAE/JNB/JNC affects no flags.

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 78: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 78/96

78

JAE/JNB/

JNC –Jump ifAbove orEqual/Ju

mp if Notbelow/Jump if NoCarry

Examples:

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP AX,4371h ; Compare (AX – 4371h)

JAERUN_PRESS

; Jump to label RUN_PRESS if AXis; above or equal to 4371h

CMP AX,4371h

; Compare (AX – 4371h)

JNBRUN_PRESS

; Jump to label RUN_PRESS if AX; not below 4371h

ADD AL,BL ; Add two bytes. If result within; acceptable range continue

JNC OK

Instruction Descriptions8 86 Microprocessor

Page 79: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 79/96

79

JB/JC/JN

AE –Jump ifBelow/Jump if

Carry/Jump if Notabove orEqual

These three mnemonics represent the sameinstruction. Just like previous, the description ofthese instructions can be understood.

Examples:

Dheeraj Suri

Flags affected : No Flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP AX,4371h ; Compare (AX – 4371h)

JB RUN_PRESS ; Jump to label RUN_PRESS if AXbelow; 4371h

ADD BX,CX ; Add two words and jump to label

ERROR_FIX if CF = 1

JC ERROR_FIX

CMP AX,4371h ; Compare AX – 4371h

JNAERUN_PRESS

; Jump to label RUN_PRESS if AX; not above or equal to 4371h

Instruction Descriptions8 86 Microprocessor

Page 80: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 80/96

80

JBE/JNA

– Jump ifBelow orEqual/Jump if Not

above

JBE & JNA represent the same instruction. Theterms above and equal are used when referringto the magnitude of unsigned numbers. The

number 0111 is above the number 0010. If, aftera compare or some other instruction whichaffects flags, either the zero flag or the carry flagis 1, this instruction will cause execution to jumpto a label given in the instruction. If CF and ZFare both 0, the instruction will have no effect on

program execution. The destination label for the jump must be in the range of -128 bytes to +127bytes from the address of the instruction afterthe JBE. JBE/JNA affects no flags.

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 81: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 81/96

81

JBE/JNA

– Jump ifBelow orEqual/Jump if Not

above

Examples:

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP AX, 4371h ; Compare (AX – 4371h)

JBE RUN_PRESS ; Jump to label RUN_PRESS

; if AX below or equal to; 4371h

CMP AX, 4371h ; Compare (AX – 4371h)

JNA RUN_PRESS ; Jump to label RUN_PRESSif

; AX not above 4371h

Instruction Descriptions8 86 Microprocessor

Page 82: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 82/96

82

JCXZ –Jump ifCXregisteris Zero

This instruction will cause a jump to a label given inthe instruction if the CX register contains all 0’s,execution will simply proceed to the next instruction.Note that this instruction doesnot look at the zero flag

when it decides whether to jump or not. Thedestination label for this instruction must be in therange of -128 to +127 bytes from the address of theinstruction after JCXZ instruction. JCXZ affects noflags. Example:

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JCXZ SKIP_LOOP ; IF CX = 0, skip the process

NXT: SUB [BX], 07h ; Subtract 7 from data value

INC BX ; point to next value

LOOP NXT ; Loop until CX = 0

SKIP_LOOP: ; Next instruction

Instruction Descriptions8 86 Microprocessor

Page 83: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 83/96

83

JE/JZ –Jump ifEqual/Jump ifZero

JE & JZ mnemonics represent the sameinstruction. If the zero flag is set, this instructionwill cause execution to jump to a label given in

the instruction. If the zero flag is not 1,execution will simply go on to the nextinstruction after JE or JZ. The destination labelfor the JE/JZ instruction must be in the range of-128 to +127 bytes from the address of theinstruction after the JE/JZ instruction. JE/JZ

affects no flags. Example : (next slide)

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 84: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 84/96

84

JE/JZ –Jump ifEqual/Jump ifZero

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

NXT: CMP BX, DX ; Compare (BX – DX)

JE DONE ; Jump to DONE if BX = DX

SUB BX, AX ; Else subtract AXINC CX ; Increment Counter

JMP NXT ; Check again

DONE: MOV AX, CX ; Copy count to AX

IN AL, 8Fh ; Read data from port 8Fh

SUB AL, 30h ; Subtract minimum value

JZ START_MACHINE ; Jump to label if result of; subtraction was 0

Instruction Descriptions8 86 Microprocessor

Page 85: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 85/96

85

JG/JNLE-Jump ifGreater/Jump ifNot less

than orEqual

JG or JNLE represent the same instruction. Theterms greater or less are used to refer to therelationship of two signed numbers. Greater

means more positive. The number 00000111 isgreater than the number 11101010, because insigned notation the second number is negative.This instruction is usually used after a Compareinstruction. The instruction will cause a jump toa label given in the instruction if the Zero Flag is

0 and the carry flag is the same as the overflowflag. The destination label must be in the rangeof -128 bytes to +127 bytes from the address of instruction after JG/JNLE instruction. If the jumpis not taken, execution simply goes on to thenext instruction after the JG or JNLE instruction.

JG/JNLE affects no flags.

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 86: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 86/96

86

JG/JNLE-Jump ifGreater/Jump ifNot less

than orEqual

Examples:

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP BL, 39h ; Compare by subtracting 30h; from BL

JG NEXT_1 ; Jump to label if BL morepositive than 39h

CMP BL, 39h ; Compare by subtracting 39h; from BL

JNLE NEXT_1 ; Jump to label if BL not less

than; or equal to 39h

Instruction Descriptions8 86 Microprocessor

Page 87: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 87/96

87

JGE/JNL– Jump ifGreaterThan orEqual/Ju

mp if Notless Than

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JGE/JNL both represent the same instruction. Theterms greater and less are used to refer to therelationship of two signed numbers. Greater meansmore positive. The number 00000111 is greater

than the number 11101010, because in signednotation the second number is negative. Thisinstruction is usually used after the compareinstruction. The instruction will cause a jump to alabel given in the instruction if the sign flag is equalto the overflow flag. The destination label must be

in the range of -128 bytes to +127 bytes from theaddress of the instruction after the JGE/JNLinstruction. If the jump is not taken, executionsimply goes on to the next instruction after the JGEor JNL instruction. JGE/JNL affects no flags.Example (on next slide)

Instruction Descriptions8 86 Microprocessor

Page 88: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 88/96

88

JGE/JNL– Jump ifGreaterThan orEqual/Ju

mp if Notless Than

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP BL, 39h ; Compare by subtracting 39hfrom BL

JGE NEXT_1 ; Jump to label if BL morepositive; than 39h or equal to 39h

CMP BL, 39h ; Compare by subtracting 39hfrom BL

JNL NEXT_1 ; Jump to label if BL not lessthan 39h

Instruction Descriptions8 86 Microprocessor

Page 89: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 89/96

89

JL/JNGE –Jump ifLessThan/Jumpif Not

GreaterThan orEqual

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JL/JNGE both represent the same instruction. Theterms greater and less are used to refer to therelationship of two signed numbers. Greater meansmore positive. The number 00000111 is greater

than the number 11101010, because in signednotation the second number is negative. Thisinstruction is usually used after the compareinstruction. The instruction will cause a jump to alabel given in the instruction if the sign flag is notequal to the overflow flag. The destination label

must be in the range of -128 bytes to +127 bytesfrom the address of the instruction after theJL/JNGE instruction. If the jump is not taken,execution simply goes on to the next instructionafter the JL or JNGE instruction. JL/JNGE affects noflags. Example (on next slide)

Instruction Descriptions8 86 Microprocessor

Page 90: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 90/96

90

JL/JNGE –Jump ifLessThan/Jumpif Not

GreaterThan orEqual

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP BL, 39h ; Compare by subtracting 39hfrom BL

JL AGAIN ;Jump to label if BL morenegative than 39h

CMP BL, 39h ; Compare by subtracting 39hfrom BL

JNGE AGAIN ; Jump to label if BL not morepositive than 39h or BL notequal to 39h

Instruction Descriptions8 86 Microprocessor

Page 91: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 91/96

91

JLE/JNG –Jump ifLess ThanorEqual/Jump

if NotGreater

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JLE/JNG both represent the same instruction. Theterms greater and less are used to refer to therelationship of two signed numbers. Greater meansmore positive. The number 00000111 is greater

than the number 11101010, because in signednotation the second number is negative. Thisinstruction is usually used after the compareinstruction. The instruction will cause a jump to alabel given in the instruction if the zero flag is set,or if the sign flag is not equal to the overflow flag.

The destination label must be in the range of -128bytes to +127 bytes from the address of theinstruction after the JLE/JNG instruction. If the jump is not taken, execution simply goes on to thenext instruction after the JL or JNGE instruction.JLE/JNG affects no flags. Example (on next slide)

Instruction Descriptions8 86 Microprocessor

Page 92: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 92/96

92

JLE/JNG –Jump ifLess ThanorEqual/Jum

p if NotGreater

Dheeraj Suri

Flags affected : No flags are affected.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

CMP BL, 39h ; Compare by subtracting 39hfrom BL

JLE NXT_1 ; Jump to label if BL more than39h or equal to 39h

CMP BL,39h ; Compare by subtracting 39hfrom BL

JNGPRINTER 

; Jump to label if BL not morepositive than 39h

Instruction Descriptions8 86 Microprocessor

Will l th 8086 t f t h th t

Page 93: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 93/96

93

JMP-Unconditional JumptoSpecified

Destination

Will always cause the 8086 to fetch the nextinstruction from the location specified in theinstruction rather than from the next location

after the JMP instruction. If the destination is inthe same code segment as the JMP instruction,then only the instruction pointer will be changedto get to the destination location (near jump). Ifthe destination for the jump instruction is in asegment with a name different from that of the

segment containing the JMP instruction, thenboth the IP and CS segment register contentswill be changed to get to the destination location(far jump). The JMP instruction affects no flags.Examples: (next slide)

Dheeraj Suri

Flags affected : No flags are affected after JMP instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Instruction Descriptions8 86 Microprocessor

Page 94: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 94/96

94

JMP-Unconditional JumptoSpecified

Destination

Dheeraj Suri

Flags affected : No flags are affected after JMP instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JMP Continue ; Fetch next instruction fromaddress at label CONTINUE

JMP BX ; Replace the contents of IPwith; the contents of BX. BX mustfirst be loaded with the offsetof the destination instructionin CS. This is a near jump. It is

also referred to as an indirect jump because the new valuefor IP comes from a registerrather than from theinstruction itself, as in a direct

 jump.

Instruction Descriptions8 86 Microprocessor

Page 95: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 95/96

95

JMP-Unconditional JumptoSpecified

Destination

Dheeraj Suri

Flags affected : No flags are affected after JMP instruction.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

JMP WORDPTR[BX]

; Replace IP with a word to byBX ; in DS. This is an indirectnear jump.

JMP DWORDPTR[SI]

; Replace IP with a wordpointed to by SI in DS. ReplaceCS with a word pointed to bySI + 2 in DS. This is an indirectfar jump.

Instruction Descriptions8 86 Microprocessor

The slides for rest of the instr ctions are

Page 96: Microprocessor 8086 MPA2

7/23/2019 Microprocessor 8086 MPA2

http://slidepdf.com/reader/full/microprocessor-8086-mpa2 96/96

The slides for rest of the instructions areUnder construction. Until then studentsAre advised to refer section 6.2 in

Douglas V. Hall!

Flags affected :

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF DF IF TF SF ZF AF PF CF