Please copy and paste this embed script to where you want to embed

8086 Instruction Template Need for Instruction Template 8085 has 246 opcodes. The opcodes can be printed on an A4 size paper. 8086 has about 13000 opcodes. A book of about 60 pages is needed for printing the opcodes. Concept of Template In 8085, MOV r1, r2 (ex. MOV A, B) has the following template. 0

1

3-bit r1 code

3-bit Register code 000 001 010 011 100 101 110 111

3-bit r2 code

Register B C D E H L M A

Ex. 1: Code for

MOV A, 01 11 1 7

B is 000 = 78H 8

Ex.2: Code for

MOV M, D is 01 11 0 010 = 72H 7 2

Using the template for MOV r1, r2 we can generate opcodes of 26 = 64 opcodes. 8086 Template for data transfer between REG and R/M 1 0 0 0

1

0 D

W

MOD 2 bits

REG 3 bits

R/M 3 bits

REG = A register of 8086 (8-bit or 16-bits) (except Segment registers, IP, and Flags registers) Thus REG = AL/ BL/ CL/ DL/ AH/ BH/ CH/ DH/ AX/ BX/ CX/ DX/ SI/ DI/ BP/ SP R/ M = Register (as defined above) or Memory contents (8-bits or 16-bits) W = 1 means Word operation W = 0 means Byte operation

D = 1 means REG is Destination register D = 0 means REG is source register MOD = 00 means R/M specifies Memory with no displacement MOD = 01 means R/M specifies Memory with 8-bit displacement MOD = 10 means R/M specifies Memory with 16-bit displacement MOD = 11 means R/M specifies a Register 3-bit Register code 000 001 010 011 100 101 110 111

Register name When W = 1 When W = 0 AX AL CX CL DX DL BX BL SP AH BP CH SI DH DI BH

Aid to remember:

ALl Children Drink Bournvita (AL, CL, DL, BL) SPecial Beverages SIamese DrInk (SP, BP, SI, DI)

Case of MOD = 11 Example: Code for MOV AX, BX treated as ‘Move from BX to destination register AX’

1 0 0 0

1

0

D 1

8

W 1 Word operation

MOD 11

B

REG 00 0 AX is destination C

R/M 011 BX

= 8B C3H

3

Example: Alternative code for MOV AX, BX treating it as ‘Move from source register BX to register AX’

1 0 0 0

8

1

D 0 0

W 1 Word operation 9

MOD 11

D

REG 01 1 BX is source

R/M 000 AX

= 89 D8H

8

There are 2 possible opcodes for MOV AX, BX as we can choose either AX or BX as REG.

Example: Code for MOV AL, BH treated as ‘Move from BL to destination register AL’

1 0 0 0

1

D 0 1

8

W 0 Byte operation

MOD 11

A

REG 00 0 AL is destination

R/M 111 BH

C

= 8A C7H

7

Example: Alternative code for MOV AL, BH treating it as ‘Move from source register BH to register AL’

1 0 0 0

8

1

D 0 0

W 0 Byte operation

MOD 11

8

REG 11 1 BH is source

F

R/M 000 AL

= 88 F8H

8

There are 2 possible opcodes for MOV AL, BH as we can choose either AL or BH as REG. Case of MOD = 00, 01 or 10 R/M

000 001 010 011 100 101 110 111

MOD = 00 No Displacement [SI+BX] [DI+BX] [SI+BP] [DI+BP] [SI] [DI] [BP] Direct Addressing [BX]

MOD = 01 8-bit signed displacement d8 [SI+BX+d8] [DI+BX+d8] [SI+BP+d8] [DI+BP+d8] [SI+d8] [DI+d8] [BP+d8]

MOD = 10 16-bit signed displacement d16 [SI+BX+d16] [DI+BX+d16] [SI+BP+d16] [DI+BP+d16] [SI+d16] [DI+d16] [BP+d16]

[BX+d8]

[BX+d16]

The table shows 24 memory addressing modes i.e. 24 different ways of accessing data stored in memory. Aid to remember: SubInspector DIxit is a BoXer ( [SI+BX] and [DI]+[BX] ) SubInspector DIxit knows to control BP ( [SI+BP] and [DI]+[BP] ) He says’ SImple DIet DIRECTs a BoXer' ( [SI], [DI], Direct addressing, [BX] )

Ex: Code for MOV CL, [SI]

1 0 0 0

1

D 1

0

8

W 0 Byte operation

MOD REG R/M 00 00 1 100 No CL is [SI] Disp. destination 0 C

A

= 8A 0CH

Note that there is a unique opcode for MOV CL, [SI] as CL only can be REG. Ex: Code for MOV 46H[BP], DX D 1 0 0 0 1 0 0

8

W 1 Word operation

MOD REG R/M d8 01 01 0 110 46H 8-bit DX is [BP+d8] Disp. source 5 6

9

= 89 56 46H

Note that there is a unique opcode for MOV 46H[BP], DX as DX only can be REG. Ex: Code for MOV 0F246H[BP], DX

1

0

0

0

1

D 0 0

8

W 1 Word operation 9

MOD 10 16-bit Disp. 9

REG 01 0 DX is source

R/M 110 [BP+d16]

d16 F2 46H

6

= 89 96 F2 46H Stored as 89 96 46 F2H in Little Endian

Note that there is a unique opcode for MOV 0F246H[BP], DX as DX only can be REG.

Ex: Code for MOV [BP], DX

1 0 0 0 1 0

8

D 0

W 1 Word operation 9

MOD REG R/M d8 01 01 0 110 00H 8-bit DX is [BP+d8] Disp. source 5 6

Note that MOV [BP], DX is treated as MOV 00H[BP], DX before coding.

= 89 56 00H

Ex: Code for MOV BX, DS:1234H

1 0 0 0 1 0

D

W

MOD

REG

R/M

1

1

00

01 1

110

Word operation 8

B

No BX is Disp. Dest. 1

Direct addr 12 34H

Direct addr. E

Note that when MOD = 00 and R/M = 110, it represents Direct Addressing.

= 8B 1E 12 34H Stored as 8B 1E 34 12H In Little Endian

View more...
1

3-bit r1 code

3-bit Register code 000 001 010 011 100 101 110 111

3-bit r2 code

Register B C D E H L M A

Ex. 1: Code for

MOV A, 01 11 1 7

B is 000 = 78H 8

Ex.2: Code for

MOV M, D is 01 11 0 010 = 72H 7 2

Using the template for MOV r1, r2 we can generate opcodes of 26 = 64 opcodes. 8086 Template for data transfer between REG and R/M 1 0 0 0

1

0 D

W

MOD 2 bits

REG 3 bits

R/M 3 bits

REG = A register of 8086 (8-bit or 16-bits) (except Segment registers, IP, and Flags registers) Thus REG = AL/ BL/ CL/ DL/ AH/ BH/ CH/ DH/ AX/ BX/ CX/ DX/ SI/ DI/ BP/ SP R/ M = Register (as defined above) or Memory contents (8-bits or 16-bits) W = 1 means Word operation W = 0 means Byte operation

D = 1 means REG is Destination register D = 0 means REG is source register MOD = 00 means R/M specifies Memory with no displacement MOD = 01 means R/M specifies Memory with 8-bit displacement MOD = 10 means R/M specifies Memory with 16-bit displacement MOD = 11 means R/M specifies a Register 3-bit Register code 000 001 010 011 100 101 110 111

Register name When W = 1 When W = 0 AX AL CX CL DX DL BX BL SP AH BP CH SI DH DI BH

Aid to remember:

ALl Children Drink Bournvita (AL, CL, DL, BL) SPecial Beverages SIamese DrInk (SP, BP, SI, DI)

Case of MOD = 11 Example: Code for MOV AX, BX treated as ‘Move from BX to destination register AX’

1 0 0 0

1

0

D 1

8

W 1 Word operation

MOD 11

B

REG 00 0 AX is destination C

R/M 011 BX

= 8B C3H

3

Example: Alternative code for MOV AX, BX treating it as ‘Move from source register BX to register AX’

1 0 0 0

8

1

D 0 0

W 1 Word operation 9

MOD 11

D

REG 01 1 BX is source

R/M 000 AX

= 89 D8H

8

There are 2 possible opcodes for MOV AX, BX as we can choose either AX or BX as REG.

Example: Code for MOV AL, BH treated as ‘Move from BL to destination register AL’

1 0 0 0

1

D 0 1

8

W 0 Byte operation

MOD 11

A

REG 00 0 AL is destination

R/M 111 BH

C

= 8A C7H

7

Example: Alternative code for MOV AL, BH treating it as ‘Move from source register BH to register AL’

1 0 0 0

8

1

D 0 0

W 0 Byte operation

MOD 11

8

REG 11 1 BH is source

F

R/M 000 AL

= 88 F8H

8

There are 2 possible opcodes for MOV AL, BH as we can choose either AL or BH as REG. Case of MOD = 00, 01 or 10 R/M

000 001 010 011 100 101 110 111

MOD = 00 No Displacement [SI+BX] [DI+BX] [SI+BP] [DI+BP] [SI] [DI] [BP] Direct Addressing [BX]

MOD = 01 8-bit signed displacement d8 [SI+BX+d8] [DI+BX+d8] [SI+BP+d8] [DI+BP+d8] [SI+d8] [DI+d8] [BP+d8]

MOD = 10 16-bit signed displacement d16 [SI+BX+d16] [DI+BX+d16] [SI+BP+d16] [DI+BP+d16] [SI+d16] [DI+d16] [BP+d16]

[BX+d8]

[BX+d16]

The table shows 24 memory addressing modes i.e. 24 different ways of accessing data stored in memory. Aid to remember: SubInspector DIxit is a BoXer ( [SI+BX] and [DI]+[BX] ) SubInspector DIxit knows to control BP ( [SI+BP] and [DI]+[BP] ) He says’ SImple DIet DIRECTs a BoXer' ( [SI], [DI], Direct addressing, [BX] )

Ex: Code for MOV CL, [SI]

1 0 0 0

1

D 1

0

8

W 0 Byte operation

MOD REG R/M 00 00 1 100 No CL is [SI] Disp. destination 0 C

A

= 8A 0CH

Note that there is a unique opcode for MOV CL, [SI] as CL only can be REG. Ex: Code for MOV 46H[BP], DX D 1 0 0 0 1 0 0

8

W 1 Word operation

MOD REG R/M d8 01 01 0 110 46H 8-bit DX is [BP+d8] Disp. source 5 6

9

= 89 56 46H

Note that there is a unique opcode for MOV 46H[BP], DX as DX only can be REG. Ex: Code for MOV 0F246H[BP], DX

1

0

0

0

1

D 0 0

8

W 1 Word operation 9

MOD 10 16-bit Disp. 9

REG 01 0 DX is source

R/M 110 [BP+d16]

d16 F2 46H

6

= 89 96 F2 46H Stored as 89 96 46 F2H in Little Endian

Note that there is a unique opcode for MOV 0F246H[BP], DX as DX only can be REG.

Ex: Code for MOV [BP], DX

1 0 0 0 1 0

8

D 0

W 1 Word operation 9

MOD REG R/M d8 01 01 0 110 00H 8-bit DX is [BP+d8] Disp. source 5 6

Note that MOV [BP], DX is treated as MOV 00H[BP], DX before coding.

= 89 56 00H

Ex: Code for MOV BX, DS:1234H

1 0 0 0 1 0

D

W

MOD

REG

R/M

1

1

00

01 1

110

Word operation 8

B

No BX is Disp. Dest. 1

Direct addr 12 34H

Direct addr. E

Note that when MOD = 00 and R/M = 110, it represents Direct Addressing.

= 8B 1E 12 34H Stored as 8B 1E 34 12H In Little Endian

Thank you for interesting in our services. We are a non-profit group that run this website to share documents. We need your help to maintenance this website.

To keep our site running, we need your help to cover our server cost (about $400/m), a small donation will help us a lot.