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

Instruction Set

The document outlines the instruction set of the 8086 microprocessor, categorizing instructions into data transfer, binary arithmetic, decimal arithmetic, logical, shift/rotate, and control transfer instructions. It details specific instructions such as MOV, ADD, PUSH, POP, IN, OUT, and various arithmetic operations, explaining their functions and effects on the flag register. Additionally, it highlights the significance of data transfer instructions, particularly noting that they do not affect flags except for the POPF instruction.

Uploaded by

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

Instruction Set

The document outlines the instruction set of the 8086 microprocessor, categorizing instructions into data transfer, binary arithmetic, decimal arithmetic, logical, shift/rotate, and control transfer instructions. It details specific instructions such as MOV, ADD, PUSH, POP, IN, OUT, and various arithmetic operations, explaining their functions and effects on the flag register. Additionally, it highlights the significance of data transfer instructions, particularly noting that they do not affect flags except for the POPF instruction.

Uploaded by

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

8086 Instruction

Set - 1instructions (including I/O


Data transfer
1.
transfers),
2. Binary arithmetic instructions,
3. Decimal (BCD, ASCII) arithmetic instructions,
4. Logical instructions,
5. Shift and rotate instructions,
6. Control transfer instructions.

03/13/25 1
1 2 3 4 5 6
MOV, ADD, DAA, AND, SHL, JMP,
XCHG, ADC, DAS, OR, SHR, JA/JNBE,
PUSH, SUB, AAA, XOR, SAL, JAE/JNB/
POP,IN, SBB, AAS, NOT, SAR, JNC,
OUT, CMP, AAM, TEST ROL, JB/LANE/
CBW, MUL, AAD ROR, JC, JBE/
CWD IMUL, RCL, JNA,
DIV, RCR JCXZ,
IDIV, JE/JZ,
INC, JO, JG/JNLE,
DEC, JP/JPE,J JGE/JNL,
NEG S,LOOP, JL/JNGE,
LOOPE/L JLE/JNG,
OOPZ, JNE/JNZ,
LOOPNE/ JNO,
LOOPNZ, JNA/JPO,
CALL,RE JNS
T,INT,
03/13/25 IRET 2
Data Transfer
Instructions

03/13/25 3
Data Transfer instructions essentially
copy the data and do not affect any flags
(except of course the POPF instruction
which modifies all the flags as per the
stack top word)

03/13/25 4
MOV
 Stands for move, it is actually copy, that is, when
data is moved from one register source to a
destination register, source is not destroyed,
there will be a copy of this data in the destination
register

03/13/25 5
XCHG
 Exchange instruction exchanges data between
registers or between register and memory

03/13/25 6
PUSH
 Push causes the data in the source register to
be copied on to the stack top

03/13/25 7
POP
 Pop causes the stack top moved to (that is,
removed from the stack and loaded onto) the
destination register or memory specified by the
instruction

03/13/25 8
IN: Copy data from a port
IN accumulator, port
 The IN instruction reads from an input port into
AL or AX (only these two registers), to be
specified in the instruction

 The port address is generally in the register DX

 But if it is 8-bits or less, then it can also be


directly given in the instruction

03/13/25 9
 Ex:
IN AL,0C8H;Input a byte from port address 0C8H to AL
IN AX,34H; Input a word from port address 034H to AX

MOV DX,0FF78H ;Initialize DX to point to port


IN AL, DX ;Input a byte from 8 bit port 0FF78h to AL
IN AX,DX ; Input a word from 16 bit port 0FF78h to AX

03/13/25 10
OUT: output a byte or word
to a port
OUT port, accumulator
 The OUT instruction outputs the data in register
AX or AL (only) to be specified in the instruction
to the output port indicated directly in the
instruction if the port address is 8 bits or less, or
in the register DX (for addresses 16 bits or less)

03/13/25 11
Examples:

out 16h, ax; write to output port at address 16h from reg. ax

out dx, ax; write to output port at address in dx from reg. ax

out 23h, al; write to output port at address 23h from reg al

out dx, al; write to output port at address in dx from reg al

03/13/25 12
CBW (Convert byte to word)
 The source register AL and the destination AX
are both implied and not specifically mentioned
in this instruction

 This instruction is used to extend the 8-bit


integer (signed number) in reg. AL to 16- bit
integer in AX

 The process is called sign extension

03/13/25 13
 If the number in AL is positive, AH will be loaded
with 00 hex, else AH will be loaded with FF hex

Example: cbw

03/13/25 14
CWD (Convert Word to
Double Word)
 Convert word in reg. AX (implied and not stated
in the instruction) to double word in regs. DX:AX
(also implied and not stated)

 That is, sign extend from AX into DX:AX

Example: cwd

03/13/25 15
Among all the data transfer instructions
popf is the only instruction that affects and
modifies the flags

03/13/25 16
 Which of the following is not a data
copy/transfer instruction?
a) MOV
b) PUSH
c) DAS
d) POP

03/13/25 17
Binary Arithmetic
Instructions

03/13/25 18
All binary arithmetic instructions update
the flag register based on the result of the
operation performed

03/13/25 19
ADD
 Adds the first operand (destination operand) and
the second operand (source operand) and
stores the result in the destination operand

 The destination operand can be a register or a


memory location; the source operand can be an
immediate, a register, or a memory location

 Two memory operands cannot be used in


one instruction

03/13/25 20
 When an immediate value is used as an operand, it is
sign-extended to the length of the destination operand
format

 The ADD instruction performs integer addition

DEST ← DEST + SRC;

 The OF, SF, ZF, AF, PF, and CF flags are set according
to the result

Examples: ADD AX, BX


ADD [BX + 4], DX
ADD CX, 2[SI]
ADD DX, 123 H
03/13/25 21
ADC
 Adds with carry

 Same as ADD with the following change in the


operation:

DEST ← DEST + SRC + CF;

 The OF, SF, ZF, AF, PF, and CF flags are set
according to the result

03/13/25 22
Example…
data segment
a db 0ABh
b db 0A5h
c dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
mov al, a
add al, b
mov ah, 00h
adc ah, 00h
mov c, ax
mov ah, 4ch
int 21h
code ends
end start

03/13/25 23
SUB
 Subtraction

 Follows the same rules as ADD with the


following change in the operation:

DEST ← DEST – SRC;

 The OF, SF, ZF, AF, PF, and CF flags are set
according to the result

03/13/25 24
SBB
 Subtract with borrow

 Same as SUB with the following change in the


operation:

DEST ← DEST – (SRC + CF);

 The OF, SF, ZF, AF, PF, and CF flags are set
according to the result

03/13/25 25
CMP
 Compare two operands

 Compares the first source operand with the second


source operand and sets the status flags in the
FLAGS register according to the results

 The comparison is performed by subtracting the


second operand from the first operand and then
setting the status flags in the same manner as the
SUB instruction

03/13/25 26
 When an immediate value is used as an operand, it is
sign extended to the length of the first operand

Operation:

temp ← SRC1 − SRC2;

 In case an immediate value is used, then


temp ← SRC1 − Sign Extend (SRC2);

 The CF, OF, SF, ZF, AF, and PF flags are set
according to the result

03/13/25 27
Examples:

CMP AX, 24 H; (24 is sign extended to 16 bits before


subtraction, because AX is a 16-bit register)

CMP BYTEPTR[BX], -24 H; (no sign extension done,


data in bytes are being handled)

CMP BX, SI

CMP AL, [BX]; (BX will be taken only as a byte pointer,


as AL is a byte register)

03/13/25 28
MUL

 Performs an unsigned multiplication of the first


operand (destination operand) and the second
operand (source operand) and stores the result
in the destination operand

 The destination operand is an implied operand


located in register AL or AX (depending on the
size of the operand)

03/13/25 29
 The source operand is located in a general-
purpose register or a memory location

Operation:

IF byte operation
THEN
AX ← AL ∗ SRC
ELSE (* word operation *)
DX:AX ← AX ∗ SRC

03/13/25 30
Flags Affected

The OF and CF flags are set to 0 if the upper half of


the result is 0; otherwise, they are set to 1

The SF, ZF, AF, and PF flags are undefined

Examples:
MUL BX
MUL WORDPTR [BX + DI]48 H
MUL BYTEPTR [SI]
MUL CL

03/13/25 31
IMUL : multiply signed numbers
IMUL source
 Integer (signed) multiply

 Similar to MUL, except the data are considered


as signed integers

 Flags are also affected similarly as for MUL

03/13/25 32
Examples:
IMUL BH ;Signed byte in AL times signed byte
in BH ; result in AX
;69x14
;AL=01000101=45h=69 decimal
;BH=0000 1110=0Eh=14 decimal
IMUL BH;AX=03C6H=+966 decimal
; MSB=0,positive result magnitude in true form.

;-28x59
;AL=11100100=E4H=-1CH=-28 decimal
;BH=00111011=3BH=+59 decimal
IMUL BH;AX=F98CH=-1652 decimal
;MSB=1,negative result magnitude in 2’s complement form.

03/13/25 33
DATA SEGMENT
C DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX

MOV AL,1CH
NEG AL

MOV BL,3BH
IMUL BL

MOV C,AX

MOV AH,4CH
INT 21H
CODE ENDS
END START

03/13/25 34
DIV:

 Divide the unsigned integer dividend in the


accumulator by the unsigned integer divisor
specified in the instruction

 If the divisor specified is a word register or word


memory, the dividend is considered to be the double
word in DX:AX and the quotient of division will be in
register AX, with the remainder in register DX and
the divisor word specified in the instruction will not
be altered

03/13/25 35
 If the divisor specified in the instruction is a byte
register or byte memory, then the accumulator
will be the word register AX

 The quotient of the division will be in AL register,


and AH register will have the remainder

03/13/25 36
 In case of word division, if the divisor word is not
greater than the part of the dividend word in DX,
then the quotient obviously will not fit into the
register AX

Execution of DIV instruction in such a case will


cause a division overflow exception to be
generated, and operating system should take
care of this exception

03/13/25 37
Examples of DIV instruction:

DIV BX;
DIV WORDPTR [DI];
DIV CL;
DIV BYTEPTR [SI];

03/13/25 38
IDIV : devide by signed byte or
word
IDIV source
 Integer divide, same as DIV but the data and the
results are considered as signed integers

 The CF, OF, SF, ZF, AF, and PF flags are


undefined, when IDIV is executed

03/13/25 39
Examples:
IDIV BH ;Signed word in AX/ signed byte in BH;

;AX=00000011 10101011=03ABH=939 decimal


;BH=1101 0011=D3=-2DH=-45 decimal
IDIV BH ;Quotient: AL=ECH=-14H=-20 decimal
;remainder: AH=27H=+39 decimal

03/13/25 40
INC
 Increment register or memory

 This involves only a single operand

 Adds 1 to the destination operand, while


preserving the state of the CF flag

 The destination operand can be a register or a


memory location

03/13/25 41
 This instruction allows a loop counter to be updated
without disturbing the CF flag

 If we use an ADD instruction with an immediate


operand of 1 to perform an increment operation that
does update the CF flag

Operation:
DEST ← DEST + 1;

 The CF flag is not affected. The OF, SF, ZF, AF,


and PF flags are set according to the result

03/13/25 42
Multiplication and Division
Multiplication and Division
DEC
 Similar to INC, this instruction does the
operation:
DEST ← DEST – 1;

 The CF flag is not affected

 The OF, SF, ZF, AF, and PF flags are set


according to the result

03/13/25 45
NEG: Form 2’s complement
NEG destination
 Replaces the value of operand (the destination
operand) with its two’s complement

 This operation is equivalent to subtracting the


operand from 0

 The destination operand is located in a general-


purpose register or a memory location
DEST ← – (DEST)

03/13/25 46
Flags Affected

 The CF flag set to 0 if the source operand is 0;


otherwise it is set to 1

 The OF, SF, ZF, AF, and PF flags are set


according to the result

 Ex: ;AL=0000 0110H=06H


NEG AL ; replace number in AL with its 2’s complement
;RESULT:1111 1010=FAH

03/13/25 47
Decimal (BCD,
ASCII) Arithmetic
Instructions

03/13/25 48
DAA: Decimal adjust accumulator
(AL) after BCD addition
 Adjusts the sum of two packed BCD values to
create a packed BCD result

 The AL register is the implied source and


destination operand

 The DAA instruction is only useful when it


follows an ADD instruction that adds (binary
addition) two 2 - digit, packed BCD values and
stores a byte result in the AL register

03/13/25 49
 The DAA instruction then adjusts the contents of
the AL register to contain the correct 2-digit,
packed BCD result

 If a decimal carry is detected, the CF and AF


flags are set accordingly

 If the lower nibble in AL after an addition is


greater than 9 or AF was set by the addition,
then the DAA instruction will add 6 to the lower
nibble in AL

03/13/25 50
 If the result in the upper nibble of AL is now
greater then 9 or if the carry flag was set by the
addition or correction, then DAA instruction will
add 60H to AL

03/13/25 51
Example 1:
; AL = 0101 1001 = 59 BCD
; BL = 0011 0101 = 35 BCD
ADD AL, BL ; AL = 1000 1110 = 8EH
DAA ; Add 0110 Because 1110 > 9
; AL = 1001 0100 = 94 BCD

03/13/25 52
Example 2:
; AL = 1000 1000 = 88 BCD
; BL = 0100 1001 = 49 BCD
ADD AL, BL ; AL = 1101 0001=D1h, AF = 1
DAA ; Add 0110 because AF=1
; AL = 1101 0111 = D7H
; 1101 > 9 so add 0110 0000
; AL = 0011 0111 = 37 BCD, CF
=1

03/13/25 53
Flags affected

 The CF and AF flags are set if the adjustment of


the value results in a decimal carry in either digit
of the result

 The SF, ZF, and PF flags are set according to


the result

 The OF flag is undefined

03/13/25 54
DAS: Decimal adjust after BCD
subtraction
 Adjusts the result of the subtraction of two packed
BCD values to create a packed BCD result

 The AL register is the implied source and


destination operand

 The DAS instruction is only useful when it follows a


SUB instruction that subtracts (binary subtraction)
one 2-digit packed BCD value from another and
stores a byte result in the AL register

03/13/25 55
 The DAS instruction then adjusts the contents of the
AL register to contain the correct 2-digit, packed
BCD result

 If a decimal borrow is detected, the CF and AF flags


are set accordingly

 The CF and AF flags are set if the adjustment of the


value results in a decimal borrow in either digit of
the result

 The SF, ZF, and PF flags are set according to the


result. The OF flag is undefined

03/13/25 56
Examples:
;AL=1000 0110=86BCD
; BH=0101 0111=57BCD
SUB AL,BH ;AL=0010 1111=2FH,CF=0
DAS ;Lower nibble of result is 1111,so DAS automatically subtracts
0000 0110 to give AL=0010 1001=29BCD

;AL=0100 1001=49BCD
;BH=0111 0010=72BCD
SUB AL,BH ;AL=1101 0111=D7H,CF=1
DAS ;Subtracts 0110 0000(-60H) bcoz 1101 in upper nibble >9
;AL=01110111=77BCD,CF=1
;CF=1 means borrow was needed

03/13/25 57
AAA: ASCII adjust AL after
addition
 Adjusts the sum of two unpacked BCD values to
create an unpacked BCD result

 The AAA instruction works only on the AL


register .It is the implied source and destination
operand for this instruction

 The AAA instruction is only useful when it


follows an ADD instruction that adds (binary
addition) two unpacked BCD values and stores a
byte result in the AL register
03/13/25 58
Example:
;assume AL=0011 0101,ASCII5 BL=0011 1001,ASCII 9

ADD AL,BL; Result: AL=01101110=6EH,Which is


incorrect BCD

AAA; Now AL=0000 0100,Unpacked BCD 4.


;CF=1 indicates answer is 14 decimal

03/13/25 59
 The AAA instruction then adjusts the contents of the
AL register to contain the correct 1-digit unpacked
BCD result

 If the addition produces a decimal carry, the AH


register increments by 1, and the CF and AF flags
are set

 If there was no decimal carry, the CF and AF flags


are cleared and the AH register is unchanged

 In either case, bits 4 through 7 of the AL register are


set to 0
03/13/25 60
 The AF and CF flags are set to 1 if the
adjustment results in a decimal carry otherwise
they are set to 0

 The OF, SF, ZF, and PF flags are undefined

03/13/25 61
IF ((AL AND 0FH) > 9) OR (AF = 1)
THEN
AL ← AL + 6;
AH ← AH + 1;
AF ← 1;
CF ← 1;
ELSE
AF ← 0;
CF ← 0;
AL ← AL AND 0FH;

03/13/25 62
AAS: ASCII adjust AL after
subtraction
 Adjusts the result of the subtraction of two
unpacked BCD values to create a unpacked BCD
result

 The AL register is the implied source and


destination operand for this instruction

 The AAS instruction is only useful when it follows


a SUB instruction that subtracts (binary
subtraction) one unpacked BCD value from
another and stores a byte result in the AL
03/13/25 63
 The AAA instruction then adjusts the contents of
the AL register to contain the correct 1-digit
unpacked BCD result

 If the subtraction produced a decimal carry, the


AH register decrements by 1, and the CF and
AF flags are set. If no decimal carry occurred,
the CF and AF flags are cleared, and the AH
register is unchanged

 In either case, the AL register is left with its top


nibble set to 0

03/13/25 64
Example:
;assume BL=0011 1001=39h=ASCII 9
AL=0011 0101=35h=ASCII5
ASCII9-ASCII5
SUB AL,BL ; Result: AL=0000 0100=BCD 04 and CF=0
AAS ; result:AL=0000 0100= BCD 04 and CF=0;no borrow required

;assume AL=0011 0101=35h=ASCII5


BL=0011 1001=39h=ASCII 9
;ASCII 5-ASCII9
SUB AL,BL; Result: AL=1111 1100=-4 in 2’s compliment and CF=1

AAS; result: AL=0000 0100= BCD 04 and CF=1; borrow needed

03/13/25 65
IF ((AL AND 0FH) > 9) OR (AF = 1)
THEN
AL ← AL – 6;
AH ← AH – 1;
AF ← 1;
CF ← 1;
ELSE
CF ← 0;
AF ← 0;
AL ← AL AND 0FH;

03/13/25 66
AAM: ASCII adjust AX after
multiply
 Adjusts the result of the multiplication of two
unpacked BCD values to create a pair of
unpacked (base 10) BCD values

 AAM works only after the multiplication of two


unpacked BCD bytes and it works only on an
operand in AL.

 After the 2 unpacked BCD digits(one BCD digit


per byte) are multiplied, the AAM instruction is
used to adjust the product to two unpacked BCD
digits in AX
03/13/25 67
 The AAM instruction then adjusts the contents of
the AX register to contain the correct 2-digit
unpacked (base 10) BCD result

Example:
;AL=0000 0101=unpacked BCD 5
; BH=0000 1001=unpacked BCD 9
MUL BH ;AL x BH; result in AX
;AX=00000000 00101101=002DH
AAM ;AX=00000100 00000101=0405H
;which is unpacked BCD for 45
03/13/25 68
AAD: ASCII adjust AX before
division
 AAD converts two unpacked BCD digits in AH and AL to
the equivalent binary number in AL

 Adjusts two unpacked BCD digits (the least significant


digit in the AL register and the most significant digit in
the AH register) so that a division operation performed
on the result will yield a correct unpacked BCD value

 The AAD instruction is only useful when it precedes a


DIV instruction that divides (binary division) the adjusted
value in the AX register by an unpacked BCD value

03/13/25 69
 The AAD instruction sets the value in the AL register
to (AL + (10 * AH)), and then clears the AH register
to 00H

 The value in the AX register is then equal to the


binary equivalent of the original unpacked two digit
(base 10) number in registers AH and AL

03/13/25 70
Example:
;AX =0607H unpacked BCD for 67 decimal
;CH=09H
AAD; result: AX=0043=43H=67 decimal
DIV CH; devide AX by unpacked BCD in CH
;quotient:AL=07 unpacked BCD
;remainder : AH=04 unpacked BCD
;flags undefined after DIV

03/13/25 71
Logical Instructions

03/13/25 72
AND
 Performs a bitwise AND operation on the
destination (first) and source (second) operands
and stores the result in the destination operand
location

 The source operand can be an immediate, a


register, or a memory location; the destination
operand can be a register or a memory location

03/13/25 73
 Each bit of the result is set to 1 if both
corresponding bits of the first and second
operands are 1; otherwise, it is set to 0

Operation:
DEST ← DEST AND SRC;

Flags Affected:
 The OF and CF flags are cleared; the SF, ZF,

and PF flags are set according to the result; The


state of the AF flag is undefined

03/13/25 74
OR
 Performs a bitwise inclusive OR operation
between the destination (first) and source
(second) operands and stores the result in the
destination operand location

 The source operand can be an immediate, a


register, or a memory location; the destination
operand can be a register or a memory location

03/13/25 75
 Each bit of the result of the OR instruction is set
to 0 if both corresponding bits of the first and
second are 0; otherwise it is set to 1

Operation:
DEST ← DEST OR SRC;

Flags Affected:
 The OF and CF flags are cleared; the SF, ZF,

and PF flags are set according to the result; The


state of the AF flag is undefined

03/13/25 76
XOR
 Performs a bitwise exclusive OR (XOR)
operation on the destination (first) and source
(second) operands and stores the result in the
destination operand location.
 XOR gives a true output when the number of
true inputs is odd.
 The source operand can be an immediate, a
register, or a memory location;
 The destination operand can be a register or a
memory location.

03/13/25 77
 Each bit of the result is 1 if the corresponding
bits of the operands are different; each bit is 0 if
the corresponding bits are the same.

Operation:
DEST ← DEST XOR SRC;

Flags Affected:
 The OF and CF flags are cleared; the SF, ZF,

and PF flags are set according to the result; The


state of the AF flag is undefined

03/13/25 78
NOT
 Performs a bitwise NOT operation (each 1 is set
to 0, and each 0 is set to 1) or does 1’s
complementing on the destination operand and
stores the result in the destination operand
location

 The destination operand can be a register or a


memory location

03/13/25 79
Operation:
DEST ← NOT DEST;

Flags Affected:
None

03/13/25 80
Logical Instructions
Mnemonic Meaning Format Operation Flags Affected
AND Logical AND AND D,S (S) · (D) → (D) OF, SF, ZF, PF, CF
AF undefined
OR Logical Inclusive OR OR D,S (S)+(D) → (D) OF, SF, ZF, PF, CF
AF undefined
XOR Logical Exclusive OR XOR D,S (S) + (D)→(D) OF, SF, ZF, PF, CF
_ AF undefined
NOT LOGICAL NOT NOT D None
(D) → (D)
Shift and Rotate
Instructions

03/13/25 84
 Shift and rotate instructions shift the data by one
or more bits towards either left or right, straight
or in a circular fashion

 The carry flag is always involved in these


operations

03/13/25 85
Shift Instructions…

 Shift instructions position or move numbers to


the left or right within a register or memory
location

 Two are logical shifts and two are


arithmetic shifts

03/13/25 86
 The logical shifts move a 0 into the
rightmost bit position for a logical left shift and
a 0 into the leftmost bit position for a logical
right shift

03/13/25 87
 The arithmetic and logical right shifts are
different because the arithmetic right shift
copies the sign-bit through the number,
while the logical right shift copies a 0
through the number

 Logical shift operations function with


unsigned numbers, and arithmetic shifts
function with signed numbers

03/13/25 88
 Logical shifts multiply or divide unsigned
data, and arithmetic shifts multiply or divide
signed data

 A shift left always multiplies by 2 for each bit


position shifted, and a shift right always
divides by 2 for each bit position shifted

03/13/25 89
 The logical shift instructions are SHL, SHR

 The arithmetic shift instructions are SAL,


SAR

03/13/25 90
SHL – Shift Operand Bits Left, Put Zero in
LSBs

SHL Destination, Count

03/13/25 91
 As a bit is shifted out of the LSB position, a
zero is put in the LSB position

 The MSB will be shifted to CF

CF  MSB LSB  0

03/13/25 92
 If the desired number of shifts is 1, this can be
specified by putting a 1 in the count position of the
instruction

 For shifts of more than 1 bit position, the desired


number of shifts is loaded into the CL register

Example:
MOV CL, 05H
SHL AX, CL

03/13/25 93
SHL/SAL Instruction :
 This instruction stands for Shift Logical/Arithmetic
Left.
 The SHL/SAL instruction performs shifting of each
bit in the operand (register or memory location)
to the left side and fills the least significant bit
(LSB) with zero and obtain the result in the
destination operand.
 The MSB is shifted into the carry flag (CF). The
operation of SHL/SAL instruction with 2 times shift
is shown below.

03/13/25 94
03/13/25 95
SAL (Shift Arithmetic Left)
Instruction,

SAL – Shift Operand Bits Left, Put Zero in LSBs

SAL Destination, Count

03/13/25 96
 As a bit is shifted out of the LSB position, a
zero is put in the LSB position

 The MSB will be shifted to CF

CF  MSB LSB  0

03/13/25 97
 If the desired number of shifts is 1, this can be
specified by putting a 1 in the count position of the
instruction

 For shifts of more than 1 bit position, the desired


number of shifts is loaded into the CL register

Example:
MOV CL, 05H
SAL AX, CL

03/13/25 98
SHR Instruction :
 This instruction stands for shift Logical
Right.
 The SHR instruction performs shifting of
each bit in the operand (register or
memory location) to the right side and fills
the most significant bit (MSB) with zero.
 The LSB is shifted into the carry flag (CF).
The operation of SHR instruction with 2
times shift is shown below.

03/13/25 99
03/13/25 100
 Here also the number of shifts of the bits is given
as the count in the instruction and all the flags
are affected according to the result.
 If the shift count is one, then it is directly
mentioned in the instruction.
 For shifting the bits, two or more than two times,
CL register must be used at the count position
which is loaded with shift count value as shown in
the below examples.

03/13/25 101
Example for SHR Instruction

Instruction Explanation

; shift bits in CX 1-bit right


SHR CX, 1
; puts 0 in MSB and LSB in CF

; Right shift bits in AX for 5 times (assume CL = 05H)


SHR AX, CL
; puts 0’s in 5 MSB’s and last LSB in CF

03/13/25 102
SHR – Shift Operand Bits Right, New MSB = 0

SHR Destination, Count

03/13/25 103
 This instruction shifts each bit in the specified
destination some number of bit positions to
the right

 As a bit is shifted out of the MSB position, 0


is put in the MSB position

 The LSB will be shifted into CF

03/13/25 104
0  MSB LSB  CF

03/13/25 105
 If the desired number of shifts is 1, this can be
specified by putting a 1 in the count position of
the instruction

 For shifts of more than 1 bit position, the desired


number of shifts is loaded into the CL register

Example:
MOV CL, 03H
SHR AL, CL

03/13/25 106
SAR Instruction
 This instruction stands for Shift Arithmetic
Right.
 It does the same operation as SHR except it
fills the bit portion shifted right from the MSB
with a copy of old MSB i.e., the SAR
instruction performs the right shift on each
bit and fills the MSB portion with the copy of
old MSB.
 The operation of SAR instruction with 2 times
shift is shown below.

03/13/25 107
03/13/25 108
 Similar to SHR, in SAR instruction, LSB
is shifted to carry flag (CF).
 In the case of multiple shifts, the CF
contains the most recent shift bit and
all the flags are affected according to
the result.

03/13/25 109
Example for SAR Instruction

Instruction Explanation
; shift bits in CX 1-bit right
SAR CX, 1 ; puts copy of old MSB in MSB
and LSB in CF
; Right shift bits in AX for 5 times
(assume CL = 05H)
SAR AX, CL
; puts 5 old MSB in 5 MSB’s
portion

03/13/25 110
SAR

03/13/25 111
 This Arithmetic shift right instruction copies
the sign bit through the number

SAR Destination, Count

03/13/25 112
 If the desired number of shifts is 1, this can be
specified by putting a 1 in the count position of the
instruction

 For shifts of more than 1 bit position, the desired


number of shifts is loaded into the CL register

Example:
MOV CL, 03H
SAR AL, CL

03/13/25 113
ROL – Rotate All Bits of Operand Left, MSB
to LSB
ROL Destination, Count
 This instruction rotates all the bits in a
specified word or byte to the left some number
of bit positions

CF MSB LSB

03/13/25 114
 If the desired number of shifts is 1, this can
be specified by putting a 1 in the count
position of the instruction

 For shifts of more than 1 bit position, the


desired number of shifts is loaded into the CL
register

Example:
MOV CL, 03H
ROL AL, CL

03/13/25 115
ROR – Rotate All Bits of Operand Right,
LSB to MSB
ROR Destination, Count
 This instruction rotates all the bits in a
specified word or byte to the right some
number of bit positions

CF MSB LSB

03/13/25 116
 If the desired number of shifts is 1, this can be
specified by putting a 1 in the count position of the
instruction

 For shifts of more than 1 bit position, the desired


number of shifts is loaded into the CL register

Example:
MOV CL, 03H
ROR AL, CL

03/13/25 117
For the ROL and ROR instructions, the original
value of the CF flag is not a part of the result,
but the CF flag receives a copy of the bit that
was shifted from one end to the other

03/13/25 118
RCL (Rotate Left including
carry)
 The RCL instruction shifts the CF flag into the
least-significant bit and shifts the most
significant bit into the CF flag

03/13/25 119
RCR (Rotate Right including
carry)
 The RCR instruction shifts the CF flag into the
most-significant bit and shifts the least-
significant bit into the CF flag

03/13/25 120
03/13/25 122
Shift Instructions
Mnemonic Meaning Format Operation Flags Affected
SAL/SHL Shift arithmetic SAL/SHL D,Count Shift the (D) left by the CF,PF,SF,ZF
Left/shift number of bit positions AF undefined
Logical left equal to count and fill OF undefined if count ≠1
the vacated bits
positions on the right
with zeros

SHR Shift logical SHR D,Count Shift the (D) right by the CF,PF,SF,ZF
right number of bit positions AF undefined
equal to count and fill OF undefined if count ≠1
the vacated bits
positions on the left
with zeros

SAR Shift arithmetic SAR D,Count Shift the (D) right by the CF,PF,SF,ZF
right number of bit positions AF undefined
equal to count and fill OF undefined if count ≠1
the vacated bits
positions on the left
with the original most
significant bit
Rotate Instructions
Mnemonic Meaning Format Operation Flags Affected
ROL Rotate left ROL D,Count Rotate the (D) left by the CF
number of bit positions OF undefined if count ≠ 1
equal to Count. Each bit
shifted out from the left
most bit goes back into the
rightmost bit position.
ROR Rotate right ROR D,Count Rotate the (D) right by the CF
number of bit positions OF undefined if count ≠ 1
equal to Count. Each bit
shifted out from the
rightmost bit goes back into
the leftmost bit position.
RCL Rotate left RCL D,Count Same as ROL except carry CF
through is attached to (D) for OF undefined if count ≠ 1
carry rotation.
RCR Rotate right RCR D,Count Same as ROR except carry CF
through is attached to (D) for OF undefined if count ≠ 1
carry rotation.
Ex. What is the result of ROL BTRE PTR [SI], 1
if SI is pointing to a memory location that contains 41H? (82H)
 Ex. What is the result of ROL BYTEPTR [SI], 1
 if SI is pointing to a memory location that
contains 41H? (82H)

03/13/25 126
Control Transfer
Instructions

03/13/25 127
 The intelligence in any program lies in the ability
of the program to follow different courses of
action based on intermediate results produced
during the working of the program; that way, the
program is enabled to perform data sensitive
tasks

 This capability is obtained by context sensitive


jump operations, in contrast to the normal
sequential cyclical operation of fetching the next
instruction and executing it, in the order in which
it is found in the program

03/13/25 128
JMP: Jump instruction

 Transfers program control to a different point in


the instruction stream without recording return
information

 This instruction can be used to execute three


different types of jumps: Near Jump, Short Jump
and Far Jump…

03/13/25 129
 Near jump—A jump to an instruction within the
current code segment (the segment currently
pointed to by the CS register), sometimes referred
to as an intra segment jump

 Short jump—A near jump where the jump range is


limited to –128 to +127 from the current IP value

 Far jump—A jump to an instruction located in a


different segment than the current code segment, is
sometimes referred to as an inter segment jump

The CS register is not changed on near and short jumps…


03/13/25 130
Conditional Jump Instructions…

03/13/25 131
MNEMONIC CONDITION TESTED

JA/JNBE(jump if above/jump if not below (CF AND ZF) =0


or equal)

JAE/JNB/JNC(jump if above or CF=0


equal/jump if not below /jump if no carry)

JB/JNAE/JC(jump if below/jump if not CF=1


above or equal/jump if carry)

JBE/JNA(jump if below or equal/jump if (CF OR ZF)=1


not above)

JCXZ(jump if CX register is zero) CX = 0

JE/JZ(jump if equal/jump if zero) ZF = 1

JG/JNLE(jump if greater/jump if not less ((SF XOR OF) OR ZF )


than of equal) =0
03/13/25 132
MNEMONIC CONDITION TESTED
JGE/JNL(jump if greater than or (SF XOR OF)=0
equal/jump if not less than)

JL/JNGE(jump if less than/jump if (SF XOR OF)=1


not greater than or equal)

JLE/JNG(jump if less than or ((SF XOR OF) OR ZF )=1


equal/jump if not greater)

JNE/JNZ(jump if not equal/jump if ZF=0


not zero)

JNO(jump if no overflow) OF=0 (not overflow)


JNP/JPO(jump if no parity/jump if PF=0 (not parity/parity
parity odd) odd)
JNS(jump if not signed, jump if SF=0 (not sign)
positive)
03/13/25 133
MNEMONIC CONDITION TESTED

JO(jump if overflow) OF=1 (overflow)

JP/JPE(jump if parity/jump if parity PF (Parity / parity equal)


even)

JS(jump if signed) SF=1 (Sign)

03/13/25 134
LOOP Instruction

 The LOOP instructions are basically conditional


jump instructions which have the format

LOOP LABEL

03/13/25 135
 LOOP instruction combines 2 operations in each
instruction

 The first operation is to decrement the CX


register by 1

 The second operation is to check the CX register


and, in some cases, also the zero flag to decide
whether to do a jump to the specified label

03/13/25 136
LOOP(jump to specified label if Loop Until CX=0
cx≠0 after auto decrement)

LOOPE / LOOPZ(loop while Loop if zero flag is set and


cx≠0 and zf=1)
CX !=0

LOOPNE / LOOPNZ(loop Loop if zero flag not set


while cx≠0 and zf=0)
and CX !=0

03/13/25 137
ALP to move data from one location to another rusing
LOOP instrcution

DATA SEGMENT
ARRAY1 DB 10H, 20H, 30H, 40H, 50H
LEN DB $-ARRAY1
ARRAY2 DB 5 DUP(?)
DATA ENDS

CODE SEGMENT UP: MOV AL, [SI]


ASSUME CS:CODE, DS:DATA MOV [DI],AL
START: MOV AX,DATA INC SI
MOV DS,AX INC DI
LOOP UP
MOV CH,00H
MOV CL, LEN MOV AH,4CH
INT 21H
LEA SI, ARRAY1 CODE ENDS
LEA DI, ARRAY2 END START

03/13/25 138
CALL
 Call instruction is a returnable jump to the destination or
the target address provided in the instruction

 This instruction can be used to execute two different types


of calls:

 Near call — A call to a procedure within the current code


segment (the segment currently pointed to by the CS
register), sometimes referred to as an intra segment call

 Far call — A call to a procedure located in a different


segment than the current code segment, sometimes
referred to as an inter segment call

03/13/25 139
 When executing a near call, the processor
pushes the value of the IP register (which
contains the offset of the instruction following the
CALL instruction) onto the stack (for use later as
a return-instruction pointer)

 The processor then branches to the address in


the current code segment specified with the
target operand

 The CS register is not changed on near calls

03/13/25 140
 When executing a far call, the processor pushes
the current value of both the CS and IP registers
onto the stack for use as a return-instruction
pointer

 The processor then performs a “far branch” to


the code segment and offset specified with the
target operand for the called procedure

03/13/25 141
RET
 The RET (return) instruction returns control back
from the procedure to the program that has
called the procedure

 The control will be returned to the instruction


following the procedure call

 This instruction transfers program control to a


return address located on the top of the stack

03/13/25 142
 The address is usually placed on the stack by a
CALL instruction, and the return is made to the
instruction that follows the CALL instruction

 The optional source operand specifies the


number of stack bytes to be released after the
return address is popped; the default is none

03/13/25 143
INT –interrupt program
execution
INT type
 These instructions are software interrupt procedure
calls

 The term type in the instruction format refers to a


number between 0 to 255 which identifies interrupt

03/13/25 144
When an 8086 executes an INT instruction it will

 Decrements the stack pointer by 2 and push the flags


onto the stack

 Decrements the stack pointer by 2 and push the


contents of CS onto stack

 Decrement the stack pointer by 2 and push the offset of


the next instruction(IP) after the INT instruction on the
stack

03/13/25 145
 Get a new value of IP from an absolute memory address
of 4 times the type specified in the instruction
Ex: for INT 8 instruction, a new IP will be read from
address 00020H.

 Get a new value for CS from an absolute memory


address of 4 times the type specified in the instruction
plus 2
Ex: for an INT 8 instruction the new value of CS will be
read from address 00022H

 Reset both IF and TF .other flags are not affected

03/13/25 146
IRET: Return from interrupt
 The IRET instruction performs a far return to the
interrupted program or procedure

 During this operation, the processor pops the


return instruction pointer, return code segment
selector, and FLAGS image from the stack to the
IP, CS, and FLAGS registers, respectively, and
then resumes execution of the interrupted
program or procedure

03/13/25 147
 Which of the following instruction is not
valid?
a) MOV AX, BX
b) MOV DS, 5000H
c) MOV AX, 5000H
d) PUSH AX

03/13/25 148
 Ans: B
 Explanation: Both the source and destination
operands cannot be memory locations except
for string instructions.

03/13/25 149
 The instruction that pushes the
contents of the specified
register/memory location on to the
stack is
a) PUSHF
b) POPF
c) PUSH
d) POP

03/13/25 150
 Answer: c
Explanation: Since PUSH operation
transfers data to stack from a register
or memory location

03/13/25 151
 The instructions that are used for
reading an input port and writing an
output port respectively are
a) MOV, XCHG
b) MOV, IN
c) IN, MOV
d) IN, OUT

03/13/25 152
 Answer: d
 Explanation: The address of the input/output port
may be specified directly or indirectly.
Example for input port: IN AX, DX; This instruction
reads data from a 16-bit port whose address is in
DX and stores it in AX
Example for output port: OUT 03H, AL; This sends
data available in AL to a port whose address is
03H.

03/13/25 153
 The instruction that pushes the flag
register on to the stack is
a) PUSH
b) POP
c) PUSHF
d) POPF

03/13/25 154
 Answer: c
Explanation: The instruction
PUSHF(push flags to stack) pushes the
flag register on to the stack.

03/13/25 155
 The flag that acts as Borrow flag in the
instruction, SBB is
a) direction flag
b) carry flag
c) parity flag
d) trap flag

03/13/25 156
 Answer: b
Explanation: If borrow exists in the
subtraction operation performed then
carry flag is set.

03/13/25 157
 The instruction, CMP to compare source
and destination operands it performs
a) addition
b) subtraction
c) division
d) multiplication

03/13/25 158
 Answer: b
Explanation: For comparison, the
instruction CMP subtracts source
operand from destination operand.

03/13/25 159
 In the RCL instruction, the contents of the
destination operand undergo fu
 nction as
a) carry flag is pushed into LSB & MSB is pushed
into the carry flag
b) carry flag is pushed into MSB & LSB is pushed
into the carry flag
c) auxiliary flag is pushed into LSB & MSB is
pushed into the carry flag
d) parity flag is pushed into MSB & LSB is pushed
into the carry flag

03/13/25 160
 Answer: a
Explanation: In RCL(Rotate right
through carry), for each operation, the
carry flag is pushed into LSB and the
MSB of the operand is pushed into carry
flag.

03/13/25 161
 The instructions that are used to call a
subroutine from the main program and return
to the main program after execution of called
function are
a) CALL, JMP
b) JMP, IRET
c) CALL, RET
d) JMP, RET

03/13/25 162
 Answer: c
Explanation: At each CALL instruction,
the IP and CS of the next instruction are
pushed onto the stack, before the
control is transferred to the procedure.
At the end of the procedure, the RET
instruction must be executed to
retrieve the stored contents of IP & CS
registers from a stack.

03/13/25 163

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy