Chapter 4
Chapter 4
By: Gemmachis T.
The instruction set provides commands to the processor, to tell it what it needs to
do.
The instruction set consists of addressing modes, instructions, native data types,
registers, memory architecture, interrupt, exception handling, and external I/O.
8086 Microprocessor has more than 20,000 instructions.
Hence this microprocessor is called CISC processor
Cont’d…
Classification of Instruction Set
Arithmetic Instructions
String Instructions
POP des:
POP instruction is used to get a word from the top of the stack to the provided
location.
It pops the operand from top of stack to Des.
Des can be a general purpose register, segment register (except CS) or memory
location.
Example:
POP AX;
Cont’d…
XCHG des, src:
XCHG is used to exchange the data from two locations.
This instruction exchanges src with des.
It cannot exchange two memory locations directly.
Example:
XCHG DX, AX;
IN Accumulator, Port Address:
IN instruction is used to read a byte or word from the provided port to the
accumulator.
It transfers the operand from specified port to accumulator register.
Example:
IN AX, 0028 H
Cont’d…
OUT Port Address, Accumulator:
OUT instruction is used to send out a byte or word from the accumulator to
the provided port.
It transfers the operand from accumulator to specified port.
Example:
OUT 0028H, AX;
LEA Register, src:
LEA (Load Effective Address) instruction is used to load the address of
operand into the provided register.
It loads a 16-bit register with the offset address of the data specified by the src.
Example:
LEA BX, [DI];
This instruction loads the contents of DI (offset) into the BX register.
LDS des, src: Cont’d…
LDS (Load Data Segment) instruction is used to load DS register and other
provided register from the memory
It loads 32-bit pointer from memory source to destination register and DS.
The offset is placed in the destination register and the segment is placed in
DS.
To use this instruction the word at the lower memory address must contain
the offset and the word at the higher address must contain the segment.
Example:
LDS BX, [0301H];
Cont’d…
LES Des, Src:
LES (Load Extra Segment) instruction is used to load ES register and other
provided register from the memory.
It loads 32-bit pointer from memory source to destination register and ES.
The offset is placed in the destination register and the segment is placed in
ES.
This instruction is very similar to LDS except that it initializes ES instead of
DS.
Example:
LES BX, [0301H];
Cont’d…
The following are instructions to transfer flag registers.
These instructions do not accept any operands
ADC (ADD with Cary) adds the two operands with CF.
It affects AF, CF, OF, PF, SF, ZF flags. Example:
ADC AL, 74H;
ADC DX, AX;
ADC AX, [BX];
Cont’d…
SUB Des, Src:
SUB instruction is used subtracts a byte from byte or a word from
word.
It effects AF, CF, OF, PF, SF, ZF flags. Example:
SUB AL, 74H;
For subtraction, CF acts as borrow flag. SUB DX, AX;
SUB AX, [BX];
SBB Des, Src:
SBB (Subtract with Borrow) subtracts the two operands and also
the borrow from the result.
Example:
It effects AF, CF, OF, PF, SF, ZF flags. SBB AL, 74H
SBB DX, AX
SBB AX, [BX]
Cont’d…
INC Src:
It increments the byte or word by one.
The operand can be a register or memory location.
It effects AF, OF, PF, SF, ZF flags.
CF is not effected. Example:
INC AX;
DEC Src:
It decrements the byte or word by one.
The operand can be a register or memory location.
It effects AF, OF, PF, SF, ZF flags.
CF is not effected. Example:
DEC AX;
Cont’d…
AAA (ASCII Adjust after Addition):
The data entered from the terminal is in ASCII format.
In ASCII, 0 – 9 are represented by 30H – 39H.
This instruction allows us to add the ASCII codes
This instruction does not have operands.
Other ASCII Instructions:
AAS (ASCII Adjust after Subtraction)
AAM (ASCII Adjust after Multiplication)
AAD (ASCII Adjust Before Division)
Cont’d…
DAA (Decimal Adjust after Addition)
It is used to make sure that the result of adding two BCD numbers
is adjusted to be a correct BCD number.
It only works on AL register.
DAS (Decimal Adjust after Subtraction)
It is used to make sure that the result of subtracting two BCD
numbers is adjusted to be a correct BCD number.
It only works on AL register.
NEG Src:
It creates 2’s complement of a given number.
Example:
That means, it changes the sign of a number. NEG AL;
Cont’d…
CMP des, src:
It compares two specified bytes or words.
The src and des can be a constant, register or memory location.
Both operands cannot be a memory location at the same time.
The comparison is done simply by internally subtracting the
source from destination.
The value of source and destination does not change, but the flags
are modified to indicate the result.
Cont’d…
MUL src:
It is an unsigned multiplication instruction.
It used to multiply unsigned byte by byte/word by word.
It multiplies two bytes to produce a word or two words to
produce a double word.
Example:
AX = AL * Src Src=8-bit register/memory MUL BH;
DX : AX = AX * Src Src=16-bit register/memory MUL CX;
Example:
CMPS
CMPSB
CMPSW
Cont’d…
SCAS/SCASB/SCASW string:
These instructions scan a string.
They compare the string with byte in AL or with word in AX.
SCASB compares byte at ES:DI with AL and sets flags
according to result.
SCASW compares word at ES:DI with AX and sets flags.
Example:
SCAS
SCASB
SCASW
Cont’d…
MOVS / MOVSB / MOVSW:
These instructions are used to move the byte/word from one string to
another.
They cause moving of byte or word from one string to another.
In these instructions, the source string is in data segment and destination
string is in extra segment.
SI and DI store the offset values for source and destination index.
MOVSB moves contents of byte given by DS:SI into ES:DI
MOVSW moves contents of word given by DS:SI into ES:DI
Example:
MOVS
MOVSB
MOVSW
Cont’d…
REP/REPE/REPZ/REPNE/REPNZ (Repeat):
These are an instruction prefix.
REP Used to repeat the given instruction till CX ≠ 0
REPE repeat the given instruction while CX = 0
REPZ repeat the given instruction while ZF = 1
REPNE repeat the given instruction while CX != 0
REPNZ repeat the given instruction while ZF = 0
Example:
REPE MOVSB STR1, STR2;
It copies byte by byte contents.
REP repeats the operation MOVSB until CX becomes zero.
Processor Control Instructions
Process control instructions are the instructions which control the
processor’s action by setting(1) or resetting(0) the values of flag
registers.
These instructions control the processor itself.
8086 allows to control certain control flags that causes the
processing in a certain direction
These instructions are used for processor synchronization if more
than one microprocessor attached.
Cont’d…
STC: It sets the carry flag CF to 1.
CLC: It clears the carry flag CF to 0.
CMC: It complements the carry flag CF.
STD: It sets the direction flag DF to 1.
If it is set, string bytes are accessed from higher memory
address to lower memory address.
CLD: It clears the direction flag DF to 0.
If it is reset, the string bytes are accessed from lower memory
address to higher memory address.
STI: It sets the interrupt flag to 1 .
CLI: It clears/resets the interrupt flag to 0
~~~~~~~ The End ~~~~~~~