MP Module 2 - Modified - Correct
MP Module 2 - Modified - Correct
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
=======================================================
--------------------------------------------------------------------------------------
Arithmetic Instructions
I. Addition Instructions
III. Multiplication and Division Instructions: MUL, DIV, IMUL, IDIV, AAM,
AAD, CBW &CWD
--------------------------------------------------------------------------------------
Addition Instructions
1. ADD
• add a number from source to a number in destination and put the result in the
specified destination..
E.g.
E.g.:
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
• 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.:
• It subtracts the two operands and also the borrow from the result.
Both SBB and SUB instructions affect AF, CF, OF, PF, SF, ZF flags.
3. DEC
• It is used to make sure that the result of subtracting two BCD numbers is adjusted
to be a correct BCD number.
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
• 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
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
Logical Instructions
Logical instructions are the instructions which perform basic logical operations
such as AND, OR, NOT,XORetc.
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
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).
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).
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.
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)
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.
ROL AL, 1
Result Cf=1;
AL=0000 0011
ROL AL, 1
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
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
RCL AL, 1
RCL AL,1
this instruction rotates all the bits in a specified word or byte some number of bit
positions to right.
CMP
This instruction compares a byte / word in the specified source with a byte / word
in the specified destination.
CF ZF SF
CX=BX 0 1 0 Result of substraction is 0
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.
LOOP
LOOPE / LOOPZ
LOOPNE / LOOPNZ
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
There are very strong set of string instructions in 8086 includes instruction for
string movement, comparison, scan, load and store.
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.
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
This instruction compare a byte / word in one string with a byte / word in another
string.
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 Repeats the operation MOVSB until CX becomes zero. It copies byte by
byte contents
-----------------------------------------------------------------------------
These instructions control the processor itself. 8086 allows to control certain
control flags that causes the processing in a certain direction.
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
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.
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.
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 ah,1
Int 21h