Instruction Format in 8086
The instruction format of 8086 has one or more number of fields associated with it.
The first filled is called operation code field or opcode field, which indicates the
type of operation. The instruction format also contains other fields known as
operand fields.
There are six general formats of instructions in 8086 instruction set. The length of an
instruction may vary from one byte to six bytes.
8086(Machine Language Instruction Formats)
•A machine language instruction format has one or more number of fields associated with
it.
•The first field is called as operation code field or op-code field, which indicates the type
of operation to be performed by the CPU
•The instruction format also contains other fields known as operand fields
•The CPU executes the instruction using the information which reside in these fields
•There are six general formats of instructions in 8086 instructions set.
•The length of an instruction may vary from 1 byte to 6 bytes. The instruction formats are
described as follows
1 One Byte Instruction:
•This format is only one byte long and may have the implied data or register operands.
•The least significant 3-bits of the opcode are used for specifying the register operand, if
any.
•Otherwise, all the 8 bits form an opcode and the operands are implied
Eg: CLC : clear carry
2 Register to Register:
•This format is 2 bytes long
•The first byte of the code specifies the operation code and width of the operand specified
by ‘w’ bit.
•The second byte of the code shows the register operands and R/M field, as shown below
The register represented by the REG field is one of the operands.
•The R/M field specifies another register or memory location i.e. the other operand.
For example:
MOV: data transfer operation from Register to Register.
MOV CL, AL, i.e
3. Register to/from memory with no displacement:•This format is also 2 bytes long and
similar to the Register to Register format except for the MOD field as shown.
4. Register to/from Memory with Displacement:
•This type of instruction format contains 1 or 2 additional bytes for displacement along
with 2 byte format of the register to/from memory without displacement. The format is as
shown below.
5 Immediate Operand to Register:
•In this format, the first byte as well as the 3-bits from the second byte which are used
for REG field in case of register to register format are used for opcode.
•It also contains one or two bytes of immediate data. The complete instruction format is as
shown below.
6. Immediate Operand to Memory with 16-bit displacement:
•This type of instruction format requires 5 or 6 bytes for coding.
•The first 2 bytes contain the information regarding OPCODE, MOD and R/M fields. The
remaining 4 bytes contain 2 bytes of displacement and 2 bytes of data as shown.
The Opcode stands for Operation Code. Every Instruction has a unique 6-bit opcode.
For example, the opcode for MOV is 100010.
D stands for direction
If D=0, then the direction is from the register
If D=1, then the direction is to the register
W stands for word
If W=0, then only a byte is being transferred, i.e. 8 bits
If W=1, them a whole word is being transferred, i.e. 16 bits
The MOD and R/M together is calculated based upon the addressing mode and
register being used in it. This is calculated as follows:
REG stands for register selected. It is a 3-bit code which is calculated as follows:
REG Code Register Selected
000 AL AX
001 CL CX
010 DL DX
011 BL BX
100 AH SP
101 CH BP
110 DH SI
111 BH DI
R/M 0 0 01 10 11
(Memory Mode with (Memory mode with 8 (Memory Mode with 16 (Register
no displacement) bit displacement) bit displacement) Mode)
000 [BX] + [SI] [BX] + [SI] + d8 [BX] + [SI] + d16 AL AX
001 [BX] + [DI] [BX] + [DI] + d8 [BX] + [DI] + d16 CL CX
010 [BP] + [SI] [BP] + [SI] + d8 [BP] + [SI] + d16 DL DX
011 [BP] + [DI] [BP] + [DI] + d8 [BP] + [DI] + d16 BL BX
100 [SI] [SI] + d8 [SI] + d16 AH SP
101 [DI] [DI] + d8 [DI] + d16 CH BP
110 d16 (direct) [BP] + d8 [BP] + d16 DH SI
111 [BX] [BX] + d8 [BX] + d16 BH DI
Find the instruction format of the following instruction:
MOV BL , AL
(The opcode of MOV instruction is 100010)
Solution:
We are given opcode for MOV = 100010
The value of D = 0
(as the value is being fetched from the register)
The value of W = 0
(as only a byte, i.e. 8 bits are being used)
The MOD here is 1 1
(as the mode is register mode)
The value of REG is 0 0 0 (for register AL)
The value of R/M is 0 1 1
(as the register BL is being used in the register mode)
There is no displacement present in the instruction.
So, the instruction format for the given instruction is:
10001000 11000011
Q2. The opcode of ADD instruction is 000000. Find the instruction format for
the following instructions:
i. ADD AX , [BX]
ii. ADD AL , [2345H]
Solution:
i. Given instruction is : ADD AX , [BX]
Here, opcode = 000000
D = 1 (as the data is being transferred to the
register)
W = 1 (as the processing is being done on 16
bits of data)
MOD = 0 0 (because [BX] represents Memory mode with no
displacement)
REG = 0 0 0 (as AX register is being used in the
instruction)
R/M = 1 1 1 (for [BX] being used with the addressing
mode)
And, there is no displacement here in this instruction,
so the remaining bits will remain empty in the
instruction format.
Hence the instruction format for the given instruction
is:
00000011 00000111
ii. Given instruction is : ADD AL , [2000H]
Here, opcode = 000000 (for ADD instruction)
D = 1 (as the data is being transferred to the
register)
W = 0 (as the processing is being done on 8
bits of data)
MOD = 0 0 (because [BX] represents Memory mode with no
displacement)
REG = 0 0 0 (as AX register is being used in the
instruction)
R/M = 1 1 0 (for direct mode being used as the addressing
mode)
And the displacement here is 2000H
So, the lower bits of displacement are 00H i.e. 0000 0000
And the higher bits of displacement are 20H, i.e. 0010
0000
Hence the instruction format for the given instruction
is:
00000010 00000110 00000000 00100000
ADDRESSING MODES OF 8086
Addressing mode represents a method of assigning the address of the source of data or
operand to the instruction given to the microprocessor.
Addressing mode describes a flexible and efficient way to define complex effective
address.
The addressing modes of the 8086 microprocessor is classified as,
1. Immediate addressing mode:
In this type of mode, immediate data is part of instruction and appears in the form of
successive bytes
Eg: MOV AX, 10ABH
Before Result After result
AX AX
X XX
X
10 AB
2. Direct addressing mode:
In this type of addressing mode a 16-bit memory address is directly specified in the
instruction as a part of it.
The direct addressing mode is also known as Absolute Addressing mode. Here, the
instruction contains the address of the location in memory where the value of the operand is
stored.
Effective address (EA) = address field (A)
Eg:
MOV AX, [5000H]
Before: After:
AX AX
X XX 33 22
X Memory Location Memory Location
22 5000 22 5000
33 5001 33 5001
5002
5002
3. Indirect addressing mode in 8086
There are four types of Indirect addressing modes. Basically indirect addressing mode
means giving the location of the target indirectly. We give the location of data through a
register. Not all registers can be used to give locations.
Only BX, SI, DI, BP are the registers that can be used to store locations.
4. Register addressing mode:
In this type of addressing mode, the data is stored in the register and it can be an 8 bit or 16-
bit register. All the registers, except IP, may be used in this mode.
Effective address (EA) = the address stored in the register R
Eg:
MOV AX, BX
Before: After:
AX AX
FF 33 10 AB
BX BX
10 AB 10 AB
5. Register indirect addressing mode:
The address of the memory location which contains data or operand is determined in a
direct way, using the offset register
Effective address is the content of memory location present in the register.
Eg:
MOV AX, [BX]
Before: After:
AX AX
X XX 33 22
X BX BX
50 00 50 00
Memory Location Memory Location
22 5000 22 5000
33 5001 33 5001
5002
5002
6. Indexed addressing mode:
In this addressing mode, offset of the operand is stored in one of the index registers.
DS is the default segment for index register SI and DI
Effective address (EA) = address field (A) + address of Index Register (IR)
Eg:
MOV AX, [SI]
Before: After:
AX AX
X XX 33 22
X SI SI
50 00 50 00
Memory Location Memory Location
22 5000 22 5000
33 5001 33 5001
5002
5002
7. Register relative addressing mode:
In this mode, the data is available at an effective address formed by adding an 8 bit or
16 bit displacement with the content of any one of the registers BX, BP, SI and DI in
the default (either DS or ES) Segment.
instead of a register, the program counter is used.
Effective Address = Value of PC + Address part of the instruction
Eg:
MOV AX, 50H[BX]
Before: After:
AX AX
X XX 33 44
X BX BX
50 00 50 00
Effective Address = Value of PC + Address part of the
instruction
5000 + 50 = 5050 H is the new memory location and get the data from the address location
5050H
Effective Address = 5050 H
Memory Location Memory Location
44 5000
5050 44 5050
33 5051
5001 33 5051
5002
5052
5052
8. Base plus index addressing mode:
In this mode the effective address is formed by adding content of a base register (any
one of BX or BP) to the content of an index register (SI or DI). Default segment
register ES or DS.
Effective address : Index register + Base register
Eg:
MOV AX,[BX] [SI]
Before: After:
AX AX
X XX 34 12
X BX BX
10 00 10 00
SI SI
20 00 20 00
1000 + 2000 = 3000 is the new memory location and get the data from address
location 3000
Memory Location Memory Location
12 5000
3000 12 3000
34 3001
5001 34 3001
5002
3002
3002
9. Base relative plus index addressing mode:
In the effective address is formed by adding an 8 bit or 16-bit displacement with sum of
contents of any one of the base registers (BX or BP) and any one of the index registers, in
a default segment.
Effective address: Index register + Base register + Constant
Eg:
MOV AX,50H[BX][SI]
Before: after
AX AX
X XX 34 12
X
BX BX
10 00 10 00
SI SI
20 00 20 00
50 +1000 + 2000 = 3050 is the new memory location and get the data from address
location 3000
Memory Location Memory Location
12 5000
3050 12 3050
34 3051
5001 34 3051
5002
3052
3052
The 8086 microprocessor supports 8 types of instructions −
Data Transfer Instructions
Arithmetic Instructions
Bit Manipulation Instructions
String Instructions
Program Execution Transfer Instructions (Branch & Loop Instructions)
Processor Control Instructions
Iteration Control Instructions
Interrupt Instructions
Let us now discuss these instruction sets in detail.
Data Transfer Instructions
These instructions are used to transfer the data from the source operand to the destination
operand. Following are the list of instructions under this group −
Instruction to transfer a word
MOV − Used to copy the byte or word from the provided source to the
provided destination.
Eg:
MOV BX,00F2H
Before: After:
BX BX
X XX 00 F2
X
PUSH – Pushes (sends, writes or moves) the content of a specified
register or memory location(s) onto the top of the stack.
Eg: PUSH AX
Before: After:
AX AX
10 20 10 20
Stack Location Stack Location
SP SP
20038 20036
20 20038
20038
20037 10
20037
20036 20036
POP – POP (reads) two bytes from the top of the stack and keeps them in a specified
register, or memory location (s)
Eg:
PUSH AX
Before: After:
AX AX
X XX 10 20
X Stack Location Stack Location
SP SP
20038 20036
20 20038
20 20038
10 20037
10 20037
20036
20036
XCHG − Used to exchange the data from two locations.
Eg: XCHG AX, BX
Before: After:
AX AX
10 AB FF 33
BX BX
FF 33 10 AB
XLAT − Used to translate a byte in AL using a table in the memory.
Instructions for input and output port transfer
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided
port.
Instructions to transfer the address
LEA − Used to load the effective address of operand into the provided register.
Eg:
LEA AX, [BX],[SI]
Load AX register with effective address of = [BX] + [SI]
LDS − Used to load DS register and other provided register from the memory
Eg:
LDS AX,[38B1H]
Copy the contents of memory at displacement of 38B1H and 38B2H to AX
Then copy the contents at displacement of 38B3H and 38B4H to DS
LES − Used to load ES register and other provided register from the memory.
Instructions to transfer flag registers
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
Arithmetic Instructions
These instructions are used to perform arithmetic operations like addition, subtraction,
multiplication, division, etc.
Following is the list of instructions under this group −
Instructions to perform addition
ADD − Used to add the provided byte to byte/word to word.
ADC − Used to add with carry.
INC − Used to increment the provided byte/word by 1.
AAA − Used to adjust ASCII after addition.
DAA − Used to adjust the decimal after the addition/subtraction operation.
Instructions to perform subtraction
SUB − Used to subtract the byte from byte/word from word.
SBB − Used to perform subtraction with borrow.
DEC − Used to decrement the provided byte/word by 1.
NPG − Used to negate each bit of the provided byte/word and add 1/2’s
complement.
CMP − Used to compare 2 provided byte/word.
AAS − Used to adjust ASCII codes after subtraction.
DAS − Used to adjust decimal after subtraction.
Instruction to perform multiplication
MUL − Used to multiply unsigned byte by byte/word by word.
IMUL − Used to multiply signed byte by byte/word by word.
AAM − Used to adjust ASCII codes after multiplication.
Instructions to perform division
DIV − Used to divide the unsigned word by byte or unsigned double word by
word.
IDIV − Used to divide the signed word by byte or signed double word by
word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of
the lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of the
lower word.
Bit Manipulation Instructions
These instructions are used to perform operations where data bits are involved, i.e. operations
like logical, shift, etc.
Following is the list of instructions under this group −
Instructions to perform logical operation
NOT − Used to invert each bit of a byte or word.
AND − Used for adding each bit in a byte/word with the corresponding bit in
another byte/word.
OR − Used to multiply each bit in a byte/word with the corresponding bit in
another byte/word.
XOR − Used to perform Exclusive-OR operation over each bit in a byte/word
with the corresponding bit in another byte/word.
TEST − Used to add operands to update flags, without affecting operands.
Instructions to perform shift operations
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in
LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old
MSB into the new MSB.
Instructions to perform rotate operations
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and
to Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB
and to Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and
CF to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and
CF to LSB.
String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.
Following is the list of instructions under this group −
REP − Used to repeat the given instruction till CX ≠ 0.
REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag
ZF = 1.
REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero
flag ZF = 1.
MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to
another.
COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the
provided memory location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the
provided memory location to the I/O port.
SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a
byte in AL or string word with a word in AX.
LODS/LODSB/LODSW − Used to store the string byte into AL or string
word into AX.
Program Execution Transfer Instructions (Branch and Loop
Instructions)
These instructions are used to transfer/branch the instructions during an execution. It includes
the following instructions −
Instructions to transfer the instruction during an execution without any condition −
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next instruction.
Instructions to transfer the instruction during an execution with some conditions −
JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
JAE/JNB − Used to jump if above/not below instruction satisfies.
JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
JC − Used to jump if carry flag CF = 1
JE/JZ − Used to jump if equal/zero flag ZF = 1
JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
JGE/JNL − Used to jump if greater than/equal/not less than instruction
satisfies.
JL/JNGE − Used to jump if less than/not greater than/equal instruction
satisfies.
JLE/JNG − Used to jump if less than/equal/if not greater than instruction
satisfies.
JNC − Used to jump if no carry flag (CF = 0)
JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
JNO − Used to jump if no overflow flag OF = 0
JNP/JPO − Used to jump if not parity/parity odd PF = 0
JNS − Used to jump if not sign SF = 0
JO − Used to jump if overflow flag OF = 1
JP/JPE − Used to jump if parity/parity even PF = 1
JS − Used to jump if sign flag SF = 1
Processor Control Instructions
These instructions are used to control the processor action by setting/resetting the flag values.
Following are the instructions under this group −
STC − Used to set carry flag CF to 1
CLC − Used to clear/reset carry flag CF to 0
CMC − Used to put complement at the state of carry flag CF.
STD − Used to set the direction flag DF to 1
CLD − Used to clear/reset the direction flag DF to 0
STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
Iteration Control Instructions
These instructions are used to execute the given instructions for number of times. Following
is the list of instructions under this group −
LOOP − Used to loop a group of instructions until the condition satisfies, i.e.,
CX = 0
LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1
& CX = 0
LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF
= 0 & CX = 0
JCXZ − Used to jump to the provided address if CX = 0
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service
specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program