MPMC Ii-Unit: Instruction Formats of 8086
MPMC Ii-Unit: Instruction Formats of 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 sic bytes.
a) 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 eight bits form an opcode and the operands are
implied.
For example:
This is an operation without any operand, which clear the carry flag bit.
Depending on the register (reg = RRR), the contents of the specified register will be
exchanged with the accumulator. This operation is having one operand which is specified
in a register.
Here the operand to this instruction is implicit and it take the contents of register AL.
b) Register to Register : This format is 2 bytes long. The first byte of the code specifies
the operation code and the width of the operand specifies by w bit. The second byte of the
opcode shows the register operands and RIM field.
D7 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
OP CODE d w 11 REG R/M
The register represented by the REG field is one of the operands. The RIM field specifies
another register or memory location, ie., the other operand. The register specified by
REG is a source operand if D 0 , else it is a destination operand.
For example:
MOV : data transfer operation from Register to Register.
Op-code is
100010dw 11REG
C) 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.
D7 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
OP CODE d w MOD REG R/M
The MOD field shows the MOD of addressing. In case of no displacement. MOD = 00
For example :
This format is similar to register to register transfer. The difference is in mod field.
When mod = 0 0, the r/m fields indicates the address to memory location.
The instruction
1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 indicates the instruction MOV AX, [BX]
In hexadecimal, the instruction is 8 AH O7 H
Here the data is present in a memory location in DS whose offset address is in BX. The
effective address of the data is given as 10H DS BX
This type of instruction format contains one or two additional bytes for displacement
along with 2-byte the format of the register to/from memory without displacement.
D7 D0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D0
In this format, the first byte as well as the 3 bites 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.
D7 D0 D7 D6 D5 D4 D3 D2 D1 D0
Op code w 11 op code R/M
D7 D0 D7 D0
Lower byte Higher byte
DATA DATA
When w 0 , the size of immediate data is 8 bits and the size of instruction is 3 bytes.
When w 1 , the size of immediate data is 16 bits and the size of instruction is 4 bytes.
D7 D0 D7 D6 D5 D4 D3 D2 D1 D0
Op code w MOD op code R/M
D7 D0 D7 D0 D7 D0
Higher byte of Lower byte of Higher byte of
displacement DATA DATA
The REG code of the different registers (either a source or destination operands) in the
opcode byte are assigned with binary code.
The different addressing modes of the 8086 instructions along with corresponding MOD,
REG and R/M field are given in the table.
The default segment for the addressing modes using BP and SP is SS. For all other
addressing modes the default segments are DS or ES.
Here 005OH is the immediate data and it is moved to register AX. The immediate data
may be 8-bit or 16-bit in size.
2. Direct : In the direct addressing mode, a 16 bit address (offset) is directly specified in
the instruction as a part of it.
ex. MOV AX [1 0 0 0 H]
Here data resides in a memory location in the data segment, whose effective address is
10 H DS 1000 H
3. Register : In register addressing mode, the data is stored in a register and it is referred
using the particular register. All the registers except IP may be used in this mode.
ex. MOV AX,BX
4. Register Indirect: In this addressing mode, the address of the memory location which
contains data or operand is determined in an indirect way using offset registers. The
offset address of data is in either BX or SI or DI register. The default segment register is
either DS or ES.
e.g. MOV AX, BX
The data is present in a memory location in DS whose offset is in BX. The effective
address is 10H DS BX
5. Indexed : In this addressing mode offset of the operand is stored in one of the index
register. DS and ES are the default segments for index registers SI and DI respectively
e.g. MOV AX, SI
6. Register Relative : In this addressing 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.
e.g. MOV AX, 50H BX
7. Based Indexed: In this addressing mode the effective address of the data is formed by
adding the content of a base register (any one of BX or BP) to the content of an index
register (any one of SI or DI). The default segment register may be ES or DS.
e.g MOV , BX SI
8. Relative Based Indexed : The effective address is formed by adding an 8-bit or 16-bit
displacement with the sum of contents of any one of the base register (BX or BP) and any
one of the index registers in a default segment.
e.g. MOV AX, 50H BX SI
9. Intrasegment Direct Mode: In this mode, the address to which the control is to be
transferred lies in the segment in which the control transfer instruction lies and appears
directly in the instruction as an immediate displacement value. The displacement is
computed relative to the content of the instruction pointer IP.
10. Intrasegment Indirect Mode: This mode is similar to intrasegment direct mode except
the displacement to which control is to be transferred is passed to the instruction
indirectly. Here the branch address is found as the content of a register or a memory
location.
11. Intersegment Direct Mode: In this mode, the address to which the control is to be
transferred is in a different segment. This addressing mode provides a means of
branching from one code segment to another code segment. Here, the CS and IP of the
destination address are specified directly in the instruction.
12. Intersegment Indirect Mode: This mode is similar to intersegment direct mode except
the address to which the control is to be transferred is passed to the instruction indirectly.
This information is kept in a memory block of 4 bytes: IP(LSB), IP(MSB), LS(LSR) and
CS(MSB) sequentially. The starting address of the memory block may be referred using
any of the addressing modes, except immediate mode.
a) Data Transfer Instruction: This type of instructions are used to transfer data from
source operand to destination operand. All the store, load, move, exchange, input and
output operations belong to this category.
d) Loop Instructions: The LOP, LOOPNZ and LOOPZ instructions belong to this
category. These are useful to implement different loop structures.
e) machine control Instructions: These instructions control the machine status. NOP,
HLT, WAIT and LOCK instructions belongs to this category.
f) Flag Manipulation Instructions: All instructions which directly affect the flag register
belong to this category. The instructions CLD, STD, CLI, STI etc. belong to this category.
g) Shift and Rotate Instructions: These instructions involve the bitwise shifting or rotation
in either direction with or without a count in CX.
h) String Instructions: These instruction involve string manipulation operations like load,
love, scan. Compare, store etc. These instructions are only to be operated upon the string.
Arithmatic operations
CMP: compare
NEG: Negative
Logical Instructions:
Logical Instructions:
LOOPZ label : Loop through a sequence of instructions from ‘Label’ while ZF 1 and
CX 0