0% found this document useful (0 votes)
51 views

MP Module 2 - Modified - Correct

The document discusses the instruction set and various categories of instructions for the 8086 microprocessor. It describes that instructions are classified into 7 categories: data transfer, arithmetic, logical, control transfer, processor control, string manipulation, and interrupt control. It then provides details about specific instructions for data transfer (MOV, XCHG, etc.), arithmetic (ADD, SUB, INC, etc.), logical (AND, OR, NOT, etc.), and multiplication and division (MUL, DIV, IMUL, etc.). Examples are given for many of the instructions.

Uploaded by

akhil krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

MP Module 2 - Modified - Correct

The document discusses the instruction set and various categories of instructions for the 8086 microprocessor. It describes that instructions are classified into 7 categories: data transfer, arithmetic, logical, control transfer, processor control, string manipulation, and interrupt control. It then provides details about specific instructions for data transfer (MOV, XCHG, etc.), arithmetic (ADD, SUB, INC, etc.), logical (AND, OR, NOT, etc.), and multiplication and division (MUL, DIV, IMUL, etc.). Examples are given for many of the instructions.

Uploaded by

akhil krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 24

Module 2

Instruction Set
• An instruction is a binary pattern designed inside a microprocessor to perform a
specific function.
• The entire group of instructions that a microprocessor supports is called
Instruction Set.
• In assembly language each instruction is represented by a “mnemonic” that
describes its operation and is called its “operation code (opcode)”.
• example
 MOV : move - data transfer
 ADD : add - arithmetic
 JMP :unconditional jump-control transfer
8086 Instructions
• The 8086 Instructions are organized into groups of functionally related
instructions and classified into 7 categories:
1. Data Transfer
2. Arithmetic
3. Logical
4. Control Transfer
5. Processor Control Instructions
6. String Manipulation
7. Interrupt Control
=======================================================

Data Transfer Instructions


 These instructions are used to transfer data from source to destination.
 Source can be Register or a memory location or an immediate data and
Destination can be Register or a memory location.

 The different data transfer instructions are:


• MOV
• XCHG
• XLAT
• LEA
• LDS
• LES Instructions
==========================================================
1. MOV: copies operand from source to destination

 Syntax : MOV Des, Src:


 Src operand can be register, memory location or immediate data.
 Des can be register or memory operand.
 Both Src and Des cannot be memory location at the same time.
examples
 MOV CX, 037AH ; Put immediate number 037AH to CX

 MOV BL, [0050H]; Copy byte in DS at offset 0050h to BL

 MOV AX, BX ; Copy content of register BX to AX


 MOV DL, [BX] ; Copy byte from memory at [BX] to DL

2. XCHG: The Exchange instruction

 Syntax : XCHG Des, Src:


• This instruction exchanges Src with Des
• It cannot exchange two memory locations directly.

--------------------------------------------------------------------------------------
Arithmetic Instructions

These instructions are used to perform arithmetic operations like addition,


subtraction, multiplication, division, etc.

I. Addition Instructions

ADD, ADC, INC, AAA and DAA

II. Subtraction Instructions:

SUB, SBB, DEC, AAS, DAS, NEG

III. Multiplication and Division Instructions: MUL, DIV, IMUL, IDIV, AAM,
AAD, CBW &CWD
--------------------------------------------------------------------------------------

Addition Instructions

1. ADD

syntax: ADD Des, Src:

• add a number from source to a number in destination and put the result in the
specified destination..

E.g.

a) ADD AL, 74H ;

Add immediate number 74H to content of AL. Result in AL

b) ADD DX, AX ; Add content of AX to content of DX

c) ADD DX, [SI]

Add word from memory at offset [SI] in DS to content of DX


2. ADC Instruction - Add with carry

syntax: ADC Des, Src:

• It adds the two operands with CF.

E.g.:

a. ADC CL, BL ;Add content of BL plus carry status to content of CL

b. ADC DX, AX ;Add content of AX with carry to content of DX

c. ADC AX, [BX] ;Add word from memory at offset [BX] and carry with
content of AX

Both ADD and ADC instructions affect AF, CF, OF, PF, SF, ZF flags.

3. INC

syntax: INC Destination

The INC instruction adds 1 to a specified register or to a memory location.

INC BL ; Add 1 to contains of BL register

It effects AF, OF, PF, SF, ZF flags.

4. 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 any operand.


5. 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

Subtraction Instructions:

1. SUB Des, Src: subtract the number in source from the number in destination and
put the result in the destination.

• E.g.:

a. SUB CX, BX ; CX – BX; Result in CX

b. SUB AX, 3427H ; Subtract immediate number 3427H from AX


2. SBB- Subtract with borrow

Syntax : SBB Des, Src:

• It subtracts the two operands and also the borrow from the result.

• E.g.: SBB CH, AL ; Subtract content of AL and content of CF from content of


CH. Result in CH

• SBB BX, [3427H] ;Subtract word at displacement 3427H in DS and content of


CF from BX

Both SBB and SUB instructions affect AF, CF, OF, PF, SF, ZF flags.

3. DEC

It subtracts 1 from the destination word or byte.

Syntax :DEC Destination

• It effects AF, OF, PF, SF, ZF flags.

DEC CL ; Subtract 1 from content of CL register

DEC BP ; Subtract 1 from content of BP register

4. 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.

Instructions to perform addition


o ADD − Used to add the provided byte to byte/word to word.
Eg: ADD AL,BL // Contents of AL and BL are added
together and
sum is stored in AL
ADD AX,BX// Contents of AX and BX are added together
and
sum is stored in AX
5. AAS (ASCII Adjust after Subtraction)
• The AAS instruction is then used to make sure the result is the correct unpacked
BCD.
• The AAS instruction works only on the AL register.
6. NEG
Syntax : NEG Destination
• This instruction replaces the number in a destination with its 2’s
complement.

Multiplication Instructions
1. MUL Src: unsigned multiplication instruction. Src can be a register or memory
location.
• This instruction assumes one of the operand in AL or AX.
• When two bytes are multiplied −

The multiplicant is in the AL register, and the multiplier is a byte in the memory
or in another register. The product is in AX. High-order 8 bits of the product is
stored in AH and the low-order 8 bits are stored in AL.

• When a byte is multiplied by the content of AL, the result (product) is put in AX.
i.e AX = AL * Src

Eg:MUL BL // AX [AL] x [BL]


When two word values are multiplied −
The multiplicant should be in the AX register, and the multiplier is a word in
memory or another register.
The resultant product is a doubleword, which will need two registers. The high-order
(leftmost) portion gets stored in DX and the lower-order (rightmost) portion gets stored
in AX.

• When a word is multiplied by the content of AX, the result is put in DX and AX
registers.
i.e DX : AX = AX * Src

2. IMUL Src: It is a signed multiplication instruction.


3. AAM (ASCII Adjust after Multiplication)-
• AAM converts the result of the multiplication of two valid unpacked BCD digits
into a valid 2-digit unpacked BCD number

Division Instructions
• DIV : It is an unsigned division instruction. It divides word by byte or double
word by word.
Syntax: DIV divisor
The dividend is in an accumulator. The operation affects all six status flags.
When the divisor is a byte −
The dividend is assumed to be in the AX register (16 bits). After division, the quotient
goes to the AL register and the remainder goes to the AH register.

• The operand is stored in AX, divisor is 8bit, then the result is stored as: AH =
remainder , AL = quotient
example
DIV BL ; Divide word in AX by byte in BL; Quotient in AL, remainder in AH
When the divisor is a word −
The dividend is assumed to be 32 bits long and in the DX:AX registers. The high-order
16 bits are in DX and the low-order 16 bits are in AX. After division, the 16-bit quotient
goes to the AX register and the 16-bit remainder goes to the DX register.

example
DIV CX ; Divide double word in DX and AX by word in CX; Quotient in
AX, and remainder in DX

2. IDIV Src: It is a signed division instruction.


examples
• IDIV BL ;Signed word in AX/signed byte in BL
• IDIV BP
; Signed double word in DX and AX/ signed word in BP
3. AAD (ASCII Adjust Before Division)
• AAD converts unpacked BCD digits in the AH and AL register into a single
binary number in the AX register in preparation for a division operation.

Logical Instructions
 Logical instructions are the instructions which perform basic logical operations
such as AND, OR, NOT,XORetc. 

o AND, OR, NOT, and XOR instructions


o shift instructions
SHL, SAL, SHR and SAR
o Rotate instructions
ROL, ROR, RCL and RCR
o Compare instruction
CMP

Instructions to perform logical operations are


AND
 syntax : AND dest, src
 It perform AND operation of Dest and Src
 Eg. AND BH, CL ; AND byte in CL with byte in BH, Result in BH

OR
 syntax : OR dest, src
 It perform OR operation of Dest and Src
 Eg. OR AH, CL ; CL ORed with AH, Result in AH, CL note changed
NOT
 syntax : NOT dest
 Used to invert each bit in destination.
 The operand could be either register or in memory.
 Eg. NOT BX ; Complement content in BX register

XOR
 syntax : XOR dest, src
 Used to perform Exclusive-OR operation of Dest and Src
 If the bits from the operands are different, the XOR operation sets the resultant bit
to 1.If the bits from the operands are same (both 0 or both 1), sets the resultant bit
to 0
 XORing an operand with itself changes the operand to 0.This is used to clear
register
 Eg. XOR CL, BH ; bite in BH XORed with byte in CL, Result in CL, BH note
changed

shift Instructions
SHL: Shift left and append 0s on right

 Syntax : SHL destination, count

 This instruction shifts each bit in the destination some number of bit positions to
the left.

 Inserting the same number (bits that are being shifted) of zeroes to the LSB (right
end).

 The MSB (leftmost bit) will be shifted into CF (Carry flag).

 Eg.SHL AX, 1 ; Shift word AX 1 bit position left, 0 in LSB.

SAL : Shift Arithmetic Left

 Syntax : SAL destination, count

 This instruction is the same as SHL.

 Eg.SAL BX, 1 ; Shift word BX 1 bit position left, 0 in LSB

SHR : Shift Right append 0s on left

 Syntax : SHR destination, count

 This instruction shifts each bit in the destination some number of bit positions to
the right
 Inserting the same number (bits that are being shifted) of zeroes to the MSB (left
end).

 The LSB (rightmost bit) will be shifted into CF (Carry flag).

 Eg.SHR BP, 1 ; Shift word BP 1 bit position right, 0 in MSB.

SAR : Shift Arithmetic Right

 Syntax : SAR destination, count

 Shift right retain a copy of the sign-bit and shift all bits to right

 This instruction shifts each bit in the destination some number of bit positions to
the right side.

 The LSB (rightmost bit) will be shifted into CF (Carry flag).

 A copy of old MSB is put in the MSB position. ie,The sign bit is copied into the
MSB.
 Eg.SAR DX, 1 ; Shift word DX one bit position right, new MSB = old MSB.

Rotate Instructions
ROL : Rotate Left (into carry as well as into LSB)

 Syntax : ROL destination, count

 This instruction rotates all the bits in a specified word or byteto the left some
number of bit positions.

 The dete bit rotated out of MSB is circled backinto the LSB. It also copied into
CF.

 CF will contain a copy of bit most recently moved out of the MSB.
 Eg. ROL AX, 1 ; Rotate the word in AX one bit position left, MSB to LSB and
CF.

 Suppose CF=0 and AL= 1000 0001

 ROL AL, 1

 Result Cf=1;

 AL=0000 0011

 ROL AL, 1

 CF=0, AL=0000 0110

ROR : Rotate Right (into arry as well as into MSB)

 Syntax : ROR destination, count

 This instruction rotates all the bits in a specified word or byte some number of bit
positions to right.

 The data bit moved out of the LSB is also copied into CF.

 CF will contain a copy of the bit most recently moved out the LSB.

 Eg. ROR BL, 1 ; Rotate all bits in BL right, one bit position LSB to MSB and
to CF

RCL : Rotate Left through carry


 Syntax : RCL destination, count

 This instruction rotates all the bits in a specified word or byte some number of bit
positions to left.

 The operation is circular because the MSB of the operand is rotated into the carry
flag and the bit in the carry flag is rotated around into LSB of the operand

 Eg. RCL DX, 1 ; word in DX 1 bit left, MSB to CF, CF to LS

 suppose CF=0 and AL =1000 0001

 RCL AL, 1

 result CF=1; AL=0000 0010

 RCL AL,1

 CF=0, AL=0000 0101

RCR : Rotate right through carry

 Syntax : RCR destination, count

 this instruction rotates all the bits in a specified word or byte some number of bit
positions to right.

 Eg. RCR BX, 1 ; word in bx right 1 bit, CF to MSB, LSB to CF


compare instruction

CMP

 Syntax : CMP dest, src

 This instruction compares a byte / word in the specified source with a byte / word
in the specified destination.

 CF, ZF and SF are used.

 Eg. CMP CX,BX

CF ZF SF
CX=BX 0 1 0 Result of substraction is 0

CX>BX 0 0 0 No borrow, so CF=0

CX<BX 1 0 1 Requires borrow, CF=1

PROGRAM CONTROL AND TRANSFER INSTRUCTIONS

Subroutines and subrutine handling instructions

1. CALL: Call a procedure

 The CALL instruction is used to transfer execution to subprogram or a procedure.

 The address of next instruction after CALL is saved on to stack.

2. RET : It returns the control from procedure to calling program

Unconditional jump instruction

JMP : This instruction is used for unconditional jump from one place to specified
destination.
Conditional jump instructions: Transfer control depending on settings in the flags
register.

Loops and Loop handling instructions

LOOP

 This instruction is used to repeat a series of instructions some number of times,

 the number of times looping is required is placed in the CX register.

 With each iteration, the contents of CX are decremented.

 ZF is checked whether to loop again or not.

LOOPE / LOOPZ

 Loop while CX is not equal to zero and ZF = 1.

LOOPNE / LOOPNZ

 Loop while CX is not equal to zero and ZF = 0.

In all above LOOP instructions the destination of jump is in the range of -128 to +127
byes from the address after LOOP
STRING AND STRING HANDLING INSTRUCTIONS

String in assembly language is just a sequentially stored bytes or words.

 There are very strong set of string instructions in 8086 includes instruction for
string movement, comparison, scan, load and store.

 by using these string instructions, the size of program is considerably reduced

 For using string instructions, do the following

o Two segments (DS and ES) need to be defined.

o Data segment is the source segment and extra segment is the destination
segment.SI register points to data segment and DI points to extra segment.
o The control flag DF (Direction Flag) is used.If DF=0, registers are
automatically incremented.If DF =1, registers are automatically
decremented.
o The CX register should be loaded with the count of the number of
operations required.

MOVS / MOVSB / MOVSW

 These instructions moves data byte or word from location in DS to location in ES.

 The offset of the source in the data segment must be in the DS register.

 The offset of the destination in the ES(extra segment) must be in the DI register.

 MOVS

Syntax : MOVS Destination string name, source string name

 MOVSB : Move a sring as byte

Syntax : MOVSB Destination string name, source string name

 MOVSW: Move a string as byte

Syntax : MOVSW Destination string name, source string name


CMPS / CMPSB / CMPSW

 Compare string bytes or string words.

 This instruction compare a byte / word in one string with a byte / word in another
string.

SCAS / SCASB / SCASW

 Scan a string byte or string word.

 This instruction compares the string with byte in AL or with word in AX with a
byte or a word in ES pointed to by DI.

 Example:- pgm searches the string for the presence of character ‘s’

REP / REPE / REPZ / REPNE / REPNZ (PREFIX)

 Repeat string instruction until specified conditions exit.

 REP (Repeat) : This is an instruction prefix. Repeat execution of string


instructions while cx is not Zero.

 It causes the repetition of the instruction until CX becomes zero.

 Eg. REP MOVSB STR1, STR2

REP Repeats the operation MOVSB until CX becomes zero. It copies byte by
byte contents

 REPE/REPZ- Repeat execution of string instructions while cx is not Zero and


while zero flag is set.

 REPNE / REPNZ - Repeat execution of string instructions while cx is not Zero


and while zero flag is NOT set.

STOS / STOSB / STOSW

 Store a byte or word in a string.

 Copies a byte or word in AL or AX to memory location pointed by DI


LODS / LODSB / LODSW

 Store a byte or word in AL or AX.

 Copies bytes or word from memory location pointed by SI into AL or AX


register.

-----------------------------------------------------------------------------

PROCESSOR CONTROL INSTRUCTIONS

 These instructions control the processor itself. 8086 allows to control certain
control flags that causes the processing in a certain direction.

 Processor synchronization if more than one microprocessor attached.

1. CLC : Clear Carry flag.


2. STC : Set carry Flag
3. CMC : Complement Carry Flag
4. CLD : Clear Direction Flag.
5. STD: Set Direction Flag
6. CLI :Clear Interrupt Flag.
7. STI : Set Interrupt Flag.8.HLT: Halt Processing-This instruction causes the
8086 to stop fetching and executing instructions.
9. NOP : No Operation-can be used to increase the delay of a delay loop
10. ESC: Escape-used to pass instructions to a coprocessor. Instructions for the
coprocessor are represented by a 6-bit code embedded in the ESC instruction
11. LOCK : Assert bus lock Signal
Many microcomputer systems contain several microprocessors. Each
microprocessor has its own local buses and memory
The LOCK prefix allows a microprocessor to make sure that another
processor does not take control of the system bus while it is in the middle
of a critical instruction using the system bus
12. WAIT :Assert wait states- When this instruction is executed, the 8086 enters
an idle condition in which it is doing no processing
INTERRUPT CONTROL INSTRUCTIONS

1. INT type
The term type in the instruction format refers to a number between and 255,
which identify the interrupt.
2. INTO -Interrupt on overflow
If the overflow flag (OF) is set, this instruction causes the 8086 to do an indirect
call to a procedure you write to handle the overflow condition.
3. IRET -Interrupt return
The IRET instruction is used at the end of the interrupt service procedure to return
execution to the interrupted program

Important Questions

1. Explain the data transfer instructions with example.


2. Explain arithmetic instructions with examples.
3. Explain shift and rotate instructions with examples.
4. List different jump instructions in 8086
5. Write the syntax and meaning of XCHG instruction in 8086
ASSEMBLER DIRECTIVES

 Assembler directives are the commands to the assembler but are not related to
the 86 processor instruction.
 They direct the assembler how program and data should be arranged in the
memory.
 Directives do not generate any machine code.
 i.e. they do not contribute to the final size of machine code.
 Directives are assembler specific.

1. ASSUME :Used to tell assembler the name of logical segment.


Eg. ASSUME CS: Code here
2. SEGMENT : Defines the segment name and specifies that the code that
follows is in that segment.
3. ENDS : End of segment
4. END : End of source code.
5. PROC : procedure
6. Endp : end of procedure
7. DB : Define byte.
8. DW : Define word (2 bytes)
9. EQU : equate, assign numeric expression to a name
Examples:
o db 100 dup (?) define 100 bytes, with no initial values for bytes

o db “Hello” define 5 bytes, ASCII equivalent of “Hello”.

o Maxint equ 32767

10. OFFSET : returns the distance of a variable from the beginning of its
segment.
11. CODE : mark start of code segment
12. DATA : mark start of data segment
13. STACK : set size of stack segment
14. ORG : Originate or Origin:
Eg. Org 100h :It tells compiler that the executable file will be loaded at the
offset of 100h (256 bytes)
so compiler should calculate the correct address for all variables when it
replaces the variable names with their offsets.

Difference between Macro and Procedure


Assembly language is a common intermediate level programming language
which is used for microprocessor programming. This macro and procedure are two
concepts in assembly by which modular programming is implemented. So now
let’s understand how macro and procedure are different from each other. 
1. Macro : 
Macro is a set of instruction and the programmer can use it anywhere in the
program by using its name. It is mainly used to achieve modular programming. So
same set of instructions can be used multiple times when ever required by the help
of macro. Wherever macro’s identifier is used, it is replaced by the actual defined
instructions during compilation thereby no calling and return occurs. 
Syntax of macro : 

%macro macro_name number_of_parameters


<macro body>
%endmacro

2.Procedure : 
Procedures are also like macro, but they are used for large set of instruction when
macro is useful for small set of instructions. It contains a set of instructions which
performs a specific task. It contains three main parts i.e Procedure name to identify
the procedure, procedure body which contains set of instructions, and RET
statement which denotes return statement. Unlike macros, procedures follow call-
return method thereby achieving true modularity.
Syntax of Procedure : 
procedure_name :

procedure body
….......................
RET
To call a procedure 
 
CALL procedure_name
After execution of procedure control passes to the calling procedure using RET
statement. 
Difference between Macro and Procedure : 
 
S.No. MACRO PROCEDURE
Macro definition contains a set of Procedure contains a set of instructions
instruction to support modular which can be called repetitively which
01. programming. can perform a specific task.
It is used for small set of instructions It is used for large set of instructions
02. mostly less than ten instructions. mostly more than ten instructions.
In case of macro memory requirement is In case of procedure memory requirement
03. high. is less.
CALL and RET instruction/statements CALL and RET instruction/statements
04. are not required in macro. are required in procedure.
Assembler directive MACRO is used to Assembler directive PROC is used to
define macro and assembler directive define procedure and assembler directive
ENDM is used to indicate the body is ENDP is used to indicate the body is
05. over. over.
Execution time of macro is less than it Execution time of procedures is high as it
06. executes faster than procedure. executes slower than macro.
Here machine code is created multiple Here machine code is created only once,
times as each time machine code is it is generated only once when the
07. generated when macro is called. procedure is defined.
In a macro parameter is passed as part of In a procedure parameters are passed in
08. statement that calls macro. registers and memory locations of stack.
Overhead time takes place during calling
Overhead time does not take place as procedure and returning control to calling
09. there is no calling and returning. program.
 

Mov destination,source
Mov al,05h

mov dl, ’A’


MOV AH,2h
Int 21h

From key board

Mov ah,1
Int 21h

You might also like