0% found this document useful (0 votes)
48 views63 pages

Instr Set

Uploaded by

resourcesb23ec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views63 pages

Instr Set

Uploaded by

resourcesb23ec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

The Instruction set of 8086

Features
 Usually there is a destination and a source
 If there are two operands, one of them should be in a register ,or an
immediate operand
 If only one operand ,it can be a destination or a source
 In some cases, the operand is implicit
The Instruction set of 8086
 The 8086/8088 instructions are categorized into the following main types.
 The function of each instructions with suitable examples wherever
necessary.
1. Data Copy/Transfer Instructions These types of instructions are used
to transfer data from source operand to destination operand. All the
store, move, load, exchange, input and output instructions belong to
this category.
2. Arithmetic and Logical Instructions All the instructions performing
arithmetic, logical, increment, decrement, compare and scan
instructions belong to this category.
The Instruction set of 8086
3. Branch Instructions These instructions transfer control of execution to
the specified address. All the call, jump, interrupt and return
instructions belong to this class.
4. Loop Instructions If these instructions have REP prefix with CX used
as count register, they can be used to implement unconditional and
conditional loops. The LOOP, LOOPNZ and LOOPZ instructions belong
to this category. These are useful to implement different loop structures.
5. Machine Control Instructions These instructions control the
machine status. NOP, HLT, WAIT and LOCK instructions belong to this
class.
The Instruction set of 8086
6. Flag Manipulation Instructions All the instructions which directly
affect the flag register, come under this group of instructions.
Instructions like CLD, STD, CLI, STI, etc. belong to this category of
instructions.
7. Shift and Rotate Instructions These instructions involve the bitwise
shifting or rotation in either direction with or without a count in CX.
8. String Instructions These instructions involve various string
manipulation operations like load, move, scan, compare, store, etc.
These instructions are only to be operated upon the strings.
DATA TRANSFER INSTRUCTIONS
 MOV – Move
 Usage: MOV destination, source
 This instruction causes the source content to be copied to the destination.
 Remember that the data types of source and destination should match –
both should be either bytes or words.
 Examples:
MOV AX,CX
MOV AL,AH
MOV AX,[BX]
MOV COST,DX
DATA TRANSFER INSTRUCTIONS
 PUSH & POP – Push & Pop the data of stack
 Usage : PUSH source
POP destination
 For the 8086, only 16-bit data can be pushed and popped.
PUSH BX
PUSH [BX ]
PUSH DS
PUSH COSTP
POP CX
POP [SI]
Note CS is not a valid destination for POP.

Th e PUSH and POP instructions are relevant only for the stack segment.
Know about the operation of the stack before attempting to understand the PUSH
and POP instructions.
Stack
 Is a LIFO stack
 If the stack is defined from addresses 20000H to 203E8H ,
SS=2000H and SP=03E8H,.This stack then has a size of 3E8H bytes
or 1000 bytes.
 In the 8086 ,only a word (16 bits ) can be pushed on to stack .
 A push thus causes two memory locations to be accessed –
 It follows the ‘little endian ‘concept
 This is why it is called the TOP of STACK
Operation of the Stack
OPERATION OF THE STACK if BX has the content CC 99

PUSH operation in a stack


Operation of the Stack
POP operation in a stack

OPERATION OF THE STACK if pop,


CX has the content 0E 67H
Example:
Explain what is done in this program .Assume SP =0310H ,when the stack was initialized

MOV AX, 4567H

MOV BX, 0ACEH

PUSH AX

PUSH BX

POP AX

POP BX
DATA TRANSFER INSTRUCTIONS
 XCHG - Exchange
 Usage: XCHG destination, source

 The examples are as follows:


 XCHG [5000H], AX2.
 XCHG BX, AX

 Note: Exchange of contents of two memory locations is not permitted.


Immediate data is also not allowed in these instructions
DATA TRANSFER INSTRUCTIONS
 IN - Input the Port
 Usage IN destination, address(source)

 The examples are as follows:


 IN AL, 03H
 IN AX, DX

 Note: AL and AX are the allowed destinations for 8 and 16-bit input
operations. DX is the only register (implicit) which is allowed to carry the
port address.
DATA TRANSFER INSTRUCTIONS
 OUT - Output to the Port
 Usage IN destination(address), source

 The examples are as follows:


 OUT 03H, AL
 OUT AX, DX

 Note: The registers AL and AX are the allowed source operands for 8-bit
and 16-bit operations respectively. If the port address is of 16 bits it must
be in DX.
XLAT -Translate a byte in AL
 XLAT – Translate
 Usage : XLAT

 In case of code conversion problems, For look up tables


 Requirements : load into BX ,the offset of the look up table , Then use
XLAT
 Find the equivalent code and store in AL
XLAT
 XLAT is equivalent to the following instructions:
MOV AX, SEG Table
MOV DS, AX
MOV AL, CODE
MOV BX, OFFSET TABLE
XLAT
 SI or DI will be okay for showing the equivalence.
DATA TRANSFER INSTRUCTIONS
LEA –Load Effective address
Usage: LEA destination(reg16), source(memory)
LEA SI,COSTP
LEA BX, ARRAY

The above is a replacement for the instruction MOV BX, OFFSET


ARRAY used
DATA TRANSFER INSTRUCTIONS
LDS/LES –Load Pointer to DS/ES
Usage: LDS/LES loads the DS or ES register and the specified destination

Example
LDS BX, 5000H
LES BX, 5000H
List of 8086 Data Transfer Instructions with Format and Function
List of 8086 Data Transfer Instructions with Format and Function- contd

Note: None of the flags are affected with any data transfer instructions.
Arithmetic Instructions
 These instructions perform the arithmetic operations, like addition,
subtraction, multiplication and division along with the respective ASCII
and decimal adjust instructions.
 The increment and decrement operations also belong to this type of
instructions.
 The operands are either the registers or memory locations or immediate
data depending upon the addressing mode.
 The 8086/8088 instructions falling under this category are discussed
below in significant details.
 The arithmetic instructions affect all the condition code flags.
Arithmetic Instructions
 ADD - Addition
 Usage: ADD operand2(destination/result), operand1(source)

 Note: The result is in the destination operand. However, both the source
and destination operands cannot be memory operands.
Arithmetic Instructions
 ADC - Addition with Carry
 Usage: ADD operand2(destination/result), operand1(source)

 Note: adds the carry flag bit, all the condition code flags are affected by
this instruction.
Arithmetic Instructions
 INC - Increment
 Usage: INC destination

 Note: This instruction increases the contents of the specified register or


memory location by 1. All the condition code flags are affected except the
carry flag CF.
Arithmetic Instructions
 DEC - Decrement
 Usage: DEC destination

 Note: This instruction decrement the contents of the specified register or


memory location by 1. All the condition code flags are affected except the
carry flag CF.
Arithmetic Instructions
 SUB - Subtract
 Usage: SUB operand2(destination/result), operand1(source)

 Note: The destination/source operand may be a register or a memory


location, but both operands must not be memory operands. All the
condition code flags are affected by this instruction.
Arithmetic Instructions
 SBB - Subtract with Borrow
 Usage: SBB operand2(destination/result), operand1(source)

 Note: Subtraction with borrow, here means subtracting 1 from the


subtraction obtained by SUB, if carry (borrow) flag is set.
Arithmetic Instructions
 CMP - Compare
 Usage: CMP destination, source

 Note:
 It subtracts the source operand from the destination operand but does not store the result
anywhere.
 The flags are affected depending upon the result of the subtraction, If both of the operands are
equal, zero flag is set.
 If the source operand is greater than the destination, carry flag is set or else, carry flag is reset.
Arithmetic Instructions
 AAA - ASCII Adjust After Addition
 AAS - ASCII Adjust AL after Subtraction
 AAM - ASCII Adjust AL after Multiplication
 AAS - ASCII Adjust AL after Division
 Usage: AAA or AAS or AAM or AAD

 The AAA instruction is executed after an ADD


instruction that adds two ASCII coded
operands to give a byte of result in AL.

Note: The CF only affected but the remaining flags are unaffected.
Arithmetic Instructions
 DAA - Decimal Adjust after Addition
 DAS - Decimal Adjust after Subtraction
 Usage: DAA/DAS

 DAA/DAS These instructions are used to


convert the result of the addition of two
packed BCD numbers to a valid BCD
number.

Note: the CF and AF are set to 1. Otherwise, the CF and AF are set to 0, the result
needs no correction.
Arithmetic Instructions
 MUL: Unsigned Multiplication Byte or Word
 Usage: MUL destination, source
 The unsigned byte or word may be in any one of the general purpose
registers or memory locations.

Note: Immediate operand is not allowed in this instruction. If the most significant
byte or word of the result is '0’, CF and OF both will be set.
Arithmetic Instructions
 IMUL: Signed Multiplication Byte or Word
 Usage: IMUL destination, source
 This instruction multiplies a signed byte in source operand by a signed
byte or word.
Arithmetic Instructions
 DIV/IDIV – Unsigned/Signed Division
 Usage: DIV/IDIV destination, source

 The result will be in AL as quotient, while AH will contain the remainder.

Note: This instruction does not affect any flag.


Logical Instructions
 AND - Logical AND
 Usage: AND destination, source
 This instruction bit by bit ANDs the source operand that may be an
immediate, a register or a memory location to the destination

Note: Both the operands cannot be memory locations or immediate operands.


Logical Instructions
 OR - Logical OR
 Usage: OR destination, source
 This instruction bit by bit ORs the source operand that may be an
immediate, a register or a memory location to the destination

Note: Both the operands cannot be memory locations or immediate operands.


Logical Instructions
 NOT - Logical NOT
 Usage: NOT destination/source
Logical Instructions
 XOR - Logical XOR
 Usage: XOR destination, source
 This instruction bit by bit XORs the source operand that may be an
immediate, a register or a memory location to the destination

Note: Both the operands cannot be memory locations or immediate operands.


Logical Instructions
 SHL – Shift Logical Left
 Usage: SHL destination, source
 This instruction shifts the operand word or byte bit-by-bit to the left
and insert zeros in the newly introduced least significant bits.

Note: All flags are affected depending upon the result, it is to be noted here that the
shift operation is through carry flag.
Logical Instructions
 SHR – Shift Logical Right
 Usage: SHR destination, source
 This instruction shifts the operand word or byte bit-by-bit to the right
and insert zeros in the newly introduced most significant bits.

Note: All flags are affected depending upon the result, it is to be noted here that the
shift operation is through carry flag.
Logical Instructions
 SAL/SAR – Shift Arithmetic Left/Right
 Usage: SAL/SAR destination, source
 This instruction shifts the operand word or byte bit-by-bit to the right
or left through carry flag.
Logical Instructions
 ROR – Rotate Right without Carry
 Usage: ROR destination, source
 This instruction rotates the operand word or byte bit-by-bit to the right
either one or by the count specified in the CX.

Note: All flags are affected depending upon the result, it is to be noted here that the
shift operation is through carry flag.
Logical Instructions
 ROL – Rotate Left without Carry
 Usage: ROR destination, source
 This instruction rotates the operand word or byte bit-by-bit to the left
either one or by the count specified in the CX.

Note: All flags are affected depending upon the result, it is to be noted here that the
shift operation is through carry flag.
Logical Instructions

 RCL/RCR – Rotate Left with Carry


 Usage: ROR destination, source
 This instruction rotates the operand word or byte bit-by-bit of the
destination right/left by the count specified in the CX through a CF.
Branching Instructions
 These instructions transfer the flow of execution of the program to a
new address specified in the instruction directly or indirectly.

 When this type of instruction is executed, the CS and IP registers get


loaded with new values.

 This type of instructions are classified in two types:


i. Unconditional Branch Instructions
ii. Conditional Branch Instructions
Unconditional Branch Instructions
 CALL: Unconditional Call
 Usage: CALL label
 This instruction is used to call a subroutine
from a main program.

 RET: Return
 Usage: RET
 Return from the Procedure at each CALL
instruction, the IP and CS of the next
instruction is pushed onto stack.
Unconditional Branch Instructions
 INT N: Interrupt Type N
 Usage: INT N-Value
 When an INT N instruction is executed, the TYPE byte N is multiplied by
4, which contains the IP and CS values of the interrupt service routine.

INTO: Interrupt on Overflow This command is executed, when the overflow flag OF
is set.
Unconditional Branch Instructions
 JMP: Unconditional Jump
 Usage: JMP destination
 This instruction unconditionally transfers the control of execution to the
specified address using an 8-bit or 16-bit displacement.
Types of Jump instructions
 An intrasegment (within segment) - near jump-needs a new value for IP.

 jump location may be in a different segment – i.e. inter segment -then it is


called a far jump –needs a new value for CS and IP
JMP -features
 Jumping can be backward or forward in the program sequence
 Jumping can be unconditional, Then the format of the jump
instruction is JMP label, where label is the address of the destination
 JMP can be conditional
Unconditional Branch Instructions
 LOOP: Loop Unconditionally
 Usage: LOOP Label
 This instruction executes the part of the program from the label or
address specified in the instruction up to the loop instruction.
Conditional LOOP instructions
 LOOP can be combined with other conditions, to make it a conditional
instruction.
 LOOPNE / LOOPNZ and LOOPE / LOOPZ can be used.
 These instructions test the zero flag, as well as the value of CX
Conditional Branch Instructions
When these instructions are executed, execution control is transferred to the
address specified relatively in the instruction, provided the condition implicit in the
opcode is satisfied, If not the execution continues sequentially.

 The conditions, means the status of condition code flags.


 These type of instructions do not affect any flag.
 In other words, only short jumps can be implemented using conditional
branch instructions.
 A label may represent the displacement, if it lies within the above
specified range.
CONDITIONAL JUMPS
 Conditional jumps are the best part of the idea of control transfer. They
change the sequence of program execution based on the result of a
computation which causes flag bits to be set or reset.

 However, there is one case ( JCXZ) where the register content is checked.

 Note All conditional jumps are short jumps.


List of Conditional Jump Instructions which Cater to Unsigned
Arithmetic and which Directly Address Flags or Registers
List of conditional jumps-contd’
FAR Jump
 A far jump is an intersegment jump, which means that the destination
address is in a different code segment.
 This will be a 5-byte instruction, the first byte being the opcode, the
second and third, the new value of IP, and the fourth and fifth, the new
values of CS.
Format of the far jump instruction
Flag Manipulation Instructions
 These instructions directly modify some of the flags of 8086, and the
machine control instructions control the bus usage and execution.
String Manipulation Instructions
 A series of data bytes or words available in memory at consecutive
locations, to be referred as collectively or individually, are called as
byte strings or word strings.

 A string of characters may be located in consecutive memory locations,


where each character may be represented by its ASCII equivalent.

 For referring to a string, two parameters are required, (a) starting or end
address of the string and (b) length of the string.

 Repeat Instruction is used as a prefix to string instructions.


String Manipulation Instructions
 MOVSB/MOVSW: Move String Byte or String Word: Suppose a string
of bytes stored in a set of consecutive memory locations is to be moved to
another set of destination locations.
 CMPS: Compare String Byte or String Word: The CMPS instruction
can be used to compare two strings of bytes or words. The length of the
string must be stored in the register CX.
 SCAS: Scan String Byte or String Word: This instruction scans a string
of bytes or words for an operand byte or word specified in the register AL
or AX. The string is pointed to by ES:DI register pair.
String Manipulation Instructions
 LODS: Load String Byte or String Word: The LODS instruction loads
the AL/AX register by the content of a string pointed to by DS:SI register
pair.

 STOS: Store String Byte or String Word: The STOS instruction stores
the AL/AX register con- tents to a location in the string pointed by ES: DI
register pair.
String Manipulation Instructions
Example Programme
Convert a packed BCD byte to two unpacked bytes.
Example Programme
Find the values in the destination for each line of this program segment.
Thank You

You might also like