Professional Documents
Culture Documents
INSTRUCTIONS OF 8086
Classifications
Type of Branch
Branch with return (CALL, RET, IRET)
Branch without return (JMP, JNC, JO, JPE, JAE)
Conditional Branch (JNC, JO, JPE, JAE)
Unconditional Branch (JMP)
Range of Branch
Intrasegment (NEAR/SHORT Branch)
Only IP is updated
Intersegment (FAR Branch)
Both CS and IP are updated
Addressing Mode
Direct (FAR, Near/short)
Intersegment Range (CSSBA16, IPEA16)
Intrasegment Range ( IPIP+disp16 or IPIP+sign bit extended(disp8) (Relative branch)
Indirect (No relative branch)
Intersegment Range (CSSBA16, IPEA16)
Intrasegment Range ( IPEA16)
Note
Depending upon the type of procedure and the contents SP, the RET
instruction may be of four types
Return within segment
Return within segment adding 16 bit immediate displacement to the SP contents
(RET disp16)
Return intersegment
Return intersegment adding 16 bit immediate displacement to the SP contents (RET
disp16)
The INT n Instructions
INT instructions are software calls for 8086 ISRs (In other words it creates
interrupts within a program)
‘n’ indicates the type of interrupts.
There are 256 interrupts in 8086 from ‘type 0’ to ‘type FF’
In order to call each of these 256 interrupts the value ‘n’ respectively varies from
00H-FFH (for example in INT 21H, the value of n is 21H).
During execution of INT n the following things happen:
Decrements the stack pointer by 2 and push the flags onto the stack
Decrement the stack pointer by 2 and push the contents of CS onto the stack
Decrement the stack pointer by 2 and push the contents of IP (i.e. the offset of next
instruction after INT n instruction) onto the stack
Update IP with the 16 bit number present in memory with a physical address given by
n*4. For example, for INT 21H the new effective address to be loaded in IP will be read
from memory location: 21H*04H=00084H
Update CS with the 16 bit number present in memory with a physical address given by
n*4+2. For example, for INT 21H the new effective address to be loaded in IP will be read
from memory location: 21H*04H+2=00086H
Reset Both IF and TF. Other flags are not affected
The IRET Instruction
The IRET instruction is used at the end of interrupt service procedure to
return the execution to the interrupted program.
When IRET instruction is executed the following things take place:
The saved value of IP (effective return address saved during execution of INT n
instruction) in stack is copied into IP register.
The stored value of CS in stack is copied into CS register.
The stored value of flags (saved earlier during execution of INT n instruction) in
stack memory are saved into the flag register
Interrupt vector table (IVT) Interrupt
type
Logical address
SBA=0000H
Memory
(n) EA=n * 4
REP
REPZ/REPE
REPNZ/REPNE
LOOP
LOOPZ/LOOPE
LOOPNZ/LOOPNE
LOOP disp8 A
A
L1: B Microprocessor
C Executes from B to D
D
LOOP L1
E
CX=CX-1
• Assuming A – E
instructions are all
single bytes. IS
• LOOP disp8 is a two CX==0?
byte instruction NO
• Value assigned to L1 is
-5 YES
Microprocessor will
1. If CX=N Iteration will be for N times (entry values for loop body is N to 1) Execute E
1. Cx=1, iteration for once
2. If CX=0, then iteration will be for 65536 times
3. Running condition: CX ≠ 0 E
4. Exit condition: CX = 0
LOOPZ disp8 A
Microprocessor
A
Executes from B to D
L1: B
(ZF is affected)
C
D
LOOPZ L1 NO IS
E ZF==1?
• Assuming A – E
instructions are all
CX=CX-1
single bytes.
• LOOPZ disp8 is a two
byte instruction IS
• Value assigned to L1 is CX==0? NO
-5
YES
1. Loop as long as ZF is 1 (ie the result of comparison of signed/unsigned
number satisfies equality condition) and CX ≠ 0
Microprocessor will
2. Running condition: (ZF==1 AND CX ≠ 0)
Execute E
3. Exit condition: (ZF==0 OR CX==0)
1. Special case: Loop will breakout while ZF remains at 1 but CX
becomes 0 E
4. May be used to compare for dissimilarity of two data sequence
LOOPNZ disp8 A
Microprocessor
A
Executes from B to D
L1: B
(ZF is affected)
C
D
LOOPNZ L1 NO IS
E ZF==0?
• Assuming A – E
instructions are all single
bytes. CX=CX-1
• LOOPNZ disp8 is a two
byte instruction
IS
• Value assigned to L1 is -5
CX==0? NO
YES
1. Loop as long as ZF is 0 (ie the result of comparison of signed/unsigned
number satisfies in-equality condition) and CX ≠ 0
Microprocessor will
2. Running condition: (ZF==0 AND CX ≠ 0)
Execute E
3. Exit condition: (ZF==1 OR CX==0)
1. Special case: Loop may breakout while ZF remains at 0 but CX
becomes 0 E
4. May be used to compare for similarity of two data sequence
REP (Prefix) Instruction
A
A
REP B
C
NO IS
CX==0?
Microprocessor will
• REP is a prefix instruction YES
Execute B
• The instruction prefixed will be executed repeatedly
as long as CX is not equal to zero
• If CX==0 THEN next instruction will be executed CX=CX-1
• To execute an instruction N no of times CX should be
populated with value N
• Nmin=0 and Nmax=65535 C
REPZ/REPE (Prefix) Instruction
A
A
REPZ B
C
NO IS
• REPZ is a prefix instruction CX==0?
• The instruction prefixed will be executed repeatedly
as long as (ZF==1 AND CX is not equal to zero) Microprocessor will
Execute B YES
• If (ZF==0 OR CX==0) THEN next instruction will be
(ZF is affected)
executed
• Special case: Iteration breaks out if ZF==1 but
CX==0 CX=CX-1
• Used with CMP/CMPS instruction to perform
repeated comparison for equal data elements of a
sequence and to break out in case of dissimilarity. C
(comparison of two strings and detect mismatch IS
position) ZF==1?
YES
• To execute an instruction N no of times CX should be
populated with value N
• Nmin=0 and Nmax=65535 NO
REPNZ/REPNE (Prefix) Instruction
A
A
REPNZ B
C
NO IS
• REPNZ is a prefix instruction CX==0?
• The instruction prefixed will be executed repeatedly
as long as (ZF==0 AND CX is not equal to zero) Microprocessor will
Execute B YES
• If (ZF==1 OR CX==0) THEN next instruction will be
(ZF is affected)
executed
• Special case: Iteration breaks out if ZF==0 but
CX==0 CX=CX-1
• Used with CMP/CMPS instruction to perform
repeated comparison for unequal data elements of
a sequence and to break out in case of similarity. C
(comparison of two strings and detect match IS
position) ZF==0 ?
YES
• To execute an instruction N no of times CX should be
populated with value N
• Nmin=0 and Nmax=65535 NO
STRING INSTRUCTIONS
Introduction
String are sequences of data that mostly contains alphabetic characters
Obtained from/Sent to IO devices for human interaction
String instructions are special type of instructions those perform the following
on individual elements of a string:
Copy a string from one place to other area in memory
Compare two strings
Scan a string for the occurrence of a given character
Load characters of a string into accumulator for further processing
Store the character present in accumulator into a given string
The unique property of a string instruction (for ONE execution) is:
It performs one of the primary operations mentioned in above points on only ONE
character of string/strings
It then updates (increments/decrements) memory pointers to point to the next
character of the string.
The direction of update is determined by the Decrement Flag (Direction Flag)
If DF=1, memory pointers are decremented by one
If DF=0 memory pointers are incremented by one
MOVS/MOVSB/MOVSW
MOVSB/MOVSW: Copies a byte/word (that is a part of string) present in DMS
with effective address given in SI register TO a memory location in EMS with
effective address given in DI register
Source Destination
Byte/Word sized 8/16 BIT Byte/Word sized
character memory location
DS: SI ES: DI
SBA can also be obtained from:
CS/ES/SS
DF=0 DF=0
SI=SI+1(BYTE)/2(WORD) DI=DI+1(BYTE)/2(WORD)
DF=1 DF=1
SI=SI-1(BYTE)/2(WORD) DI=DI-1(BYTE)/2(WORD)
CMPS/CMPSB/CMPSW
CMPSB/CMPSW: Compares a byte/word (that is a part of string) present in
DMS with effective addres given in SI register WITH a byte/word (that is a
part of string) present in EMS with effective address given in DI register and
UPDATES FLAGS as a result
DF=0
DI=DI+1(BYTE)/2(WORD)
DF=1
DI=DI-1(BYTE)/2(WORD)
Flag manipulation and Processor control
instructions
Flag manipulation instructions:
CLC, CMC, STC, CLD, STD, CLI, STI
Machine control instructions:
Instruction Description
NOP No Operation