Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

INSTRUCTION SET of 8086 Microprocessor POP AX

POP DS
The instruction set are categorized into the following POP [5000H]
types
1. Data copy or transfer instructions XCHG : Exchange byte or word
2. Arithmetic and logical instructions
3. Branch instructions This instruction exchange the contentrs of a specified
4. Loop instructions source and destination operands
5. Machine control instructions
6. Flag manipulation instructions Example`
7. shift and rotate instructions XCHG [5000H], AX
8. String instructions XCHG BX,AX

XLAT
Data copy or transfer instructions
Translate byte using look up table
MOV
This instruction copies a word or a byte of data from Example
some source to a destination. This destination can be a LEA BX, TABLE1
register or a memory location. The source can be a MOV AL, 04H
register, a memory location or an immediate number. XLAT

Example Simple input and output port transfer instructions


MOV AX,BX
MOV AX,500H IN : Copy a byte or word from a specified port to
MOV AX,[SI] accumulator.
MOV AX,[2000H] Example
MOV AX,50H[BX] IN AL, 03H
IN AX, DX
Direct loading of the segment registers with immediate
data is not permitted. OUT: Copy a byte or word from accumulator specified
port.
PUSH : Push to stack
This instruction pushes the contents of the specified Example
register/memory location on to the stack. The stack OUT 03H, AL
pointer is decremented by 2, after each execution of OUT DX, AX
this instruction.
LEA : Load effective address of the operands in
Example specified register.
PUSH AX
PUSH DX Eg.
PUSH [5000H] LEA reg, offset

POP : Pop from stack LDS : Load DS register with other specified register
from memory
This instruction when executed, loads the specified [reg] [mem]
register/memory location with the contents of the [DS] [mem +2]
memory location of which the address is formed using
the current stack segment and stack pointer. The stack Eg.
pointer is incremented by 2. LDS reg, mem

Example

1
LES : Load ES register and other specified register Eg.
from memory. ADC 0100H
[reg] [mem] ADC AX,BX
[reg] [mem +2] ADC AX,[SI]
Eg. ADC AX,[5000]
LES reg, mem ADC [5000],0100H

FLAG TRANSFER INSTRUCTIONS SUB: Subtract


The subtract instructiion subtracts the source operand
LAHF from the destination operand and the result is left in the
Load AH with the low byte of the flag register. destination operand.
[AH] <---- [Flags low byte] Eg.
Eg LAHF
SUB AX,0100H
SAHF SUB AX,BX
Store AH register to low byte of flag register. SUB AX,[SI]
[Flags low byte] <---- [AH] SUB AX, [5000H]
Eg. SAHF SUB [5000H], 0100H

PUSHF SBB : Subtract with borrow


Copy flag register to top of stack. The subtract with borrow instruction subtracts the
[SP] <---- [SP]-2 source operand and the borrow flag (CF) which may
[[SP]] <--- [ Flags] reflect the result of the previous calculations, from the
Eg. PUSHF destination operand.
Eg.
POPF
Copy word at top of stack to flag register. SBB AX,0100H
[Flags] <---- [[SP]] SBB AX,BX
[SP] <--- [SP+2] SBB AX,[SI]
SBB AX, [5000H]
ARITHMETIC INSTRUCTIONS SBB [5000H], 0100H

INC : Increment
The 8086 provides many arithmetic operations : This instruction increases the contents of the specified
addition, subtraction, negation , multiplication and register or memory location by 1. Immediate data
comparing two values. cannot be operand of this instruction.
Eg.
ADD : INC AX
The add instruction adds the contents of the source INC [BX]
operand to the destination operand. INC [5000H]
Eg.
ADD AX,0100H DEC : Decrement
ADD AX,BX The decrement instruction subtract 1 from the contents
ADD AX,[SI] of the specified register or memory location.
ADD AX, [5000H] Eg.
ADD [5000H], 0100H DEC AX
ADD 0100H DEC [5000h]

ADC : NEG : Negate


Add with carry The negate instruction forms 2's complement of the
This instruction performs the same operation as the add specified destination in the instruction. The
instruction, but adds the carry flag to the result. destinatiopn can be a register or a memory location .

2
This instruction can be implemented by inverting each Convert signed word in AX to signed double word in
bit and adding 1 to it. DX : AX
Eg DX = 1111 1111 1111 1111
NEG AL Result in AX = 1111 0000 1100 0001
AL= 0011 0101 35H Replace number in AL with its 2's
complement DIV : Unsigned division
AL = 1100 1011 = CBH This instruction is used to divide the unsigned word by
a byte or to divide an unsigned double word by a word.
CMP : Compare Eg
This instruction compares the source operand, which DIV CL ; word in AX / byte in CL ,quotient im AL ,
may be a register or a memory location, with a remainder in AH.
destination operand that may be a memory location DIV CX ; Double word in DX and AX / word in CX
Eg. and Quotient in AX , remainder in DX.
CMP BX,0100H
CMP AX, 0100H AAA : ASCII adjust after addition
CMP [5000H], 0100H The AAA instruction is executed after an ADD
CMP BX, [SI] instruction that adds two ASCII coded operand to give
CMP BX, CX a byte of result in AL . The AAA instruction converts
the resulting contents of AI to a unpacked decimal
MUL : Unsigned multiplication byte or word digit.
This instruction multiplies an unsigned byte or word by Eg.
the contents of AL. ADD CL,DL ; [CL] = 32H = ASCII for 2 , [DL] = 35H
Eg. = ASCII for 5, Result [CL] = 67H
MUL BH ; (AX) (AL) * (AX)
MUL CH ; (DX)(AX) (AX) * (CX) MOV AL, CL ; move ASCII result into AL since AAA
MUL WORD PTR [SI] ; (DX) (AX) (AX) * ([SI[) adjust only [ AL]

IMUL : Signed multiplication AAA ; [AL] = 07, unpacked BCD for 7


This instruction multiplies a signed byte in source
operand by a signed byte in AL or a signed word in AAS : ASCII adjust AL after subtraction
source operand by a signed word in AX. This instruction corrects the result in AL register after
Eg. subtracting two unpacked ASCII operands. The result is
IMUL BH in unpacked decimal format. THE procedure is similar
IMUL CX to AAA instruction except for the subtraction of 06
IMUL [SI] from AL.

CBW : Convert signed byte to word AAM : ASCII adjust after multiplication
This instruction copies the sign of a byte in AL to all This instruction after execution converts the product
the bits in AH. AH is then said to be sign extension of available in AL into unpacked BCD format.
AL. Eg.
Eg. MOV AL , 04H ; AL= 04H
CBW MOV BL , 09 ; BL = 09
AX = 0000 0000 1001 1000 Convert signed byte in AL MUL BL ; AX = AL* BL ; AX= 24H
signed word in AX AAM ; AH= 03, AL=06
Result in AX = 1111 1111 1001 1000
AAD : ASCII adjust before division
CWD : Convert signed word to double word This instruction converts two unpacked BCD digits in
This instruction copies the sign of a byte in AL to all AH and AL to the equivalent binary number in AL.
the bits in AH. AH is then said to be a signed extension This adjustment must be done before dividing the two
of AL unpacked BCD digits in AX by an unpacked BCD byte.
Eg, IN the instruction sequence , this instruction appears
CWD before DIV instruction.

3
Eg. This instruction complements the contents of an
AX 05 08 operand register or memory location, bit by bit.
AAD result in AL 00 3A; 58D= 3A h in AL Eg.
NOT AX
DAA : Decimal adjust accumulator NOT ]5000H]
This instruction is used to convert the result of the
addition of the two packed BCD numbers to a valid XOR : Logical exclusive OR
BCD number. The result has to be only in AL This instruction bit by bit XOR's the source operand
Eg. that may be an immediate register or a memory location
AL = 53 CL = 29 to a destination operand. The result is stored in the
ADD AL, CL ; AL (AL) + (CL) destination operand.
AL 53 +29
AL 7C Eg.
DAA ;AL 7C + 06 XOR AX,0008H
;AL 82 XOR AX, BX

TEST : Logical compare instructions


DAS : Decimal adjust after subtraction The test instruction performs a bit by bit logical AND
This instruction converts the result of the subtraction of operation on the two operands. The result of this
two packed BCD numbers to a valid BCD number. This ANDing operation is not available for further use, but
subtraction has to be AL only flags are affected.
Eg. Eg.
AL = 75, BH= 46 TEST AX,BX
SUB AL, BH ; AL 2F= (AL) - (BH) TEST [0500], 06H
AF= 1
DAS ; AL 29 (as F >9, F-6= 9)
SAL/SHL : SAL/SHL destination, count
SAL and SHL are two mnemonics for the same
LOGICAL INSTRUCTIONS instruction. This instruction shifts each bit in the
specified destination to the left and 0 is stored at LSB
AND : Logical AND position. The MSB is shifted into the carry flag. The
This instruction bit by bit AND's the source operand destination can be a byte or a word .
that may be an immediate register or a memory location It can be in a register or in a memory location. The
to the destination operand that may be a register or a number of shifts is indicated by count.
memory location . The result is stored in the destination Eg.
operand SAL CX, 1
Eg. SAL AX, CL
AND AX,0008H
AND AX, BX SHR : SHR destination, count
This instruction shifts each bit in the specified
OR : Logical OR destination to the right and 0 is stored at MSB position.
This instruction bit by bit OR's the source operand that The LSB is shifted into the carry flag. The destination
may be an immediate register or a memory location to can be a byte or a word. It can be in a register or in a
the destination operand that may be a register or a memory location. the number of the shifts is indicated
memory location. The result is stored in the destination by the count.
operand. Eg

Eg. SAL CX, 1


OR AX,0008H MOV CL, 05H
OR AX, BX SAL AX, CL

NOT : Logical invert

4
RCR AL, CL
SAR : SAR destination, count
This instruction shifts each bit in the specified BRANCH INSTRUCTIONS
destination some number of bit positions to the right.
As a bit is shifted out of the MSB position, a copy of
the old MSB is put in the MSB position. The LSB will Branch instruction transfers the flow of execution of
be shifted into the CF. the program to a new address specified in the
Eg. instruction directly or indirectly. When this type of
SAR BL, 1 instruction is executed, the CS and IP registers get
MOV CL, 04H loaded with new values of CS and IP corresponding to
SAR DX, CL the location to be transferred.

ROL instruction : ROL destination, count The branch instruction are classified into two types
This instruction rotates all bits in a specified byte or
word to the left some number of bit positions. MSB is
placed as a new LSB and a new CF. 1. Unconditional branch instructions
Eg. 2. Conditional branch instructions
ROL CX, 1
MOV CL, 03H Unconditional branch instruction :
ROL BL, CL In unconditional control transfer instructions, the
execution control is transferred to the specified location
ROR Instruction : ROR destination, count independent of any status or condition . The CS and IP
This instruction rotates all bits in a specified byte or are unconditionally modified to the new CS and IP.
word to the right some number of bits. LSB is placed as
a new MSB and a new CF. CALL : Unconditional call
This instruction is used to call a subroutine (procedure)
Eg. from the main program. Address of procedure may be
ROR CX, 1 specified directly or indirectly.
MOV CL, 03H There are two types of procedures depending upon
ROR BL, CL whether it is available in the same segment or in
another segment.
1. Near CALL i.e., +32K or -32K displacement
RCL instruction : RCL destination, count 2. Far CALL i.e., anywhere outside the segment.
This instruction rotates all the bits in a specified byte or
word some number of bits position to the left along On execution this instruction stores the incremented IP
with the carry flags. MSB is placed as a new carry and and CS onto the stack and loads the CS and IP registers
previous carry in place as new LSB. with segment and offset address of the procedure to be
called.
Eg.
RCL CX, 1 RET : Return from procedure
MOV CL, 04H At the end of the procedure, the RET instruction must
RCL AL, CL be executed. When it is executed, the previously stored
content of IP and CS along with flags are retrieved into
RCR instruction : RCR destination , count the CS, IP and Flag registers from the stack and
This instruction rotates all bits in a specified byte or execution of the main programs continues further.
word some number of bit positions to the right along
with the carry flag. LSB is placed as a new carry and INT N : Interrupt Type N
previous carry is in place as a new MSB. In the interrupt structure of the 8086, 256 interrupts are
defined corresponding to the types from 00H to FFH.
Eg. When INT N instruction is executed, the type byte N is
RCR CX, 1 multiplied by 4 and the contents of the IP and CS of the
MOV CL, 04H interrupt service routine will be taken from memory
block in 0000 segment.
5
JNO Label
INTO : Interrupt in overflow Transfers execution control to address 'label' , if OF = 0
This instruction is executed when the overflow flag
ODF is set, This is equivalent to a Type4 interrupt
instruction. JNP Label
Transfers execution control to address 'label' , if PF = 0
JMP : Conditional jump
This instruction unconditionally transfers the control of JP Label
execution to the specified address using an 8 bit ot 16 Transfers execution control to address 'label' , if PF = 1
bit displacement. No flags are affected by this
instruction. JB Label
Transfers execution control to address 'label' , if CF = 1
IRET : Return from stack
When its is executed the values of IP ,CS and flags are JNB Label
retrieved from the stack to continue the execution of the Transfers execution control to address 'label' , if CF = 0
main program.
JNXZB Label
LOOP : LOOP unconditional Transfers execution control to address 'label' , if CX = 0
This instruction executes the part of the program from
the Label or address specified in the instruction up to
the loop instruction CX number of times . At each Conditional loop instructions
iteration ,CX is decremented automatically and JUMP
OF NOT ZERO structure.
LOOPZ/LOOPE Label
Conditonal branch instructions Loop through a sequence of instructions from label
while ZF = 1 and CX = 0
When this instruction is executed, execution control is
transferred to the address specified relatively in the
instruction, provided the condition implicit in the LOOPNZ/LOOPENE Label
opcode is satisfied. Otherwise execution continues Loop through a sequence of instructions from label
sequentially. while ZF = 1 and CX = 0

JZ/JZE Label STRING MANIPULATION INSTRUCTIONS


Transfers execution control to address 'label' , if ZF = 1
A series of data byte or word available in memory at
consecutive locations, to be referred as byte string or
JNZ/JNE Label word string. A string of characters may be located in
Transfers execution control to address 'label' , if ZF = 0 consecutive memory locations, where each character
may be represented by its ASCII equivalent.
The 8086 supports a set of more powerful instructions
JS Label for string manipulations for referring to a string , two
Transfers execution control to address 'label' , if SF = 1 parameters are required.

1. Starting and end address of a string


JNS Label 2. length of a string.
Transfers execution control to address 'label' , if SF = 0
The length of the string is usually stored as count in the
CX register. The incrementing or decrementing of the
JO Label pointer , in string instructions, depends upon the
Transfers execution control to address 'label' , if OF = 1 direction flag (DF) status. If it is a byte string
operation, the index registers are updated by one . On
the other hand , if it is a word string operation, the
index registers are updated by two.
6
REP : Repeat Instruction Prefix
This instruction is used as a prefix to other STOS : Store string byte or string word.
instructions , the instruction to which the REP prefix is The STOS instruction stores the AL /AX register
provided is executed repeatedly until the CX register contents to a location in the string pointed by the ES :
becomes zero (at each iteration the CX is automatically DI pair . The DI is modified accordingly . No falgs are
decremented by one). affected by this instruction .
The direction flag controls the string instruction
1. REPE / REPZ - Repeat operation while equal / execution. The SI and DI are modified after each
zero. iteration automatically. If DI = 1, then the execution
2. REPNE / REPNZ - Repeat operation while not follows auto decrement mode, SI and DI are
equal / zero. decremented automatically after each iteration. IF DS =
0, then the execution follows auto increment mode. In
These are used for CMPS , SCAS instructions only as this mode, SI and DI are incremented automatically
instruction prefixes. after each iteration.

MOVSB/ MOVSW : Move string byte or string word. Flag manipulation and processor control instructions
Suppose a string of bytes stored in a set of consecutive These instructions control the functioning of the
memory locations is to be moved to another set of available hardware inside the processor chip. These
destination locations. The starting byte of source string instructions are categorized into two types
is located in the memory location whose address may 1. Flag manipulation instructions
be computed using SI and DS contents. 2. Machine control instructions
The starting address of the destination locations where
this string has to be relocated is given by DI Flag manipulation instructions
( Destination Index) and ES (Extra segment) contents. The flag manipulation instruction directly modifies
some of the flags of the 8086.
CMPS : Compare string byte or string word. 1. CLC- clear carry flag.
The CMPS instruction can be used to compare two 2. CMC- complement carry flag.
strings of byte or words. The length of the string must 3. STC- set carry flag.
be stored in the register CX. If both the byte or word 4. CLD- clear direction flag.
strings are equal, zero flag is set. 5. STD- set direction flag.
The REP instruction prefix is used to repeat the 6. CLI- clear interrupt flag.
operation till CX (counter) becomes zero or the 7. STI- set interrupt flag.
condition specified by the REP prefix is false.
Machine control instructions
SCAN : Scan string byte or string word. The machine control instructions control the bus usage
This instruction scans a string of bytes or words for an and the execution
operand byte or word specified in the register AL or 1. WAIT- wait for test input pin to go low.
AX. The string is pointed to by ES:DI register pair. The 2. HLT- halt the process.
length of the string is stored in CX. The DF controls the 3. NOP- no operation.
mode for scanning of the string.Whenever a match to 4. ESC- escape to external device like NDP.
the specified operand is found in the string, execution 5. LOCK- Bus lock instruction prefix.
stops and the zero flag is set. If no match is found the
zero flag is reset.

LODS : Load string byte or string word


The LODS instruction loads the AL / AX register by the
content of a string pointed to by the DS : SI pair. The SI
is modified automatically depending upon DF. If it is a
byte transfer (LODSB), the SI is modified bu one and if
its a word transfer (LODSW), the SI is modified by
two. No other falgs are affected by the instruction.

You might also like