8086 Instruction Set and Programming
8086 Instruction Set and Programming
This unit is concerned with the instruction set, instruction This format is also 2 bytes long and similar to register to
format and different addressing mode of 8086 micro- register format expect for the MOD filed as shown.
processor. D D1 Do D7 Ds Ds D Da D2 Di Do
L DS
Description Clock Cycles
Fig. 6.3
Displacement 6
Base +Displacement Addressing Mode
(d) Base or Index (BX,BP,SI,DI) 5
DS-
BX - 80188/80186timings differ from those of the 8088/ 8086/
80286
Fig.6.4 All timings are for best case and do not take into account
Mode wait states, instruction alignment, the state of the prefetch
(e) Index + Displacement Addressing
in this queue, DMA refresh cycles, cache hits/misses or exception
data is formed,
The effective address of
contents of a index register processing.
addressing mode, by adding in the To convert clocks to nanoseconds divide one microsecond by
to the 8-bit or 16-bit displacement specified
the processor speed in MegaHertz:
instruction.
(1000MHz/(n MHz)) = X nanoseconds
Example : MOV AL, 30H [SI
DIGITAL ELECTRONICs &MICROPROCESSOR (SY COMP, BATU) 8086 INSTRUCTION SET AND PROGRAMMING
(6.4)
MOV BX, (0301H] => Assume DS = 1000H, then BL Register
6.5 CLASSIFICATION OFINSTRUCTION SET
will be loaded with contents of memory location address
1. Data Transfer Instructions
[DS Offset] i.e. [100OH: 0301H] and BH Register will be
These instructions are used to transfer/copy data from source loaded with contents of memory location address [1000H
to destination. The operand can be a constant, memory
location, register or /O port address.
0302H].
2. PUSH Operand:
The source may be any one of the segment register or either
general or special Function Register, Immediate Number, It pushes the operand onto top of stack.
memory Location.
16-bit data is transferred on to the stack.
Note: This Category of Instructions do not Modify Flag When Data is pushed SP pointer is decremented first
Register
and data is stored.
2. Arithmetic Logical Instructions
Example: PUSH BX
All the instructions performing arithmetic, increment in
operand, decrement the operand belong to this category.
Note: This SS:SP-2 BL Register
category of instructions do modify flag register
3. SS:SP-1 BH Register
Logical Instructions/(Bit Manipulation Instructions)
These instructions are used at the bit level. These SS SP
instructions
can be used for
Fig. 6.6
Testing a zero bit
3. POP Des:
Set or reset a bit
It pops the operand from top of stack to Des.
Shift bits across registers Des can be a general purpose register, segment register
Note: This category of instructions do modify flag register (except CS) or memory location.
4. Program Execution Transfer Instructions
When data is popped, data is retrieved first and then SP
These instructions transfer control of execution to the is incremented.
specified address. All the call, jump, interrupt and return
instructions belong to this class. Example: POP AX
4. XCHG Des, Src:
5. String Instructions
This instruction
exchanges Sre with Des.
These instructions involve various string manipulation
operations like load, move, scan, compare, store etc. These I t cannot exchange two memory locations
directly.
instructions are only to be operated onto the strings.
Example:XCHG DX, AX.
6. Processor Control Instructions Exchange the contents of AX register with DX register.
These instructions control the machine status. 5. IN Accumulator, Port Address :
6.5.1 Data Transfer Instructions It transfers the operand from specified port to
1. MOV Des, Src accumulator register.
Src operand can be register, memory location or Example: IN AX, 0028 H
immediate operand. 5. OUT Port Address, Accumulator:
Des can be register or memory operand. It transfers the operand from accumulator to specified
Both Src and Des cannot be memory location at the port.
same time. Example: OUT 0028 H, AX.
Both Src and Des operand Size should match. 1. LEA Register, Src:
Sre:
LDS Des, 2. ADc Des, Src:
8.
Tt loads 32-bit pointer from memory source to
destination register and DS.
It adds the two operands with CF
It effects AF, CF, OF, PF, SF, ZF flags.
The offset is placed in the destination register and the operands with
Similar to add instruction it adds two
The offset is placed in the destination register and the For subtraction, CF acts as borrow flag.
segment is placed in ES.
Example:
contents of
subtracts number 74H from
This instruction is very similar to LDS except that it SUB AL, 74H: It
initializes ES instead of DS. AL Register and stores subtraction into AL Register
contents of DX register from
Example: LES BX, [0301 H] SUB AX, DX: It subtracts
into AX Register.
AX and stores subtraction
10. LAHF: location
contents of memory
SUB AX, [BX] It subtracts
:
I t copies the lower byte offlag register to AH. subtraction into
pointed by [DS: BX] from AX and stores
the lower byte of
This instruction can be used to read AX Register
flag register into AH registers. SBB Des, Src:
4
Based on this, decision can be taken from the contents operands and also the borrow from
It subtracts the two
of AH register. the result.
It effects AF, CF, OF, PF, SF, ZF flags.
11. SAHF :
the contents of AH to lower byte of flag Example,
It copies
SBB AL 74H
register.
lower byte of flag
This instruction can be used to modify SBB AX, DX
settings stored in the AH
register as per initial required SBB AX [BXI
12. PUSHF: Pushes flag register onto top ofstack. It increments the byte or word by one. The operand can
9. DAA (Decimal Adjust after Addition) The conversion is done by extending the sign bit of AL
It is used to make sure that the result of adding two BcD throughout AH.
numbers is adjusted to be a correct BCD number. It only 18. CWD (Convert Word to Double Word) :
works on AL register. This instruction converts word in AX to double word in
10. DAS (Decimal Adjust after Subtraction) DX:AX.
It is used to make sure that the result of subtracting two The conversion is done by extending the sign bit of AX
BCD numbers is adjusted to be a correct BCD number. throughout DX.
only works on AL register. 6.5.3 Logical Instructions/Bit Manipulation Instructions
11. NEG Src:
1. NOT Src:
It creates 2s complement of a given number. That It complements each bit of Sre to produce 1's
means, it changes the sign of a number. complement of the specified operand.
12. CMP Des, Sre: The operand can be a register or memory location.
It compares two specified bytes or words.
2. AND Des, Sre:
The Src and Des can be a constant, register or memory It performs AND operation of Des and Src bitwise.
location. Src can be immediate number, register or memory
Both operands cannot be a memory location àt the same location.
time. Des can be register or memory location. Both operands
The comparison is done simply by internally subtracting cannot be memory locations at the same time.
the source from destination.
CF and OF become zero after the operation. PF, SF and
The value of source and destination does not change, ZF are updated.
but the flags are modified to indicate the result. 3. OR Des, Src:
Table6.3 I t performs OR operation of Des and Src bitwise.
Condition CY Src can be immediate number, register or memory
Des> Src 0 location.
DesSrc 1 0 Des can be register or memory location.
CLC:t clears the carry flag to 0. call instruction. A label is followed by a colon ().
forn
CMC:It complementsthecarry flag. The Mnemonics column contains opcode mnemonics
instruction. It is also called as operation fields w
STD I t sets the direction flag to 1. If it is set, string
ADD, S
accessed from higher memory address to enlighten the type of operation it is such as MOV,
bytes are
mem
lower memory address. MUL etc. The operand(s) column contains registers,
locations or data used by instructions. A comments col
CLD: It clears the direction flag to 0. If it is reset, the of the instruction for fu
utilized to describe the function
are accessed from lower memory address to
string bytes reference. It starts with semicolon ().
higher memory address.