Unit 2 MPMC
Unit 2 MPMC
unit-2 1
Addressing Modes Of 8086
Addressing modes:
The way the data or operand is
accessed by an instruction.
Categories of Addressing modes:
1. Data Addressing Modes
2. Program Memory Access Addressing Modes
3. Port Access Addressing Modes
unit-2 2
DATA ADDRESSING MODES
Data Addressing Modes
Data Addressing Modes explains the way the operands/Data are
Accessed by an instruction
Types of Data Addressing modes:
1. Immediate Addressing Mode
2. Register Addressing Mode
3. Direct Addressing Mode
4. Register Indirect Addressing Mode
5. Based Addressing mode
6. Indexed Addressing Mode
7. Based Indexed Addressing Mode
8. Relative Register Addressing Mode
9. Relative Based Indexed
unit-2
Addressing Modes 3
DATA ADDRESSING MODES
Immediate Addressing Mode:
The data is part of instruction itself and is available in successive
bytes of instruction code.
Example: MOV AX,0005H
Instruction
Datum
EA Datum
Register Displacement
EA Memory
Register + Datum
Address
unit-2 7
DATA ADDRESSING MODES
Relative Based Indexed Addressing Mode:
The address of the operand is formed by adding 8-bit or
16-bit displacement with the contents of any one of the
base registers( i.e. BX/BP) and index register (i.e.
SI/DI) in the default segments.
Example: MOV AX, 50[BX][SI]
Instruction
Base Index Displacement
Register
Memory Index + Datum
Register
Base
unit-2 8
Program Memory Access Addressing Modes
The Program memory access addressing modes explains about
the transfer of control to some other location which is not in
sequence hence is applicable to control transfer instructions and is
sometimes known as Control Transfer Addressing Modes.
The control transfer instructions, the addressing modes depend
upon whether the destination location is within the same segment
or in different segment. It also depends upon the method of
passing the destination address to the processor .
The various control transfer addressing modes are:
1. Intra-segment Direct
2. Intra-segment Indirect
3. Inter-segment Direct
4. Inter-segment Indirect
unit-2 9
Program Memory Access Addressing Modes
Intra-Segment Direct Addressing Mode:
the address to which the control is to be transferred lies in the same
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 contents of IP. The EA is sum of 8-bit or 16-bit
displacement and current contents of the IP.
Instruction
EA
Displacement
+
IP
The effective address to which the control will be transferred is given by the
sum of 8 or 16-bit displacement and current contents of IP.In case of jump
instruction, if the signed displacement (d) is of 8-bits(i.e.,-128<d<+127), we
term it as Short jump and if it is of 16-bits(i.e., -32768<d<+32767), it is
termed as Long jump.
Example : JMP SHORT Label
unit-2 10
Program Memory Access Addressing Modes
Intra-Segment Indirect Addressing Mode:
The displacement to which the control is to be transferred is in the
same segment in which the control is transfer instruction lies but it
is passed to the instruction indirectly. The branch address is found
as the content of a register or a memory location.This addressing
mode is used in unconditional branch instructions.
Example: JMP [BX]
Register
Effective
Instruction EA Branch Address
Compta-
Addressing tion
Mode Memory
Effective
Branch Address
unit-2 11
Program Memory Access Addressing Modes
Inter-segment Direct Addressing 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
Example: JMP 5000H:2000H
[CS]:5000H,[IP]:2000H
Inter-segment Indirect Addressing Mode:
In this mode, the address to which the control is to be transferred lies
in a different segment and it is passed to the instruction
indirectly,i.e.,contents of a memory block containing four bytes,
i.e.,IP(LSB),IP(MSB),CS(LSB), CS(MSB) sequentially. The starting
address of the memory block may be referred using any of the
addressing modes,except immediate addressing mode.
Example: JMP [2000H]
[IP]=[DS:2001H,DS:2000H],[CS]=[DS:2004H,DS:2003H]
unit-2 12
PORT ADDRESSING MODES
Port addressing modes explains about how the
I/O ports are accessed by the program.
Port addressing modes are of two types:
1. Direct I/O Port addressing mode
2. Indirect I/O Port addressing mode
Direct Port addressing mode:
o Used to access data from standard I/O mapped
devices or ports.
o An 8-bit port address is directly specified in the
instruction.
o Example: IN AL,[09H]
unit-2 13
PORT ADDRESSING MODES
Indirect Port addressing Mode:
o Used to access data from standard I/O mapped devices
or ports .
o The name of the register which holds the port address
is specified in the instruction.
o In 8086, the 16-bit port address is stored in DX register.
o Example: OUT [DX],AX
unit-2 14
STRING ADDRESSING MODE
This addressing mode is employed in string instructions to operate on
string data .In string addressing mode the effective address (EA) of
source data is stored in SI register and the EA of destination data is
stored in DI register.
The segment register used for calculating base address for source data
is DS register and can be overridden. The segment register used for
calculating base address for destination data is ES register and cannot
be overridden.
The addressing mode also supports auto increment/decrement of index
registers SI and DI depending on direction flag (DF).
If DF= 1 then the contents of index registers are decremented to point to
the next byte/word of the string after execution of a string instructions.
If DF = 0 , then the contents of index registers are incremented to point
to next byte/word.
Example: MOVSB (move string byte)
EA=[SI],BA= [DS]X1610 , MA (memory Address) = EA + BA.
EAE = [DI],BAE = [ES] X 1610 , MAE = EAE + BAE.
[MAE] [MA] ; If DF = 1 [SI] = [SI] -1, [DI] = [DI] – 1;
If DF = 0unit-2
[SI] = [SI] +1, [DI] = [DI] + 1; 15
RELATIVE ADDRESSING MODE
In this addressing mode the effective address of a
program instruction is specified relative to instruction
pointer (IP) by an 8-bit signed displacement.
Example: JZ 0AH
0AH is sign extended to 000AH.
If ZF = 1 then (IP) = (IP)+000AH;
EA = (IP) + 000AH
BA = (CS) X 16 10
MA = BA + EA.
unit-2 16
IMPLIED ADDRESSING MODE
In implied addressing mode, the instruction itself will
specify the data to be operated by the instruction.
Example: CLC (clear carry flag)
CF 0
unit-2 17
Instruction Formats Of 8086
A machine language format has one or more number of fields
associated with it.
The first field is called as operation code(Opcode) field,
which indicates the type of the operation to be performed by
the CPU.
The instruction format also contains other fields known as
Operand(data) fields. The CPU executes the instruction using
the information which resides in these 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.
The instruction formats are also known as instruction
templates.
18
Instruction Formats
One Byte Instruction Format:
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.
7 0 7 0
Opcode or Opcode W
7 0 7 32 0
or
Opcode Z Opcode Reg.
19
Instruction Formats
Two Byte Instruction:
Used for Register to register and register to/from memory with no
displacement.
This format is 2 byte long
The first byte of the code specifies the operation code and the width of
the operand specified by W bit.
The second byte of the code shows the register operands and R/M
field.
The register specified by Reg. field is one operand and the R/M field
specifies another register or memory location i.e., the other operand.
The mod field will be specifying the addressing mode of the operand.
7 2 1 0 7 6 5 3 2 0
opcode D W Mod Reg. R/M
(or)
7 opcode2 1 V 0 W 6 5 Reg.
7 Mod 3 2 R/M0
20
Instruction Formats
Three Byte Instruction:
Used for register to/from memory with 8-bit displacement or 8-bit
immediate data.
This format is 3 byte long
The first two bytes are similar to the two byte instruction format, and
have all the fields of two bytes same.
7 2 1 0 7 6 5 3 2 0 7
0
opcode D W Mod Reg. R/M Disp-8
(or)
7 opcode D W2 1 0 Mod 7Reg.6 5 R/M3 2 0 Data-8
7
0
21
Instruction Formats
Four Byte Instruction:
Used for register to/from memory with 16-bit displacement and also
for 16-bit immediate data to Register/Memory .
This format is 4 byte long
The format of instruction for register to/from memory with 16-bit
displacement, there will be two bytes of displacement along with the
first two bytes similar to two byte instruction,its format is as shown
below:
7 2 1 0 7 6 5 3 2 0 7
0
opcode D W Mod Reg. R/M Disp. Lower Byte
22
Instruction Formats
Four Byte Instruction:
The format of instruction for moving 16-bit immediate data to
register/memory will have the first byte as well as the 3-bits of second
byte which were used for Reg. field by two byte instruction as opcode
fields.
The following bytes i.e., third and fourth bytes as 16-bit immediate
data.
The format of instruction for moving 16-bit immediate data to
register/memory will have the following template.
7 2 1 0 7 6 5 3 2 0 7
0
opcode D W Mod Reg. R/M Data Lower Byte
23
Instruction Formats
Five Byte Instruction:
Used for moving immediate 8-bit data to memory with 16-bit displacement.
This is five byte long template.
The format of instruction will have the first byte as well as the 3-bits of
second byte which were used for Reg. field by two byte instruction as
opcode fields.
The next two bytes will be the 16-bit displacement bytes.
The last byte is an 8-bit data.
The format of the template is:
7 2 1 0 7 6 5 3 2 0 7
0
opcode D W Mod Reg. R/M Disp. Lower Byte
7 0 7 0
Disp. Higher Byte Data Byte
24
Instruction Formats
Six Byte Instruction:
Used for moving immediate 16-bit data to memory with 16-bit displacement.
This is six byte long template.
The format of instruction will have the first byte as well as the 3-bits of
second byte which were used for Reg. field by two byte instruction as
opcode fields.
The next two bytes will be the 16-bit displacement bytes.
The next two bytes is 16-bit data.
The format of the template is:
7 2 1 0 7 6 5 3 2 0 7
opcode 0 W
D Mod Reg. R/M Disp. Lower Byte
27
Instruction Formats
Codes for Mod field
28
Instruction Formats
Codes for Segment Registers
Usually all the addressing modes have DS as default segment, but the
instructions/Addressing modes using SP and BP for Effective Address
calculation use Stack segment as default segment.
29
Instruction Formats
Codes for Reg. field
000 AL AX
001 CL CX
010 DL DX
011 BL BX
100 AH SP
101 CH BP
110 DH SI
111 BH DI
30
Instruction Formats
Codes for R/M field
instruction set 33
Data transfer instructions
• The Source and Destination operand should be of same
size i.e. both the operands should be either 8-bits (byte)
or 16-bit (word).
• Only 8-bit word can be moved to a 8-bit register/memory
or a 16-bit word can be moved to 16-bit register/memory.
• Moving the contents of 8-bit register to 16-bit register/
memory or vice-versa is illegal.
• The Source can be a register or a memory location or an
immediate data.
• The destination can be a register or a memory location.
• In double operand instructions the source and destination
cannot refer to memory locations in the same instruction.
instruction set 34
Data transfer instructions
• Copying the contents of one memory location to
another memory location in a single instruction is not
possible (except push instruction).
• The data transfer instructions (except POPF & SAHF
instructions) do not affect any flags of 8086.
• While executing the POPF instruction, the previously
stored status of flag is restored in the flag register.
• The instruction SAHF is used to modify the content of
flag register.
• For XCHG instruction, at least one of the operands
must be a register, but neither operand can be a
segment register.
instruction set 35
Data transfer instructions
• General purpose byte or word transfer instructions:
1) MOV
2) PUSH
3) POP
4) XCHG
5) XLAT
• MOV: Copy byte or word from specified source to specified
destination.
Format: MOV <dest>, <source>
Operation: (dest) (source)
Examples: MOV Reg2, Reg1
MOV AL, Mem
MOV Seg reg, Mem
instruction set 36
Data transfer instructions
General purpose byte or word transfer instructions
• PUSH: Copy specified word to top of the stack
Format: PUSH < source >
Operation: (SP) (SP) – 2
(PA)stack = (SS) X 1610 + (SP)
(PA; PA+1) source
The stack point is decremented by 2 and the contents
of the source are transferred to stack memory
pointed by stack pointer
Examples: PUSH Reg16
PUSH Mem
PUSH Seg reg
instruction set 37
Data transfer instructions
General purpose byte or word transfer instructions
• POP: Copy word from top of the stack to specified
location
Format: POP < destination >
Operation: (PA) = (SS) X 1610 + (SP)
destination (PA; PA+1)
(SP) (SP) + 2
instruction set 39
Data transfer instructions
General purpose byte or word transfer instructions
• XLAT: Translate a byte in AL, using a table in memory
Format: XLAT
Operation: PA = DS X 1610 + (BX) + (AL)
(AL) (PA)
This instruction is used to translate a byte from one code to
another code
The instruction replaces a byte in the AL register with a byte
pointed to by BX register in a look up table in memory
Before executing XLAT instruction, the look up table is to be put
into memory and the starting address of the look up table has to
be loaded into BX register
Examples: ASCII value of 0-9 is 30-39 and EBCDIC is 0-9.
Hence to convert EBCDIC code in ASCII, the ASCII values of the
0-9 has to be stored say from 2000H, then save 2000H in BX.
instruction set 40
Data transfer instructions
Simple input and output port transfer instructions
IN & OUT
• IN : Copy a byte or word from specified port to
accumulator.
Format : IN <Accumulator>, <Source>
Example : IN AL/AX,[DX]
(AL/AX) ( Port)
the contents of 8-bit port whose address is specified
by DX register is transferred to 8-bit accumulator
(AL/AX)
IN AL/AX, addr8
(AL/AX) (addr8)
The contents of 8-bit port whose address is given in the
instruction is transferred to accumulator (AL/AX)
instruction set 41
Data transfer instructions
Simple input and output port transfer instructions
instruction set 42
Data transfer instructions
Special Address transfer instructions
instruction set 43
Data transfer instructions
Special Address transfer instructions
• LDS : Load DS register and the other specified register from
memory.
LDS Reg16,Mem
(Reg16) (Mem)
(DS) (Mem+2)
Copies a word from two memory locations into the register specified
in the instruction,it then copies a word from the next two memory
locations into the DS register.
• LES : Load ES register and the other specified register from
memory.
LES Reg16,Mem
(Reg16) (Mem)
(ES) (Mem+2)
Copies a word from two memory locations into the register specified
in the instruction,it then copies a word from the next two memory
locations into the ES register.
instruction set 44
Data transfer instructions
Flag Transfer instructions
instruction set 45
Data transfer instructions
Flag Transfer instructions
• PUSHF: Push (copy) the flag register to the top of the stack.
(sp) (sp)-2
MAs = (ss) X 1610 + (sp)
(MAs; MAs + 1) (flags)
the stack pointer is decremented by two and the contents of the
16-bit flag register is pushed to stack memory to pointed by the
SP.
• POPF:
MAs = (ss) X 1610 + (sp)
(flags) (MAs; MAs + 1)
(sp) (sp) + 2
The contents of (16-bit) stack memory pointed by the SP is
moved to flag register and the stack pointer is incremented by 2.
instruction set 46
ARITHMETIC INSTRUCTIONS
• The Arithmetic instructions can be classified into following
categories
1. Addition instructions
2. Subtraction instructions
3. Multiplication instructions
4. Division instructions
• The arithmetic operands involve two operands i.e., source and
destination.
• The result of the arithmetic operations is stored in destination
register or memory location except in the case of comparison. (in
comparison the result is used only to update the flags and then it
is discarded).
• Performing arithmetic operations directly on two operands in two
memory locations is not possible.
• In immediate addressing mode arithmetic operations is the
data/operand is not matching with the size of register then the
operation will be performed on sign extended data.
instruction set 47
ARITHMETIC INSTRUCTIONS
Addition instructions
• The arithmetic instructions alter the flags, the result is used to
update the flags.
Addition instruction
ADD,ADC,INC,AAA,DAA
ADD: Add
ADD Reg1,Reg2 Reg1 = Reg1. + Reg2.
the contents of two registers or a immediate data to register
or contents of one memory location to a register contents
are added.
The ADD instruction affects all conditional flags depending
on the result of operation.
Example: ADD AX,BX
instruction set 48
ARITHMETIC INSTRUCTIONS
Addition instructions
ADC: Add with carry
ADC Reg1. ,Reg2 Reg1 + Reg2 + [CY]
the contents of two registers or a immediate data to register or
contents of one memory location to a register contents along with
carry flag contents are added.
The ADC instruction affects all conditional flags depending on
the result of operation.
Example: ADC AX,BX
INC : Increment
INC <source>
This instruction increases the contents of the specified register or
memory location i.e., source by 1.
This instruction affects all conditional flags except the carry flag.
This instruction adds 1 to the contents of the operand.
Immediate data cannot be operand of this instruction.
Example: INC BX
INC [5000H]
instruction set 49
ARITHMETIC INSTRUCTIONS
Addition instructions
AAA : ASCII Adjust after Addition
The AAA instruction is executed after an ADD instruction that adds
two ASCII coded operands to give a byte of result in AL. The AAA
instruction converts the resulting contents of AL to unpacked decimal
digits.
After the addition the AAA instruction examines the lower 4-bits of AL
to check whether it contains a valid BCD between 0 to 9.
instruction set 51
ARITHMETIC INSTRUCTIONS
Addition instructions
DAA : Decimal adjust Accumulator
This instruction is used to convert the result of the addition of
two packed numbers to a valid BCD number,but the result
has to be only in AL.
If the lower nibble is greater than 9, after addition or if AF is
set, it will add 06H to the lower nibble in AL. After adding 06
in the lower nibble of AL is greater than 9 or if carry flag is
set, DAA instruction adds 60H to AL.
The DAA instruction affects AF,CF,PF and ZF flags. The OF
is undefined.
Example: AL = 53, CL = 29
ADD AL,CL ; AL <- (AL) + (CL)
AL = 53 + 29 = 7C H
After DAA AL <- 7C + 06 H
AL = 82
instruction set 52
ARITHMETIC INSTRUCTIONS
Addition instructions
Example:
AL = 73 and CL = 29
ADD AL,CL
AL <- AL + CL
AL <- 73 + 29
AL <- 9C H
DAA
AL <- 02 and CF = 1
AL 73
CL + 29
9C
+ 06
A2
+ 60
CF = 1 02 in AL
instruction set 53
ARITHMETIC INSTRUCTIONS
Subtraction instructions
Subtraction instructions:
SUB, SBB, DEC, NEG, CMP, AAS, DAS
o SUB : subtraction
SUB X,Y
X = X – Y, X destination, Y - source
This instruction subtracts the source operand from the
destination operand and the result is stored in destination.
the source operand may be a register or a memory location
or an immediate data and the destination operand may be a
register or a memory location, but source and destination
operand both must not be memory operands.The destination
operand cannot be an immediate data.
All the conditional flags are affected by SUB instruction.
Example: SUB BX,DX
instruction set 54
ARITHMETIC INSTRUCTIONS
Subtraction instructions
o SBB : Subtract with Borrow
SBB X,Y
X = X – Y – BW(CY) X destination, Y Source,
BW Borrow i.e., Carry flag contents.
DEC <Destination>
All the conditional flags except the carry flag are affected
depending upon the result
Example : DEC AX
instruction set 56
ARITHMETIC INSTRUCTIONS
Subtraction instructions
o NEG : Negate
NEG Mem./Reg.
The negate instruction forms 2’s complement of the
specified destination in the instruction.
For obtaining 2’s complement,it subtracts the contents of
destination from 0(zero).
The result is stored back in the destination operand which
may be a register or a memory location.
Using NEG instruction if the OF flag is set, it will indicate that
the operation was not successfully completed.
The NEG instruction affects all conditional flags.
Example:NEG BX
instruction set 57
ARITHMETIC INSTRUCTIONS
Subtraction instructions
o CMP :Compare
CMP X,Y ; X Destination, Y Source
instruction set 58
ARITHMETIC INSTRUCTIONS
Subtraction instructions
instruction set 59
ARITHMETIC INSTRUCTIONS
Subtraction instructions
instruction set 60
ARITHMETIC INSTRUCTIONS
Subtraction instructions
• Example:
• (1) AL = 75, BL = 46
SUB AL,BL ; AL 2F = (AL) – (BL)
; AF = 1
DAS ; AL 29 ( as F > 9, F-6 = 9)
(2) AL = 38 , DL = 61
SUB AL , DL ; AL D7 & CF = 1(borrow)
DAS ; AL 77 (as D > 9 , D-6 = 7)
; CF = 1 (borrow)
instruction set 61
ARITHMETIC INSTRUCTIONS
Multiplication instructions
Multiplication instructions:
MUL, IMUL, AAM
o MUL : Unsigned Multiplication of byte or word.
MUL Reg. / Mem.
This instruction multiplies an unsigned byte or word by the contents
of AL.
The Unsigned byte or word may be in any one of the general
purpose registers or memory locations.
For Byte multiplication the most significant byte will be stored in AH
register and least significant byte is stored in AL register.
For Word multiplication the most significant word of the result is
stored in DX, while the least significant word of the result is stored
in AX register
All the flags are modified depending upon the result of the
operation.
Immediate operand is not allowed in this instruction.
If the most significant byte or word of result is ‘0’ CF and OF both
will be set.
Example: MUL BL
instruction set 62
MUL BX
ARITHMETIC INSTRUCTIONS
Multiplication instructions
IMUL : Signed Multiplication.
This instruction multiplies a signed byte in source operand by a
signed byte in AL register or A signed word in AX register.
The source can be a general purpose register, memory
operand,index register or base register, but it cannot be an
immediate data.
While using this instruction the content of accumulator and
register should be sign extended binary in 2’s complement form
and the result is also in sign extended binary.
In case of 32-bit results, the higher order word(MSW) is stored in
DX and lower order word is stored in AX
In case of 16-bit result it will be stored in AX register.
The AF, PF, SF, and ZF flags are undefined after IMUL instruction
execution.
If AH and DX contains parts of 16-bit and 32-bit result
respectively, CF and OF both will be set.
The AL and AX are the implicit operands in case of 8 –bits and
16-bits multiplication respectively.
The unsigned higher bits of the result are filled by sign bit and
CF,AF are cleared.
Example: IMUL BL / IMUL instruction
BX set 63
ARITHMETIC INSTRUCTIONS
Multiplication instructions
AAM : ASCII Adjust after Multiplication
This instruction after execution, converts the product available
in AL into unpacked BCD format.
The AAM instruction follows a multiplication instruction that
multiplies two unpacked BCD operands, i.e., higher nibbles of
the multiplication operands should be ‘0’.The multiplication of
such operands is carried out using MUL instruction.
The result of the multiplication will be available in AX.
(AH) = (AL) 0A H
(AL) = (AL) MOD 0A H
The AAM instruction replaces the contents of AH by tens of
decimal multiplication and AL by singles of the decimal
multiplication.
MOV AL, 04 ; AL 04
MOV BL, 09 ; BL 09
MUL BL; AH:AL 24 H (9 X 4)
AAM ; AH 03
; AL 06
instruction set 64
ARITHMETIC INSTRUCTIONS
Division instructions
Division instructions: DIV, IDIV, AAD, CBW, CWD
o DIV : Unsigned division
DIV <reg./Mem>
This instruction performs unsigned division. It divides an
unsigned word or double word by a 16-bit or 8-bit operand.
The dividend must be in AX for 16-bit operation and the
divisor may be specified using any one of the addressing
modes except immediate.
The dividend for 32-bit operation will be in DX:AX register
pair (Most significant word in DX and least significant word in
AX).
All the flags are undefined for DIV instruction.
The result of division is for 16-bit number divided by 8-bit
number the Quotient will be in AL register and the remainder
will be in AH register similarly for 32-bit number divided by
16-bit number the Quotient will be in AX register and the
remainder will be in DX register.
If the result is too big to fit into AL or AX register then Type-0
(divide by zero) interrupt is generated and the ISR for the
Type zero will be executed such that correction steps are
taken to accommodateinstruction
the result.
set 65
ARITHMETIC INSTRUCTIONS
Division instructions
instruction set 66
ARITHMETIC INSTRUCTIONS
Division instructions
o IDIV : signed division
IDIV <reg./Mem>
This instruction performs signed division. It divides an signed word or
double word by a signed 16-bit or 8-bit operand.
While using IDIV instruction the contents of accumulator and register
should be sign extended binary.
The signed dividend must be in AX for 16-bit operation and the signed
divisor may be specified using any one of the addressing modes
except immediate.
The signed dividend for 32-bit operation will be in DX:AX register pair
(Most significant word in DX and least significant word in AX).
All the flags are undefined for IDIV instruction.
The sign of the quotient depends on the sign of dividend and divisor.
The sign of remainder will be same as that of dividend.
The result of division of signed division is also stored in the same way
as the result of unsigned division but the sign of the quotient and
remainder depends on the sign of dividend and divisor.
If the result is too big to fit into AL or AX register then Type-0 (divide by
zero) interrupt is generated and the ISR for the Type zero will be
executed such that correction steps are taken to accommodate the
instruction set 67
result.
ARITHMETIC INSTRUCTIONS
Division instructions
instruction set 68
ARITHMETIC INSTRUCTIONS
Division instructions
instruction set 69
ARITHMETIC INSTRUCTIONS
Division instructions
instruction set 70
Bit Manipulation Instructions
The Logical group includes instructions for performing AND, OR,
EX-OR, complement, shift and rotate operations on binary data.
The mnemonics used for logical instructions are AND, OR, XOR,
TEST etc……….
The Logical instructions except shift and rotate involve two
operands i.e., source and destination operand.
The source operand can be a register or memory location or
immediate data.
The destination operand can be a register or memory location.
The result of the logical operation is stored in destination register
or memory except in the case of TEST instruction , for which the
result is used only to modify the flags and then the result is
discarded.
In double operand logical instructions, both the source and
destination cannot refer to memory locations in the same
instruction . Thus performing logical operation on two memory
bytes or words simultaneously is not possible.
In double operand logical instructions, the source and destination
operand should be of same size, either both the operand size
should be byte or word.
instruction set 71
Bit Manipulation Instructions
The Logical instructions alter the flags of 8086.
The processor uses the result of logical operations to alter the
flags which reflect the status of the result.
instruction set 72
Bit Manipulation Instructions
Logical Instructions
NOT : Complement / Negation (Invert each bit of operand)
NOT < Destination>
The NOT instruction inverts each bit (forms the 1’s complement)
of the byte or word at the specified destination.
The destination can be a register or a memory location specified
by any one of the addressing mode except for immediate
addressing mode.
No flags are affected by the NOT instruction.
Example: NOT AL
NOT [AX]
instruction set 73
Bit Manipulation Instructions
Logical Instructions
AND : Logical AND of corresponding bits of two operands
AND <Destination> , <Source>
This instruction ANDs each bit in a source byte or word (which might
be a register or a memory location or an immediate data) with the
same number bit in a destination (which might be a register or a
memory location) byte or word.
The result is stored in destination operand. At least one of the
operands should be a register or an memory location , but both the
operands cannot be memory locations or immediate operands and
also immediate operand cannot be a destination operand.
The AND operation gives output 1 only when both the inputs are high.
AND AX , 0008H (let [AX] = 4567H
4567 = 0100 0101 0110 0111 ; 0008 = 0000 0000 0000 1000
4567 AND 0008 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1
AND
00 00 00 00 0 000 10 00
00 00 00 00 0 000 10 00=
0008H instruction set 74
Bit Manipulation Instructions
Logical Instructions
OR : Logical OR of corresponding bits of two operands
OR <Destination> , <Source>
This instruction ORs each bit in a source byte or word (which might be
a register or a memory location or an immediate data) with the same
number bit in a destination (which might be a register or a memory
location) byte or word.
The result is stored in destination operand. At least one of the
operands should be a register or an memory location , but both the
operands cannot be memory locations or immediate operands and
also immediate operand cannot be a destination operand.
The OR operation gives output 1 when any one of the inputs are high.
OR AX , 0008H (let [AX] = 4567H
4567 = 0100 0101 0110 0111 ; 0008 = 0000 0000 0000 1000
4567 OR 0008 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1
OR
00 00 0000 000 0 1000
01 00 01 01 0110 1 1 1 1 = 456F
H instruction set 75
Bit Manipulation Instructions
Logical Instructions
XOR : Logical XOR of corresponding bits of two operands
XOR <Destination> , <Source>
This instruction XORs each bit in a source byte or word (which might be
a register or a memory location or an immediate data) with the same
number bit in a destination (which might be a register or a memory
location) byte or word.
The result is stored in destination operand. At least one of the operands
should be a register or an memory location , but both the operands
cannot be memory locations or immediate operands and also immediate
operand cannot be a destination operand.
The XOR operation gives output 1 only when both the inputs are
dissimilar.
XOR AX , 0018H (let [AX] = 4567H
4567 = 0100 0101 0110 0111 ; 0008 = 0000 0000 0000 1000
4567 XOR 0018 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1
XOR
00 00 0000 000 1 1000
01 00 01 01 0111 1 1 1 1 = 457F H
instruction set 76
Bit Manipulation Instructions
Logical Instructions
TEST : Logical Compare instruction( AND operands to update flags)
TEST <Destination> , <Source>
This instruction performs a bit by bit logical AND operation on two
operands.
The source and destination operands are not altered they simply
update the flags.
The result of the ANDing operation is not available for further use,but
flags are affected.The affected flags are OF, CF,SF,ZF and PF.
The TEST instruction is often used to set flags before a conditional
jump instruction.
The source operand can be a register or a memory location or
immediate data.
The destination operand can be either a register or a memory
location .
But both source and destination cannot be memory location.
CF and OF are both 0’s after TEST instruction execution.
AF will be undefined for TEST instruction.
instruction set 77
Bit Manipulation Instructions
Shift Instructions
Shift instructions
SHL / SAL, SHR, SAR
SHL / SAL : Shift Logical / Arithmetic Left
SHL <reg. / Mem>
CF R(MSB) ; R(n+1) R(n) ; R(LSD) 0
CF MSD 0
These instructions shift the operand word or byte bit by bit to the
left and insert zeros in the newly introduced least significant bits.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be
in CL register.
The operand to be shifted can be either register or memory
location contents but cannot be immediate data.
All the flags are affected depending upon the result.The shift
operation will considering using carry flag.
instruction set 78
Bit Manipulation Instructions
Shift Instructions
SHR : Shift Logical Right
SHR <reg. / Mem>
CF R(LSB) ; R(n) R(n+1) ; R(MSD) 0
0 MSD LSD CF
These instructions shift the operand word or byte bit by bit to the
right and insert zeros in the newly introduced Most significant
bits.
The result of the shift operation will be stored in the register
itself.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be
in CL register.
The operand to be shifted can be either register or memory
location contents but cannot be immediate data.
All the flags are affected depending upon the result.The shift
operation will considering using carry flag.
instruction set 79
Bit Manipulation Instructions
Shift Instructions
SAR : Shift Logical Right
SAR <reg. / Mem> , <count>
CF R(LSB) ; R(n) R(n+1) ; R(MSD) R(MSD)
MSD LSD CF
These instructions shift the operand word or byte bit by bit to the
right.
SAR instruction inserts the most significant bit of the operand in the
newly inserted bit positions.
The result will be stored in the register or memory itself.
The number of bits to be shifted if 1 will be specified in the
instruction itself if the count is more than 1 then the count will be in
CL register.
The operand to be shifted can be either register or memory location
contents but cannot be immediate data.
All the flags are affected depending upon the result.The shift
operation will considering using carrysetflag.
instruction 80
Bit Manipulation Instructions
Rotate Instructions
Rotate instructions
ROL, RCL, ROR, RCR
ROL : Rotate left without carry
ROL <Reg. / Mem> , <Count>
R(n+1) R(n) ; CF R(MSB) ; R(LSB) R(MSB)
MSB LSB
CF
This instruction rotates all the bits in a specified word or byte to the left
by the specified count (bit-wise) excluding carry.
The MSB is pushed into the carry flag as well as into LSB at each
operation. The remaining bits are shifted left subsequently by the
specified count positions.
The PF, SF, and ZF flags are left unchanged in this rotate operation .
The operand can be a register or a memory location.
The count will be in instruction if it is 1, and in CL register if greater than
1. instruction set 81
Bit Manipulation Instructions
Rotate Instructions
RCL : Rotate left through i.e., with carry
RCL <Reg. / Mem> , <Count>
R(n+1) R(n) ; CF R(MSB) ; R(LSB) CF
MSB LSB
CF
This instruction rotates all the bits in a specified word or byte to the left
by the specified count (bit-wise) including carry.
The MSB is pushed into the CF and CF into LSB at each operation.
The remaining bits are shifted left subsequently by the specified count
positions.
The PF, SF, and ZF flags are left unchanged in this rotate operation .
The operand can be a register or a memory location.
The count will be in instruction if it is 1, and in CL register if greater
than 1.
instruction set 82
Bit Manipulation Instructions
Rotate Instructions
This instruction rotates all the bits in a specified word or byte to the right
by the specified count (bit-wise) excluding carry.
The LSB is pushed into the carry flag as well as the MSB at each
operation. The remaining bits are shifted right subsequently by the
specified count positions.
The PF, SF, and ZF flags are left unchanged in this rotate operation .
The operand can be a register or a memory location.
The count will be in instruction if it is 1, and in CL register if greater than
1. instruction set 83
Bit Manipulation Instructions
Rotate Instructions
This instruction rotates all the bits in a specified word or byte to the right
by the specified count (bit-wise) excluding carry.
The LSB is pushed into the carry flag as well as the MSB at each
operation. The remaining bits are shifted right subsequently by the
specified count positions.
The PF, SF, and ZF flags are left unchanged in this rotate operation .
The operand can be a register or a memory location.
The count will be in instruction if it is 1, and in CL register if greater than
1. instruction set 84
String Instructions
A string is a sequence of bytes or words i.e., a series of data bytes
or words available in memory at consecutive locations, to be
referred to collectively or individually and is known as byte strings
or word strings.
For referring to a string, two parameters are required,
Starting or end address of the string.
Length of the string.
The length of the string is usually stored as count in the CX register.
In case of 8085, the strings are referred by using pointers and
counter arrangement which are modified at each iteration, till the
required condition for proceeding further is satisfied.
But in the case of 8086, a set of instructions are used for
manipulating the string bytes or words and the index registers are
used as pointers for the source and destination strings (SI and DI
respectively). The pointers are updated i.e., incrementing and
decrementing of the pointers depending on the status of the DF
flag.
If the pointers are byte pointers then they are updated by one. On
the other hand, if it is a word string operation, the index registers
are updated by two. The counter is decremented by one for both
byte and word strings.
instruction set 85
String Instructions
The 8086 instruction set includes instructions for string movement,
comparison, scanning, loading and storing.
Generally the string instructions have prefix for repeating the execution of
string instructions till the condition is satisfied.
The string instructions end with “S” or “SB” or “SW” , where “S” represents
string, “SB” represents string byte, “SW” represents string word.
All the string instructions has implied source and destination operand (i.e.,
the operands are not specified as a part of the instruction).
The string instructions MOVS and CMPS assume that the source operand
is in data segment memory, and the destination is in extra segment
memory.
The string instructions STOS and SCANS assumes that the source
operand is in accumulator, and the destination is in extra segment
memory.
The string instruction LODS assumes that the source operand is in data
segment memory and the destination is accumulator.
For string operations, the offset or the effective address of the source
operand is stored in SI register and that of destination operand is stored in
DI register.
On execution of string instruction depending on DF, SI and DI registers
are automatically updated to point to the next byte / word of the source
and destination.If DF = 0 SI and DI are incremented by 1 and if DF = 1
then SI and DI are decremented instruction
by 1. set 86
String Instructions
The string instructions are categorized as
1. Prefix instructions
2. String data manipulation instructions
instruction set 87
String Instructions
Prefix instructions
REP : Repeat instruction Prefix
The instruction with REP prefix will be executed repeatedly until
the CX register becomes zero( for each iteration CX is
automatically decremented by one).
When CX becomes zero , the execution proceeds to the next
instruction in the sequence.
REPE / REPZ : Repeat when equal or till ZF = 1.
The instruction with REPE / REPZ prefix will be repeated if CX
0 and ZF =1 ( for each iteration CX is automatically decremented
by 1).
The repeat operation is terminated if CX = 0 or ZF = 0.
REPNE / REPNZ : Repeat when not equal or till ZF = 0.
The instruction with REPNE / REPNZ prefix will be repeated if
CX 0 and ZF =0 ( for each iteration CX is automatically
decremented by 1).
The repeat operation is terminated if CX = 0 or ZF = 1.
instruction set 88
String Instructions
String data byte/word manipulation instructions
MOVS / MOVSB / MOVSW: Move string byte or word
One byte or word of a string data stored in data segment is copied
into extra segment.
The SI register points to the source string and DI register points to
the destination string.
The CX register is decremented by one for each byte / word
movement.
The SI and DI registers are automatically incremented or
decremented depending on the status of DF.
MA = (DS) X 1610 + (SI)
MAE = (ES) X 1610 + (DI)
(MAE) (MA)
For byte operation
If DF = 0, then (DI) (DI) + 1 ; (SI) (SI) + 1
If DF = 1, then (DI) (DI) - 1 ; (SI) (SI) – 1
For word operation
If DF = 0, then (DI) (DI) + 2 ; (SI) (SI) + 2
If DF = 1, then (DI) (DI)instruction
- 2 ; (SI)set (SI) - 2 89
String Instructions
String data byte/word manipulation instructions
CMPS / CMPSB / CMPSW: Compare string byte or word
Compare one byte or word of a string data stored in data
segment with that stored in extra segment.
The SI register points to the source string and DI register points
to the destination string.
The CX register is decremented by one for each byte / word
movement.
The SI and DI registers are automatically incremented or
decremented depending on the status of DF.
MA = (DS) X 1610 + (SI)
MAE = (ES) X 1610 + (DI)
Modify flags (MA) - (MAE)
If (MA) > (MAE) then CF = 0 ; ZF = 0 ; SF = 0
If (MA) < (MAE) then CF = 1 ; ZF = 0 ; SF = 1
If (MA) = (MAE) then CF = 0 ; ZF = 1 ; SF = 0
instruction set 90
String Instructions
String data byte/word manipulation instructions
For byte operation
If DF = 0, then (DI) (DI) + 1 ; (SI) (SI) + 1
If DF = 1, then (DI) (DI) - 1 ; (SI) (SI) – 1
For word operation
If DF = 0, then (DI) (DI) + 2 ; (SI) (SI) + 2
If DF = 1, then (DI) (DI) - 2 ; (SI) (SI) - 2
instruction set 91
String Instructions
String data byte/word manipulation instructions
SCAS / SCASB / SCASW: Scan string byte or String word
One byte or word of a string data stored in extra segment is subtracted
from the contents of AL / AX and the result modifies the flags.
The DI register points to the string byte or word.
The CX register is decremented by one for each byte / word
movement.
The DI register is automatically incremented or decremented
depending on the status of DF.
MA = (DS) X 1610 + (SI)
MAE = (ES) X 1610 + (DI)
Modify flags (AL) - (MAE) / (AX) - (MAE : MAE + 1)
If (AL) > (MAE) then CF = 0 ; ZF = 0 ; SF = 0
If (AL) < (MAE) then CF = 1 ; ZF = 0 ; SF = 1
If (AL) = (MAE) then CF = 0 ; ZF = 1 ; SF = 0
For byte operation
If DF = 0, then (DI) (DI) + 1
If DF = 1, then (DI) (DI) - 1
For word operation
If DF = 0, then (DI) (DI) + 2
instruction set 92
If DF = 1, then (DI) (DI) - 2
String Instructions
String data byte/word manipulation instructions
LODS / LODSB / LODSW: Load string byte or word into AL
register.
One byte or word of a string data stored in data segment is loaded
or stored into AL / AX register.
The SI register points to the source string .
The SI register is automatically incremented or decremented
depending on the status of DF.
load instruction does not affect any flags.
MA = (DS) X 1610 + (SI)
(AL) (MA) / (AX) (MA : MA + 1)
For byte operation
If DF = 0, then (SI) (SI) + 1
If DF = 1, then (SI) (SI) – 1
For word operation
If DF = 0, then (SI) (SI) + 2
If DF = 1, then (SI) (SI) - 2
instruction set 93
String Instructions
String data byte/word manipulation instructions
STOS / STOSB / STOSW: Store string byte or word from AL
register.
One byte or word of a string data stored in AL / AX register is
copied or stored as string data into extra segment.
The DI register points to the destination string.
The DI register is automatically incremented or decremented
depending on the status of DF.
MAE = (ES) X 1610 + (DI)
(MAE) (AL) / (MAE : MAE + 1) (AX)
For byte operation
If DF = 0, then (DI) (DI) + 1
If DF = 1, then (DI) (DI) - 1
For word operation
If DF = 0, then (DI) (DI) + 2
If DF = 1, then (DI) (DI) - 2
instruction set 94
Processor Control Instructions
The Processor control instructions include flag manipulation and
processor control instructions.These instructions control the
functioning of the available hardware (programmer accessible
hardware) inside the processor chip.
These are categorized into two types:
a) Flag manipulation instructions
b) Machine control instructions
instruction set 97
Processor Control Instructions
Machine control instructions
WAIT : Wait for Test input pin to go low or an interrupt signal
This instruction causes the processor to enter into an idle state or
wait state and continue to remain in that state until a signal is
asserted on the TEST input pin or until a valid interrupt signal is
received on the INTR or NMI interrupt input pin.
If a valid interrupt signal occurs while the 8086 is in idle state, the
8086 will return to the idle state after the interrupt service
procedure executes. It returns to the idle state because the
address of the WAIT instruction is the address pushed on to the
stack when the 8086 responds to the interrupt request.
WAIT affects no flags
The WAIT instruction is used to synchronize the 8086 processor
with the external hardware such as the 8087 math processor.
HLT : Halt Processing
The HLT instruction will cause the 8086 to stop the fetching and
execution of the instructions. The 8086 will enter a halt state i.e.,
used to terminate a program.
The only ways to get processor out of Halt state are with an
interrupt signal on INTR pin, an interrupt signal on NMI pin, or a
valid reset signal on RESET input.set
instruction 98
Processor Control Instructions
Machine control instructions
NOP : No Operation
No operation is performed for three clock periods
This instruction simply uses up three clock cycles and increments
the instruction pointer to point to the next instruction.
The NOP instruction does not affect any flag.
The NOP instruction can be used to increase the delay of a delay
loop.
When hand coding, a NOP can also be used to hold a place in a
program for instruction that will be added later.
instruction set 99
Processor Control Instructions
Machine control instructions
ESC : Escape
ESC opcode, Mem. / Reg.
This instruction is used to pass instructions to a coprocessor , such
as the 8087 math coprocessor which shares the address and data
bus with 8086
Instructions for coprocessor are represented by a 6-bit code
embedded in the escape instruction.
As 8086 fetches the instructions bytes, the coprocessor also
catches these bytes from the data bus and puts them in its queue ,
but treats all the normal 8086 instructions as NOPs and when ESC
instruction is fetched by 8086, the coprocessor decodes the
instruction and carries out the action specified by the 6-bit code in
the instruction.
In most cases 8086 treats the ESC instruction as NOP but in some
cases 8086 will access a data item in memory for the coprocessor.
For ESC opcode, Mem format the data is accessed by 8087 from
memory
For ESC opcode, Mem format the data is accessed by 8087 from
8086 register specified in the instruction.
instruction set 100
Processor Control Instructions
Machine control instructions
LOCK : Assert Bus Lock signal
The LOCK is used as a prefix to a critical instruction which has to
be executed without any disturbances to system bus from other
bus masters.
When LOCK prefix is used in an instruction then during execution
of this instruction the lock prefix ensures that the shared system
resources are not taken over by other bus masters in the middle of
the critical instruction execution.
When an instruction with LOCK prefix is executed the 8086 will
assert its bus lock signal output.This signal is connected to an
external bus controller device, which then prevents any other
processor from taking over the system bus
LOCK affects no flags.
CALL Disp-16
(SP) (SP) – 2
MAS = (SS) X 1610 + (SP)
(MAS) (IP)
(IP) Disp-16
instruction set 105
Program execution transfer instructions
Unconditional transfer instructions
JMP Mem.
The content of (16-bit) memory is moved into IP and the next word
in memory is moved into CS register.
(IP) (Mem.)
(CS) (Mem. + 2)
Define Problem
2 3
Develop Algorithm
.OBJ
Assemble .LST
Assembl
YES y
Errors NO
Assembler Directives 144
1
1
.EXE
LINK .MAP
Locate .BIN
NO YES
External
System
Load Program
Load Program
4 5
NO NO
Errors Errors
YES YES
Stop
2 3
Inter-Segment Procedure:
CALL (SP) (SP) – 2
(((SP) + 1) : (SP)) (CS)
(SP) (SP) –2
(((SP) + 1) : (SP)) (IP)
(IP) (EA)
(CS) Seg. Address
MP
CALL
SP
RET
MP SP1
SP2
CALL
CALL
RET
RET
SP1
SP1
MP SP1
CALL
CALL CALL
RET
RET
RET
Push all the flags and all registers used in the procedure.
MP SP ISR
INT
CALL CALL SP
RET
IRET