Documente Academic
Documente Profesional
Documente Cultură
8086 Microprocessor
By
Manish Singhal
c
Software
ADD AX, BX
i
Instructions
LABEL: INSë CëION ; COMMENë
Address identifier Does not generate any machine code
!"
!#$#$
!"!"!!%#!
#&#$#$%%"
'
!#$#$!"&%
($&" !#$##!
ëwo key benefits of assembly language
programming
Ë
Applications
One of the most beneficial uses of
assembly language programming is
real-time applications.
Byte 2 has three fields
± Mode field (MOD)
± egister field ( EG) used to identify the register for the first operand
± egister/memory field ( /M field)
÷
_
Mnemonic Meaning Format Operation Flags affected
MOV Move Mov D,S (S) (D) None
_
!
!
)!!" #!#
#!# #!#
**
_
_
!" #$ %&'()*+,
c+
_
- .!+._+.!
Mnemo Meaning Format Operation Flags
nic affected
LEA Load LEA eg16,EA EA ( eg16) None
Effective
Address
LDS Load LDS eg16,MEM32 (MEM32) ( eg16) None
egister
And DS (Mem32+2) (DS)
ï
!
!
"
#"$
%
&
&
&
&
$
ci
)
$__+_+ ++_
c
Examples:
Ex.2 INC BX
INC WO D Pë [BX]
Ë *iÒ/0",12
*Ò/0",12 25
+ 56
11** --------
1 7B 81
cË
)
- 1,+,,+_!++_+!
c
Multiplication and Division
c
Multiplication and Division
c÷
Multiplication and Division
#
# #
/1.
1.0 /
#0
,2, .
c
Multiplication and Division Examples
!"$
$
$
" "
$
'
()
)
* +,
-
*
()
.
)
(/
-
(/
0* 1+,
-
*
02
.
02
()
.
)
3
.
)
/33- 02
- ï4(/
- *
() V - *
* 15
-
0 ()60.)
-
) V 0
- *
() V
7* 115
-
0
) V
i+
!"&$ .89'+,.8:+8;;
* +,
-
.
8
.
/
(/
-
(/
0* 1+,
-
.
02
. 02
02
8
. 02
/
.
48
)
-
*
V V
*115
-
0-
8
9 0.48)
u 0: /V 4 V
cÒ +i ´ È i3/+i245- cÒ 5
È
6
V
7*
15
-
-86./40
-
40
u /V
6
ic
!"'$ 89;;;+,8:;<+_8;;;;
*
+,
8
.
/)
÷c +++
0*
1+,
02
8
. 02
/)
.
48ï
+5 +++
V
*
15
4
- +
$
88 -
"'"
ï*
) V
0 V V
7*
115
-
; <
38 -
"'"
ï*
) V ) V
ii
!"($ 8&<;+,.8:;
-
u / V È 0 È 0 / V 3 V
4i-/62/ciÒ+' i7+24+-/
2
0) V 6
Ò+- i+-
i1)*44i+-ciÒ+i+7+4Ò+-
u / V -*
i
Logical Instructions
9
#
9
_ .
_ __+ /0=/_0ĺ /_0 9+9+@9+A9+
9
.
5 _+ /0>/_0ĺ /_0 9
9+9+@9+A9+
9
.
!"
5 _+ /0 ù /_0ĺ/_0 9
9+9+@9+A9+
? 9
. . _ /_0ĺ /_0 9
_
_
iË
LOGICAL Instructions
=
9 ,
!
">
!66!
>
>"
9 ï"!
"
">
"
"
?">
_
$
"
"
9 ï
=
8
=
@7)A
BC
9 ,
"
">
"
"
$
"
iÒ
BC
9 ,
"
1'">
"
BC
2 2 2 2
!" #$;
"
"
4
3
"'
"
)
>"
;
=
;
B8; D
BC
;
; D
BC
;
0 D
i
Shift and otate Instructions
SH /SAL: shift logical left/shift
arithmetic left
SH : shift logical right
SA : shift arithmetic right
OL: rotate left
O : rotate right
CL: rotate left through carry
C : rotate right through carry
i
*#&!%
#%% "
8
h
"$"
$"
"
$
#!
"
""
#"$
!
$
2
">
"
h
i÷
Shift Instructions
9
#
9
.7 ) .7._+
) ) /_0 B ) 9+A9+9+@9
. )
B
B #
9
.7) C
) 9
.
5 B #
E
) ) 4) D
_
.
.
+
c
SHL Instruction
-*/%%2$%!#
%%""%#
+
h
"
@ Y
@
@ Y
@ i
Fast Multiplication
Shifting left 1 bit multiplies a number by 2
r
Ë
SH Instruction
-/%#2$%!#
#%""#
%" 8
h
%##Ê "&""iÊ
Ô
@
@
Ò
SA Instruction
!%&$!9#
Ô
@
@
otate Instructions
9
#
9
.
._+
)/_0B) 9
.
B
B#
C
9
F! )B)
E
)
B
B G
))
B#
F
_+
)/_0)B) 9
)
B
B#
C
9
F! )B)
E
))
B
B G
)
B
#
F
.
._+
."# 9
. )
/_0
F 9
)
)
E
_+
"# 9
) )
/_0
F 9
)
)
E
OL Instruction
OL (rotate) shifts each bit to the left
ëhe highest bit is copied into both the Carry
flag and into the lowest bit
No bits are lost
Ô
Ô
÷
O Instruction
O (rotate right) shifts each bit to the right
ëhe lowest bit is copied into both the Carry flag and
into the highest bit
No bits are lost
Ô
Ô
CL Instruction
CL (rotate carry left) shifts each bit to the left
Copies the Carry flag to the least significant bit
Copies the most significant bit to the Carry flag
Ô
Ë+
C Instruction
C (rotate carry right) shifts each bit to the right
Copies the Carry flag to the most significant bit
Copies the least significant bit to the Carry flag
@
Ô
Ëc
otate Instructions
_
.
.
Ëi
Flag control instructions
MNEM- MEANING OPE AëION Flags
ONIC Affected
,*, ,,5# /,52 + ,5
, ,5# /,52 c ,5
,
, ,!! /,52 /,52l ,5
,5#
,*1 ,1 /152 +
5# ) : 1) $ !" 15
# $ $"
1 1 /152 c
5# ) : 1) $ "!" 15
# $ $"
,*) ,)$ /)52 + )5
5#
) )$ /)52 c )5
5# Ë
Compare Instruction, CMP
Mnemo Meaning Format Operation Flags
nic Affected
,
; ,! ,
;1 (D) ± (S) $" ,555
# # ;55<5
%#
Allowed Operands
Destination Source
(D) = (S) ; ZF=1
egister egister
(D) > (S) ; ZF=0, CF=0 egister Memory
(D) < (S) ; ZF=0, CF=1 Memory egister
egister Immediate
Memory Immediate
Accumulator Immediate
ËË
String?
ËÒ
String Instruction Basics
' =$!$$1"
' =$!$$)"1)%%1
"&
15#/+4>c41 2
&#
? //2+ù/1)22 //12+ù/)22
1 ) 1)
@ /)2 /)2 ci
/1)2 /1)2 ci
,
; ,! ,
;? %#
# ,
;@ //12+ù/)22 //2+ù/1)22 $
1 ) 1) /)2 /)2 ci %#
/1)2 /1)2 ci
Ë÷
Mnemo- meaning format Operation
Nic
, # ,? %#
' 1) ,@ /*
2 //2+ù/1)22
/1)2 /1)2 ci
Ë
Branch group of instructions
Branch instructions provide lot of convenience to the
programmer to perform operations selectively, repetitively
etc.
#$%$
Ò+
SB OëINE & SB OëINE HANDILING INSë CëIONS
Main program
Subroutine A
First Instruction
Call subroutine A
Next instruction
eturn
Call subroutine A
Next instruction
Òc
È $$#!%#!"%
$%!#!
È !#$#$$%"B"$C
È @& "$$#$"
!"%#!$$
È $$&$);,");!$
!"%"
È %$ $$
!!"% "$$#&$
%);,");!$&"
È $%$$%);&"
0/!/;2 /;2i 2
È c/!!c#c)#!2&$
%"$""");
È ! ,**ciË-
CALL BX
CALL [BX]
Òi
Inter Segment
Far-proc
Memptr32
ëhese two words (32 bits) are loaded directly into IP and
CS with execution at CALL instruction.
First 16 IP
Next 16 CS
Ò
!
# 5! 5#
%%"
Operand
Near-proc
Far ± proc
Memptr 16
egptr 16
Memptr 32 ÒË
Eë N
& $$ !$ " $# $ $
! #! $ /2 $
!
# 5! 5#
%%"
$ $ ! È
" #! # );
/" , % %2 )%
"
""" %
;
Operand
None
ÒÒ
Disp16
Loop Instructions
$ $" % $ &
!
5! *;*
/,
2 /,
2c
D$! 8" "%" % ,
E+
$ ($ $
)$ *; 0 % ,
,
!$
"" $ $! % !
@& $" ,
%
"!" 0" "! % ($ 8
)% ,
4+ ! " $ % #
$"
)% ,
E + $ $ %"
$
Ò
LOOP Instruction contd.
It is a 2 byte instruction.
Ò÷
Control flow and JMP instructions
nconditional Jump
Part 1
JMP AA
nconditional JMP
Part 2
Skipped part
Part 3
AA XXXX Next instruction
>"D$!)$
ÈD$! 5D$!
)#!D$! )#!D$!
/D$! #!2 /D$!"%%#!2
Is limited to the address with in Permits jumps from one code
the current segment. It is achieved segment to another. It is
by modifying value in IP achieved by modifying CS and IP
Operands
Short label
Near label
Far label )#!D$!
Memptr16
egptr16
+
memptr32 )#!D$!
Conditional Jump
Part 1
Part 2
NO
Skipped part
condition XXXX
YES
Part 3
AA XXXX Next instruction
c
Conditional Jump instructions
i
Conditional Jump Instructions
Mnemonic : Jcc
Meaning : Conditional Jump
Format : Jcc operand
Operation : If condition is true jump to the address specified by operand.
Otherwise the next instruction is executed.
Flags affected : None
ëYPES
D & ,54+"<54+
D ,54c
D, , ,54c
D ($ <54c
D. . <54+"545
Ò
Mnemonic meaning condition
DÈ* È*($ <54+"545
DÈ È&% 54+
DÈ; È; ;54+
DÈ< È< <54+
DÈ È# 54+
D &% 54c
D; ; ;54c
D; ;& ;54c
D; ;"" ;54+
D # 54c
D< < <54c
Jumps Based on a single flag
JZ r8 ;Jump if zero flag set to 1 (Jump if result is zero)
JNZ r8 ;Jump if Not Zero (Z flag = 0 i.e. result is nonzero)
JS r8 ;Jump if Sign flag set to 1 (result is negative)
JNS r8 ;Jump if Not Sign (result is positive)
÷
Examples for JE or JZ instruction
ï
/!%D#&2
,
;)1)
JE SAME
>
$"%<4c
/%)41)2
Examples for JE or JZ instruction
ï
,G >
$"%<4c
$" /%)41)2
F4ci÷
,
;)1)
JE BACK
11,
1
$"%<4+
/%)($1)2
+
Jumping beyond -128 to +127?
ß
Ê Ê
,
;)1) ,
;)1)
D
DÈÈ
@% 11,
1
D
;
Hci
È
11,
1
>
>
#%D
;/$"A$!2ùicÒ 4ù iGD
;$
"$""
c
ëerms used in comparison
&" $"%!#>#"
."$" #"$!
)!$&
ï
ï
Ë
Jump on multiple flags contd
contd
Ò
Jump on multiple flags contd.
DÈ* D$!%È/*($2
D. D$!%.
Jump on multiple flags contd.
D* D$!%*
DÈ. D$!%È/.($2
4cÈ14+ 4+È14+
/$#&2 /$&2
/4+È14c2 /4cÈ14c2
/ # &J2 / # #&J2
Jump on multiple flags contd.
DÈ* D$!%È*
D. D$!%.($
4+È14+ 4cÈ14+
/$&2 /$#&2
/4cÈ14c2 /4+È14c2
/ # #&J2 / # &J2
÷
Near Jump
ÈD$!
1D$! )"D$!
/!!2 /$!!2
D$! *#D$!
i!
i
# 55-
÷ c # !
#!
#ù i #ùicÒ
ÈD$!"i5D$!$&!!!
D
;$"%%"
Short Jump
i/÷2$# ci÷ùci
u
!0 ($$!%A$!
.D$!"%F4ci÷($"A$!
."%*#D$!%Hci÷($"A$!
!"30 A$!($$!c
!&%% "A$!$
)%A$!"$$Hci÷$
""c/-4*#A$!"2
)%A$!"!F4ci÷$""
÷% ""%È;/÷-4A$!"2
÷+
Short Jump contd.
-!1&
!#iD$!"%% "A$!%
-!"&$"
D
;SHO ë
;#!!$"$
D$!"F4ci
,
1
÷c
Long Jump
/c2$# i÷ùi
*#D$!&ËG%,"#!
, ++++-
*#D$! , ÷+++- D
;5@1
"A$!
($$!F4i
5@14 , 5555-
÷i
Long Jump contd.
)&ËG%,"#!
÷
Long Jump or Short Jump?
, ++++-
D$!"
," , +++1- D
;5@1 455+-
! &#
/i+-20 " , ++c+-
% "A$!
J
5@14 , 555+-
, 5555-
÷Ë
Long Jump or Short Jump?
, ++++-
D$!"
," G@14 , ++c+- 455+-
! &#
/i+-2% "
0 "A$!
J D
;G@1
, 555+-
, 5555-
÷Ò
Intra segment indirect Jump
È)"D$!$!!
)$# i!
# !#!
c D
;1
)%1
4ciË-, ciË-
ciË-#"&"!
i D
; "i+++-K
L
ciË- 1 iË- Ò÷-
÷
Far Jump
5D$!
1D$! )"D$!
/!!2 /$!!2
Ò
i!
i%%i#!
# 55-
#
#
3 Near Jump and 2 Far Jump instructions have the same mnemonic
JMP but different opcodes
÷
Inter segment Direct Jump
It is a 5 byte instruction
1 byte opcode (EAH)
2 byte offset value
2 byte segment value
÷÷
Inter segment Indirect Jump
D
;1@1;i+++-K
L
÷
Inter segment Indirect Jump
"5)"D$!
)!!$"
)$#!!$!%i
)"" A$!%"
D
;1@1;i+++-K
L
ciË-
,1- Ò÷-
1 iË- Ò÷- )Ë$
1 i- ,1-
+
Machine control instructions
HLë $' -*#
-* $ $ ÷+÷ %# " $#
$ ÷+÷ #
$ % $ # )È $
# È
) # $
NOP $
$ ! 0 $ 0 " "
# % $ $ $
! $" &" " $
ESC $
&$$!"È;
"%!!!%$
%!÷+÷!%,$&"
"
÷+÷%$0$
"$($$ !÷+÷
$È;5#$$"÷+÷"
"$#÷+÷ @)
c
Machine control instructions contd
LOCK $
% $ % !0 $ "$#
$ % $ % ! $ 0
!
!$ ! "&"$ ! "
# ! $ !! $
0 % $ " $ !!
$
0 % $ !"" % $ !
$ 0 &" " #
M*,G3 & % ,;> # !" &
"$# $ " $" $ # &
%! 0# $
$ !" 0 # ! & "
! 0 ! $
WAIë $
$ 0 ÷+÷ " " ,;> "
# "$# ) $ " $
% ÷+÷ ! $ # &" )È È
)
&" $ ) $" " " #
i