Professional Documents
Culture Documents
UNIT 1 - 8086 Instruction Set
UNIT 1 - 8086 Instruction Set
UNIT 1 - 8086 Instruction Set
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
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
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]
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]
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
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
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.