Beruflich Dokumente
Kultur Dokumente
and Interfacing
A. P. Godse
D. A. Godse
Atul P. Godse
M. S. Software Systems (BITS Pian)
B.E. Industrial Electrooics
Fonnerty Leduret., Oepot1ment of Electronics E119g.
Vlshwakarma Institute of Technology
Pune
Visit us at : www.vtubooks.com
~@
6
Thchnical Publications Pune
T hJ.e One
(1)
Syllabus (Microprocessors & Interfacing)
Unit-1 (Chapter-1, 21
An ovetview of 8085, Architecture of 8086, Microprocessor. Spec:la! fUflctlons of general purpose
registers, 8086 flag register and func6on of 8086 flags.
UNJT-11 (Chapter-31
Addressing modes of 8086, Instruction sel of 8086, Assembter directives simple programs.
Procedures. and Macros.
UNIT-Ill (Chapter-41
Assatnbly language progtall'l$ Involving logical, Branch and catl ln:structions, Sortfng, Evatuatlon
of arittwnetic expressions., String manipulation.
UNIT-IV (Chapter-s, 6)
Pin di&9f&rri of 8086 Minlmum mode and maximum mode of operation, Timing diagram, Memory
4
interfacing tQ 8086 (Static RAM and EPROM). Need for OMA, OMA data lransfef method, lnterfac:ing
with 8237/8257.
UNIT-V <Chapter-?)
8255 PPI-Various mOde-s of operation and interfacing to 8086. Interfacing keyboard, Displays,
Stepper motor and &etuatOfS. OIA and AID converter interfacing.
UNIT-VI (Chapter-s, 9)
Interrupt structure of 8086, Vector interrupt table , Interrupt service routines. IntroduCtiOn to DOS
and BIOS Interrupts, 8259 PIC archttectute and interfacing cascading of Interrupt oontroller and its
importance.
UNIT-VII (Chapter-10)
Serial data transfer schemes. Asynchronous and synchronous data transfer sdlemes. 8251
USART architecture and interfacing, TTL to RS 232C and RS232C to TTL oonvSion, Sample
program of serial data transfer, Introduction to High...s,peed serial oommunicetions standilrds. USB.
UNIT-VIII (Chapter-H)
8051 Mk:rocontrOIIef ai'Chit&eturo. Regist&f set or 8051, Modes of dmet operation, Serial port
operation, Interrupt structure of 8051 , Memory arxl 1/0 interfacing 8051.
{2)
Copyrighted material
Table of Contents :
Chapter 1 : An Overview of 8085 {11)to{166)
Chapter 2 : Arohttecture of 8086 Microprocessor {21)to{2 14)
Chal)ter 3 : 8086 Instruction Set and Assembly Language Programming {31)to{3-110)
Chapter 4 : Assembly Language Programs {41)to{4 -74)
Chapter 5 : 8086 System Coofiguration {51) to (534)
Chapter 6: D!recl Memory Access {DMA) 823718257 {6 1) 10 (6 28)
Chapter 7 : 8255 PPI {Programmable Periplleral lnterface) {1 1) to (7 64)
Chapter 8: 80861nterrupts {81) to (8 28)
Chapter 9 : lntroduclion to DOS and BIOS Interrupts {9 1) to (9 30)
Chapter 10: Serial Communication {10 1) to (10 38)
Chapter 11 : 8051 Microconlroller {1 1 1) to (11 38)
Appendix A (A1)to(A6)
Appendix B (B 1) to {B 10)
Appendix C {C 1)to{C 8)
Chapte!Wise University Questions with Answers {P1)to{P 34)
:
,,.. 8085. 8086/88 Architecture. programming and interfacing.
,,.. Free download 8086 programs on www.vtubooks.com.
8051 Microcontroller architecture.
Large number of programming examples.
Programs using modular programming approach.
Practical interfacing design examples.
.....................................................................................................................................
(3)
Copyrighted material
Microprocessors
& Interfacing
Atul P. Godse
M. S. Softw311! Systems (BfTS Pilaro)
B.E. lrduSirial Electrorics
Formerty Lecturer ln Occ:>artment of Elcctrorics Engg.
Vlshwakarrna Institute of Technology
Pune
Visit us at : www.vtubooks.com
e
~ 6
_'Jechnical Publications Pune
Copyrighted material
Microprocessors & Interfacing
ISBN 9788184311259
All rights res.rved wi*' Technicot Pvblicotions. No pot1 of this bool: ahould be
reproduced In ony form, Eledroni(, Mechonicol, Pholoc::opr or ony inbmolion storage ond
retrieYol system without prior permission In writing. from Techricof Public:otionJ, Pune.
Publisl..d by :
1tthnlcaii'\Jbllcallons 1'\Jne
" ..... L.ldoo<v. -IW>. 1\.w- ... 030, ......
___
1'11nters :
Ylkr..... l'rlnterS
34.---e..
Puno <11008.
. , ., -. . ;; "." ~ . - .. . . . -~" _. -
Copyrighted material
Preface
Thanks to professors, students and authors of various technical books
for their overwhelming response to our books. Looking at the feedback and
the response we received from previous books, We are very pleased to
release a text book on Microprocessors and its Applications.
The purpose of this book is to fulfil a need for text stating in plain, lucid
and simple everyday language. This book provides a logical method for
explaining and it prepares a background of the topic with essential
tnustrations. This text is provided with number of solved design examples
which helps students to understand the application of microprocessor and
microcontroller based systems.
We are spedally grateful to the great teacher Prof. A.V. Bakshi for h1s
time to time, much needed, valuable guidance. Without the full support and
cheerful encouragement of Mr. Uday Bakshi the book would not have
been completed In time.
Finally. we wish to thank Mr. Avinash Wani, Mr. Ravindra Wani and
the entire team of Technical Publications who have taken immense pain to
get the quality printing In time.
Authors
Atul Godse
Deepali Godse
- - - - -~ - L r ~ ._- - - -
Table of Contents
1.1 8085 Microprocessor ............................................................................1 - 1
1.2 Architecture of 8085 .., ...., .... , , , , , .. , , , , .. , .. , , , , , , , , , , ......, .. , , , , 1 - 2
1.2. 1Regjster Struci!Jre ... . . . . .. . . . . ... . . . . . . .. .. .. . . 1 3
1.2.2 AriUvnetic Logic U n~ (ALU) . ... . .. . . . . . . . . . .. . . . . .. . . . .. . . . .. . . .... . . . . . . 1 6
1 2 3 lnstructjon Derater 1 6
1.2 4 Address Buffer I I I I
. 1. 6
1 2 5 Addre,cwData Buffer 1 7
1 2 6 tnaementerttlecremeoter Address Latch 1 7
1.2.7 lnlemJpl Conlrol... . . . .. . . . . . . . . . .. . . . . . . . .... . . . .. . .... . .. . . .. . . . . .. . . .. 1 - 7
1.2.8 Serial vo Control " " .. " .. . " " . . . . . . . . ..... " " " " " " " . " . " " " . . 1 7
1.2.9 Tiering and Conlrol Cirt>Jilry . . . . . . .. ... . . . . . .. . . . .... . .. . . . .. . .. . . . .. . . . . .. 1 - 7
1.3 Pin Definitions of 8085 , , ....,, .., ........,,,, .........., ......, ..........,,, ......1 - 8
1.3.1Power S'4J!)!y and Frequency Signals.......... . ... ... .. . . . . ... . .. . ...... . . . . 1 9
1 3 2 Data Bus and Addre:ss: Bus , , , 1- 9
1.3.3 Conlrol and Status Signals . . . .. . . . . . . . . . .. ... . ... . .... . .. . . . .. . .. . . . . . . .. . 1 9
1.3.4 Interrupt Signals . . .. . . . . . . ... . . . . . . . . .. . . . . .. . . ...... . ...... . .. . . . . . .. . 1 -10
1.3.5 Serial I/O Signals . . . . . . . . .. . . . . . . . . ... . ... . .... . . . ..... . . . .. . .. . . . . .. . . . 1 10
1.3.6 OMA Signal . . . . . .. . . . . .... . . . . . . . . ...... . .... . . .. . . .. . . .. . .. . . . . .. . . . . 1 10
1.3.7 Rese1 Signals . . . . . . . . ... . . . . . . .. ......... . .. . . .. . . . .. . . 11 0
1.4 Bus Organisation ................................................................................ 1 -10
1 4 1 Clock Cjrcujts I I , .. , , , 1 11
1.4.2 Oemultiplexing AD, AD, . . . . . . . . . . . . . . . . . . . . . . .. . . .. . .. . . . . . . . .. . . . . . . 1 - 12
1 4 3 Rese! Cjo;ujt , , , , , , " :z 1 - 12
1.4.4 Generation of CoQtrol Signals . .... . . ... . . . . .. . . . . . . . . . 1 - 14
1.4.5 Bus Drivers .. . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . .. . .. . . .. . . . . . .. . . . . . 1 15
1.4.6 Typical Configuration.......... . ..... . . . . .. .. . . . . .. . . .. . . . . . . .. . .. ... . . .. 1 17
1.5 Timing and Control ............................................................................. 1 - 18
1.5.1 8085 Machine Cydes and their Tmings . . . . . . .... . . .. .... . .. . ... . ... . .. . ... . 1 - 24
1.5.2 Conceot of Wait Slates . ,. . . ,. . ,. ,. ,. ,. .. . .. . . . .. .... ....... . .. . ,. .... . 1- 35
1.6 Instruction Set of 8085 .. , , , , ......, ......, , , , ...., ... , .. .. , .., . . . 1 - 37
1.6.1 Data Transfer Group . . . . . .... . . . . . . . .". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 - 37
1.6.2 Arithmetic Group . .. . ........ . . . . . . ...... . . . .. . . .. . .. . . ...... ...... 1 39
1.6.3 Branch Group ..... . . . . . . . .. . . . . . ... . .... . . . .. . . . .. . ... . . .. . . .... . , .. . 1 - 45
1.6.4Logic Group . . .. . . . .. . . . . . . . .. . . . . . . . . . .. . . . . .. . .. . . . .. . . .. . . . .. . .... . . 1 - 48
1.6.5 Slack Operations . . . .. .... . . . . . . . .. . ........ . . .. . ... . ..... . .... 1 - 52
1.6.6 Machine Coolrlll Group .. . . . . . . ... . . ..... .. . . . .... ... . .. . . . ... .. . . . . . .. . . 1 - 54
1.7 80851nterrupt Structure and Operation ..............................................1- 55
1.7.1 Types ollnterrupts... . .. . . . . . .... . .......... . . . . . . . . .... . . .. . . ... . ...... 1 - 55
1.7.2 Overall Interrupt StnxUe . . .... ... .. . ... .. .. . . . . . . . ... . ... . .. . .... . ...... 1 - 56
1.72.1 - lnl!!!!!ps in 8085. 1 56
1.722 Sollware lnlemJpts In 8085 1 60
1.7.3 Masb!g I UnrnasU!g ol lr!ten!!J!s . ... . ... . . .. . ... .. .. . .... . . . . .. .. ... . .... 1 - 60
1.7.4 Pending Interrupts . .. . . . .. . . . . . ............... . . . .. . .. . .... . .. . .. . . . .... 1 62
Reyjew Questions . . . , . " ' ' " """ "' ' '
, ' ' 1-65
356 1 BCOM!m* 3 29
3.5.&,2 ASCU Mhi1lllc .. 3 30
3.5.7 Basic LAgle lnsbuctions .. .. .3 32
3,5 8 Shift end Rntale .. . , .. .. I I ' ' .. . . . .. . .. . ........ . 336
3.5.0.1 SH11 . 336
3.U.2- 339
3.8 String lnttnJetiont ...............................................................................3 42
3.7 Program Control Transfer lnstructions................................................3 44
3 7 1 CAll arxl RET .klstnr#km I I I I I I I I I I I I I I I I I T I I I 1 I I I I 1 , I I I I I I I t 3 -44
3 7 2 .IMP lnstrucfigo f t f t ft t t t t t t t t t t 0 0 I t 0 I 0 0 0 0 J 0 0 0 I t 0 J I 1 I I I l I f I I I f I J f 0 0 0 0 0 0 0 0 3 46
f
3.7.3 Cood . Coodilional ~ -" " ....... " " .. " ........... ' ............ 3. 48
3 8 lteratlon Control Instructions ....... :..............................., . , ...................3 49
3 9 Processor Coolml lnslructioos .. , , , , .. , , , , ............ ., .......................3 49
3.10 External Hardware Synchronization Instructions .............................3 - 50
3.11 Interrupt Instructions .........................................................................3 - 51
3 12 Assembler D jrectjves 3-52
3.12.1 S<Jmmary of Assembler Directives ........ . .... . .... . ....... . .. . .......... 3- 58
3.12.2 Variables. S<Jffix and Operntors .... . ......... .. . .... . .. . .... . .. . ......... . 3-58
3.12.3 Accessing a Procedure and Data from anodler Assembly Module . . . . . ... . ... . .. . 3- 59
3.13 Assembly language Programming ...................................................3 - 60
3.13.1 Assembly Language P!O<Jams ................ . ....... . ..... .. . .... ... .. . 3- 62
3.13.2 Assembly Language Programming TillS .. .. . . . .. . . . .. .. . .. . .. . .. . .. .. . .. .. . 3 - 63
3.13.3 Programming with an Assembler. . .. .. .. .. .. . .. .. .. . .. . .. . .. .. . .. . .. .. . .. . 3 - 65
3.13.3.1 Assembling Process . 3 -66
3.13.32 UMing Process . . . . . . . . . . . . . . . . . . . . . . . . 3 67
3.13.3.3 Debugging Process . . . . . . . . . . . . . . . . . . . . . . . . . 3 67
3.14 Assembly language Example Programs ..........................................3 - 69
3.15 Timings and Delays .................................................. ........................3 - 72
3.15.1 Timer Delay using NOP Instruction . .. . . .. . .. .. . .. .. . .. .. . .. . .. . .. . .. .. .... 3 n
3.15.2 Timer Delay using Counters .. " " " . " " " . " " " . " . . . " . " . " . " " " .. 3. n
3.15.3 Timer Delay using Nested Loops .... . .. ...... . .... .... .... . .. . .. . .. .... . . 3 74
3.16 Data Conversions , ......, ......, .. , , ..,, , , .., , ........, .., , , .., .., , .., ,,3 - 75
3.16.1 Routines to Conwrt Binary to ASCII ......... ... .... . .. . .. .. . .. . .. . .... . ... 3 76
3.16.1.1 By AAM lnslruclion fFor rwmber less !liM 100). . . . . . . . . . . . . . . . 3 76
3.16.1.2 By Series o1 Decimal OMsion. . . . . . . . . . . . . . . . . . 3 79
3.16.2 Routine to Convert ASCII to Binary . ............ ... . .. . . .. . ...... . . . . 3 82
3 16 3 Routine In Read Hexadpdmal Data 3 - 85
3.16.4 Routine to Display Hexadecimal Data ........ . ...... . .. . .. . .. . .. . .. . ...... . 3 90
3.16.5 Loolrup Tabies fO< Data Conversions .. .. .... . .. . . . .... . .. . ..... . .... . .. . . . 3 93
3 17 Pmced! !res 3 .. 96
3 17 1 Reentrant Procedure 3-98
3 17 2 Reausjve Prooedum 3-98
3 18 Macro . ..... ...................3 - 99
3 19 lnstructjoo Formats ........... 3 - 100
Review OtJestjoos 3-107
Copyrighted material
Program 1 : Read keyboard input and display it on monitor ......................4- 1
Program 2: Addition of two 32-bit numbers................................................4 - 1
Program 3 : Addition of 3 x 3 matrix ...........................................................4 - 2
Program 4 : Program to read a password and validate user .....................4 - 4
Program 5 : Program to calculate factorial of a number ............................4 - 5
Program 6 : Reverse the words in string .................................................. .. .4- 7
Program 7 : Search numbers, alphabets, special characters .....................4- 9
Program 8 : Program to find whether string is palindrome or not ............ .4 - 12
Program 9 : Program to display string in lowercase ................................ .4 - 13
Program 10: Write an 8086 assembly language program (ALP) to add
array of N number stored In the memory ............................ .4 - 14
Program 11 : Write 8086 ALP to perform non-over1ai>P8d block transfer. 4 - 18
Program 12: Write 8086 ALP to find and count negative numbers from
the array of signed numbers stored in memory...................4- 23
Program 13 : Convert BCD to HEX and HEX to BCD ...............................4- 26
Program 14 : Multiplication of two 8-bit numbers ......................................4- 32
Program 15 : Divide 4 digit BCD number by 2 digit BCD number............4- 38
Program 16 : To perforrn conversion of temperature from "F to "C ..........4 - 41
Program 17 : String operation ...................................................................4 - 44
Program 18: String Manipulations............................................................4- 52
Program 19 : Sorting of Array ...................................................................4- 62
Program 20 : Program to search a given byte in the string .......................4- 66
Program 21 : Program to find LCM of two 16-bit unsigned numbers ........4- 67
Program 22 : Program to find HCF of two numbers.................................4 - 68
Program 23 : Program to find LCM of two given numbers........................4 - 70
Copyrighted material
6.10 Transfer Types ................................ ............................................... 6-20
6.10.1 Memory.ro.Memory Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 6 20
6.10.2 Autoinitiafrze . . . .. . . . .. . . . . . . . .... . . . . . . . .... . . . .. . .. . .... . .. . . . .. . . . . 6 21
6.11 Priority .. ........ .. :..................... .................. ................... ................... ... 6- 21
6.11.1 RxedPriority. . . .. . ..... ... . . . . . . . . .. . . . . ..... . . .. .. . ...... . . 6-21
6.11.2 R!lta!i1g Priority .. . . . .... .. . . . . . .. . . . . ...... . ... .. . .. . . . .. . .. . . .. . . . . . 6 - 21
6.12 Register Description ......................................................................... 6- 22
6.13 Interfacing ....................................................................................... 6 - 27
Review Questions 6 - 28
;:_', ., -~ -! . ... , . . . . . .~ . ._ ' . ... . . :"''1.-. . ?..(;' :; ~ ~j"t~i-;'}',_
... '"" .., u ' ~ < - < ,. ~' ..
Copyrighted material
7.12 Control of High Power Devices using 8255 ......................................7 - 4 7
7.1 2.11n~ated Cirruit Buffess . ...... . .. . . . . .. . . . .. . . . . .. .. ... . . . . 7. 47
7 12 2 Traosjsto Buffea 7 - 48
7.12.3 Isolation Circuits . . . . . . . . . . . . . . . . .. . . .. .. . .. . . . . .. . .. . . . . . .. . .. . . . . 7 50
7.12.3.1 El<!drcmagne1leRelays .. . . . . .. . . . . . . . . . . . . . 7 50
7.12.3.2SolidSia18Relays . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-51
7.13 Keyboard and Display lnterfacing .....................................................7 - 51
7 15 Centronics Printer Interlace 7 - 58
Review Questions ...................................................................................7 - 64
Copyrighted material
9.1 Character Input Functions .....................................................................9 3
9.2 Character Display Functions ............... ..................................................9 - 7
9,3 File Control Block Functions .. . ... . . .. .. .. .. .. .... ...... .. .......... ,9 - 8
9.4 Handle Functions ......... .......................................................................9 15
9.5 Memory Management Functions ........................................................9- 22
9.6 Display Functions Provided by ROM 8105 .........................................9 25
9 .7 Printer Functions .................................................................................9 28
10.4.2 Pin Diagram oi8251A.... . . . . . .... . ........ . .... ... . . ... . .. . .... . ...... 10 5
10.4.3 Blook Diagram .......... .. . .. .... .... . .... . .. .... . .. . ...... .... .. ..... 10 7
10.4.4 8251AControl W<llds .... . . . . . . . .. . . . . . . . .... . . . .. . . . ... . .. . .. . .. . . . ... 10 9
1Q.4.5 8251ASta!usW<lld . .... .. .. . .. . .. .... .. . ....... ..... ... .. . .. . ...... . . 10 11
10.4.6 Oa1a Cormulicalion Types ...................... . . . . . . .. . . . . . .. . . . . . 10 12
10.4.7 1nte!facing 8251A to 8066 in 110 Mapped 110 Mode . .. . .......... . .. .. . ...... 10 14
10.4.8 ~ 8251AID 8066 in Memory Mapped 110 . .. . . ..... . . . . . . . ......... 10 15
10.4.9 F'!l!granmil1g Examples ........ . . . ...... . .. .. .. .. .. .... . ....... . ...... 10 - 16
10.5 Serial Communication Protocol (RS232C) ......................................10 17
10.6 Sa mple Programs of Serial Data Transfer......... ..............................10 19
10.6.1 Pro!JllmtoTraMIIIHlneCharaeter ...... .. . ........................... .. 10 - 19
10.6.2 Program to ReceM! One Charaeter ............................. . .. . . . .. . 10 20
10.6.3 PIO!JMl to Transmit Fie . ... ............ . ... ... .... . ... . .. . . . ... 10 20
10.7 Introduction to High-Speed SeriaiCQ!nmunication
Standards. USB ...........................................................,.,..............10 - 22
10.7.1 USB FeallKes ... . .... . . . . . . . ....... . .... . . . .. . . . . . .. . . ... . . . . . . .. . 10 23
10.7.2 Umilation of USB . . . . . .. . . . . . . .. . .. .... . .... . .... . .. . .... . .. . .. . .. . .. . 10-25
10.7.3 Minim\Mn PC Requirements for USB Support .......... . ... . . ....... . .. . . . . . 10 26
10.7.4 USB 'tiered slar" Topology ................. . .............. . .... . .... . .. 10 27
10.7.5 Terminologyusedin USB ......................... . .. ........... .. .. . .. 10-28
10.7.6 Host's Functions . ...... ... .... .. . ...... , ., ........ . .. ... .. . ......... . 10 30
10.7.7 Perip/lela! Fooctions .. . . ... ............ ...... . ..... , .. . .... . .... ... .. . 10-31
10.7.8 USB Cornrnunication . .. . . . . . . .. . ... . ... . .. . . , . . . ... .. ... . . . . , . . . .. . . 10-32
10.7.9 Elements of Transfer .. . . .... . ... .. ..... . .. ... .. ... .. ... ... ... .. . . .... . 1032
10.7.10 Data Transfer Types . .. .. . .... .... .. .. .. .. ... .. . .. . .... .. .... .. . ..... 10 - 34
10.7.1 1 USB Controller. .. . ....... ... .. .. .. ..... ... . .... . ..... ..... .... . . ... . 10 36
Review Questions .................................................................................10 - 37
. - b , , . ,
Copyrighted material
11.4 Memory Organization in 8051 .........................................................11 - 15
11.5 Input/Output Pins, Ports and Circuits .............................................. 11 - 16
11.6 Extemal Data Memory and Program Memory ................................ 11 - 19
11.6.1 ExtemaiProgram Me1110fY. .... ..................... . .......... . .. ... . . . 11 19
11.6.2ExtemaiDalaMemocy . .. . . . . . .... . . . ......... . ..... . .... .. . .. . .... . .. . 11-21
11.6.3 lmporlant P<lints to Remember in Aa:essing External Memory . . . .. . ... . .. .. . 11 23
11.7 Timers and Counters ......................................................................11 - 24
11.7.1 Timer/Counter Control Logic . . . . . . . . . . . . . . . . . . . . .. . .. . .. . . . . . . . . .... , . 11 24
11. 7.2 Timer 0 and Timer 1 ..............,,... , .... , ..,,,,.. , ..................,,,,11 - 25
11.8 Serial Port .......................................................................................11 - 29
11.8.1 Operating Modes fo< Serial Port . . . .. ..... ........ .. .. . .. ... .. .. . .. . . .. . . 11 30
11.8.2 Serial Port Control Register .... . . . .... .. . ... .. ... .. ..... .. . . . .. ...... . .. 11 - 31
11.8.3 Generatilg Bald Rates . . .... . . . . .. . . . . . . .. . . .. . . .... . . . . .. .... . .. . . . . . 11 31
11.9 Interrupt Structure ...........................................................................11 -.33
11.9.1 Priority Level Slruclura . . . . .... . . . . . . .. . . .... . . . ....................... 11 34
11.9.2 Extemal lnteiT\JI)ts . . . . .. . . . . . . .. . . . . . . . .. . . .. . . . .. . .. . .. , . . . . . , . . .. . . . 11 36
11.9.3 Sif9&-Step Operation .... . . . . . . .. . . . . . .. . . . .. ... .. . .. . . . .. .. . . . . . . .. . . 11 36
11 .10 Interfacing 8255 for 1/0 Expansion ...............................................11 - 37
Review Questions ..................................................................................11 - 38
8086 Programs
Peogrom Add two numbe<$ ... ......................... .............................. .......................... .(3 - 69)
Program Find the overage oi tw"o numbers ............... ............. ............. .. ..... ...... ........ .(3 69)
Pmgrom . Find the moximu1n number in lhe Ofi"'y ... ... ... .......... ... .. ..... ... .. ... ..... ....... ... .. (3 - 69)
Progra m - Sea rch o number 1n the o rroy ... ........... ... .. ... .... . ......... ..... .. .. ... ..... ...... . ... ..... (3 70)
Pr rom- Find sum of numbers in the orro ................................. .................... ... ... .... 3 70
Program . Scporo1e even ond odd numbeB in the orroy.............. ....................... .........{J - 7 1)
Program Reod keyboard input ond display it on monitor ............................ .................{4 -1)
Pfogfom Addi~on of lwo 32-bil number> ........... ................. ............. ............. .............(4 - 1)
Program - Addition o f 3 x 3 matrix .. .. ...... ..... ... ... ... ...... ... ............. ... .. ... .. ... .. ... .. ...... .. ...(4 - 2)
Program Reod a password a nd validate uw...................... .......... ... ............... ...........(4 . 4)
Pro g ram Calculate ladOfial of o number ........ ........ ...... ... ..... .......... ..... ..... ........ ........(4 - 5)
Prog ram Reverse the words in string .. ............................ ........ ..... .......... ............. ........(4 7)
Program SeorGh numbers, ofphobets, special characters .............. ... ... m (4 9)
......... ... .. ........
Progrom -Find whether string is palindrome o r not.... ......... ..... ........ .......... ....~.............(-4 12)
Program - To display string.in lowercose ....... ... ..... ...... ............................... ... .......... ...(4 . 13)
Program Write on 8086 assembly longooge program (Al P} lo o dd a rray of N number
stored in the memory.... ...... ......... ..... ...... ... ........ .......... ., ...... .................... (4 14 )
Pro g ram Write 8086 ALP to perform non-cwerlopped block tra nsfer........................... (4 ) 8)
Program - Write 8086 ALP to fi nd ond count negative numbers from the army o f sig ned
numbe($ stored in memory. ............................................ ............... ...........{4 23)
P,og,om Corwert BCV lo HEX and HEX lo BCD .................................. .....................{4 26)
f f0gf0m - MuiNplicoNon of two Bbil numbefS .... ......... ...............................................{4 321
Progom - Divide 4 digit BCD number by 2 diga BCD number...................... ............... (4 - 38)
Ptogrom To pe<fonn convenion oflempe<Oiufe from 'f lo "C........ .................. .......... (4 - 4 1)
Program String operolions .... ..... ......... .. ...... ........ ......... ........ ............. ..... ....... .......... (4 - 44)
Ptogrom Siring Monipulat;ons ................................................................................ (4 - 521
Ptogmm Sot1ing of A"oy.............. ........ ...... ........................................................ .... (4 - 62)
Program Search o g iven byte in the string .......... .. .................................................... (4 ~ 661
ProgfQm Find LCM of two 16 bil uos;gned numbefS ............................................... .. (4 . 67)
Program f;nd HCF of two numbers............. ......................... ...................................(4 - 68)
Pr rom Find lCM of two iven numbets............... ................................................. 4 ~ 70
r h\r
An Overview of 8085
(1 1)
Copyrighted material
Microprocessors and Interfacing 12 An Overview of 11085
11. It has S~bit accumulator, flag register, instruction regis ter, :;:;ix: S.bit ~cneral purpose
registers (6, C, 0 , E, H and L) and two 16-bit registers (SP and PC). Getting the
operand from the general purpose registers is more faster than from memory.
Hence skilled programmers always prefer general purpose registers to store
program v:l.riablcs than memory. ,
12. It p rovides five hardware interrupts : TRAP, RST 7.5, RST 6.5, RST 5.5 and INTR.
13. It has serial 1/0 control wh.ich allows serial communication.
t4. It provides control s ignals (10/M, RD, WR) to control the bus cycles, and hence
external bus COQtroller is not required.
15. The extem..'\1 hardware (another micropnxes.."ttr or equivalent master} can detect
which machine cycle microprocessor is executing using s tatus signals (10/M, S,
5 1). This feature is very useful when more than one processors are using common
system resources (memory and 1/ 0 devices).
16. It has a .n:'echanism by which it is possible to increase its interrupt handling
ca pad ty.
17. The 8085 has an ability to share system bus with Direct Memory Access controller.
This feah.ue allows to transfer large amoun t of data from l/0 device to memory or
from memory to 1/ 0 device wlth high speeds.
18. It c.m be used to implement three ~p microcomputer with supporting 1/0
devices like IC 8155 and IC 8355.
Addres..~/Data buffer
lnrrementer / O.Crementer Address Latch
lnterrupt control
Serial 1/ 0 contro l
Tinting and control circuitry.
Copyrighted material
Mlcn>processors and Interfacing 13 An Overview of 8085
RST8.6 TRAP
ljR"
A
RS~5, 5
Interrupt control
R$~ 7 .5
sr sj
SonO'll IJO control
I
j I k'lsti'Uction
rogh;tQr
~ WR. .
BR
o Reo
HR
c-
ZRoo
ER. .
L Re
"'""""
S lo:l(lk polntor
... ~
unit
ln!llt'Uetion
do<adO<
~
.._.m
coun1er
,r (Ai.U )
"""
.,..,.
"'<>V>'ER { - 5 V
.......,
maehlno
tnctementerf
000'011'1e01Ct
Addreee 18tdl
~' ~>P\.Y -GI>IO
I
J
- ------
CU< x, - Timir'IO tl<~CI COt'ltrol
IN
C LK
GEN
CONTROl. STAl\.15 OMA
----.. RESET
----.. ----..
I Addross
bvl'fer
I IAddress 1 Data
buller
I
Jo Je J. j LD
CU<LuT
w~ ,a,;;;
I
RESET IN u
Au; "e
_U
AD7 ADo
READY HLOA RESET OUT
Addrossbus 0;ll~
....
I AddtCISil
Copyrighted material
Microprocessors and Interfacing 1-4 An Over,iew of 8085
2. Temporary Registers
a) Temporary d?~ta regist~ r b) W and Z regi:;ters
3. Special Purpose Registers
a) Accumulator b) Flng registers c) Ins truction n.."gister
,_
. Copyrighted material
Microprocessors and Interfacing 15 An Overview of 8085
to the addrt.."S.'i given in lhc ins truction. XCHG instruction exchanges the contents of H with
0 and L \\o'ilh E. At the time of exchange W and Z n ..'gi:->ters are u$4..-:.d for tcmpornry
storage of data.
3. Special Purpose Registers :
a) Register A (Accumulator) : It is a tri-state eight bit register. It is extensively used in
arithmetic... logics load, and store opcrations, as well as in,. input/output (1/ 0) operations.
Most or the times thE.> result of arithmetic and logical operations is stored in the register A.
Hence it i~ a lso identified as accumulator.
b) Flag Register : It is an 8-bit register, in which five of the bits carry significant
information in the form of flags : 5 (Sign llag), Z (Zero flag), AC (Auxiliary carry llag), P
(Parity flag), and CY (carry flag), as shown in Fig. 1.3.
o7 o6 o5 o" o3 ~ 01 o0
s z xiAclx iP i x cv
Fig. 1.3 Flag register
5-Sign flag : Aftcr the I!Xt..'Cu tiOJt of arithmetic: or logiC<tl OJX'r.tlions, if bit ~ of the
resull is 1, the sign flag i~ set. In a given byte if 0, is 1, the number wiJI be viewed as
negative number. Tf 0 1 is 0. the number will be ronsiden.>d . as positive number.
ZZero flag : Tile zero flag sets if the result of operation in ALU is zero and flag resets
if result is non zero. The zero flag is also .set if n certain register content lx.'C(,mes 7..t!'n,_)
foUowing an increment or decrement operation of that register.
AC..Auxilia.ry Carry flag : l his flag is set if there ls an overflow out of bit 3 i.e. , carry
from lower nibble to h.igher nibble (03 bit to 0 4 bit). This Oag is used for BCD operations
and it is not .wailable fo r the programmer.
P-Parity flag : Parity is defill(.-'d by the number of ones present in the accumulator.
After an a.rithmctic or logical operation if the result has nn even number of ones, i.e. even
parity, the flag is set If the parity is odd, flag is reset
CY.Carry flag : This flag is set if th~Jre is an overflow l--.ut or bit 7. The carry flilg al:o><)
serves as a botTQw flag for subtraction. In both the ('Xamples s hown below, the c.ury (ln.g
is set.
ADDinCN SUBTRACTION
c) Ins truction Register : ln a typical proces..">>r operation, the paocessor first fNches the
opcodc of instruction from memory (i.e. it places an address on the addre;.'$s bus and
memory responds by placing the data stored at the specified addn.~s on th(' dnta bus). The
CPU stores thi~ opcode in a register called lhc instruction rC'gis tcr. This opcodc is further
sent to ~ instmction decoder to scJcct one of the 256 a ltcm atin..--s.
Copyrighted material
Microproc;e,&,llors ~nil Interfacing 1 -6 An OVerview of 8085
Copyrighted material
Microprocessors and Interfacing 1 7 An Overview of 8085
Copyrighted material
Microprocessors and Interfacing 18 An Overview of 8085
~
2
l
SV
""
~0
tv,...
x, Vee .. SID <
x, X, Vee
110 SOD
xz HOeD
..
28
RESETOlfT HU>A
.............
SOD Cu<{OUT) ,...,
bLa
address
y
~
"'" RT:.SET IN RST75
RSTts.S
7
""'"
~Sl7.S
READY
10/ Ii ..
RSTS..5
,.,.
ADo
AD,
.......,....
Multlpfelle<l )
RS1 6,5
1\,; ""'
READY
R5f5,5 Ro H04.0 ,.
35
NTR WR RESET IN 38
......
iNTA
"""
AD,
.....
ALE
INTA 11
..."",. "'
... ALE
...,, s,
AD2 29
33
AD,
... Ro
...
AD, 31
Wif
ADo
AD,
v~,
..... 31
Fig. 1.4 (a) Pin configuration
Rt;SET OU f
"''
CIJ< 0\IT
Fig. 1.4 (b) Functional pin diagram
a) Power supply a !'\d frequency s ignals.
b) Data bus and address bus
c) Control bus
d) interrupt signals
e) Serial 1/0 signals
I) OMA signals
g) Reset signaL
Copyrighted material
Mlci'O!>'ocessors and Interfacing 1 -9 An Ove<VIew of 8085
mtching of lower half of an address bus is done by using external latch and ALE signal
from 8085.
8) iO and WR : These sign..1J:s are basicaUy used to control the direction of the data
flow between processor and memory or l/ 0 device/port. A low on RD indicah.'S that the
data must be read from the selected memory location or l/0 port via data bus. A low on
WR i nd i cat~$ that the data rr,u$1 be written into th<' ~k-ctcd memory locntion or 1/0 port
via datil bus.
0 IOIM1 5 0 and S 1 10/M ind ict\fet' whether 1/0 opc-rt~tion or memory operation ls
:
being carried out. 5 1 and Su indicate the type of machine cycle in prog-ress.
0) READY : It is uS(.od by the microprocessor to sense whether a ~riphcral is ready or
not for dat.l transfer. lf not, the processor waHs. Jt is thus used to sync.hronire s lower
peripherals to tht- microprocessor.
Copyrighted material
Mlcroproc:.ssors and lnt.rfaclng 110 An Overv~w of 8085
Copyrighted material
MlctoprocHoors ond Interfacing 1 -1 1 An Overview of 808S
'-- T a
X
'
Clk
' 0
X
Fig. 1.5 Block diagram of built-in clock generotor
LC Tuned Circuit :
It is a LC rt$0n., nt tank circuit. The
resonant frequency for this circuit is given by
x,
L c~= I
f, =
2nJL(C..., +C;~ )
X:!
Where Cin, is the internal capacita.nce: and
it is normally 15 pF. The output frequency of
Fig. 1.6 LC circuit
this circuit has 10% variations. To minimize
the variations in the output frequency, U is recommended to have Cex1 at lei\St twice that
of c,. i.e. 30 pF.
RC Tuned Circuit : Fig. 1.7 shows the RC tuned
circuit. The output frequency of this circuit Is also
not exactly stable. But this circuit has an advantage
x,
that its component cost is less. c R
I-
.
Crystal Ooclllator Circuit : Fig. 1.8 shows the Xz
crystal oscillator circu..it. It is the most s table drcuit.
The 20 pF capacitor in the circuit is connected to
assure oscillator s tart-up at the correct frequency. Fig. 1.7 RC Circuit
Copyrighted material
SV
x, Pull-up
Crystal~ resistance
External
+-- -IX2 dook x,
8085
c-
I ~"~----i~X!
(NC)
___________j
Fig. 1.8 Crystal clock circuit Ftg. 1.9 External frequency source
External Clock :
Fig. 1.9 shows how to drive dock input of 8085 with e:xt{>mal fn:..>q ut!ncy source. Here
external clock is ;sppliccl at X1 input and X 2 input is kept open.
Copyrighted material
Microprocessors and Interfacing 1 1 3 An Overview of 8085
IC 74LS373
ADo
AD 1
D o:-{1
ADz
CU<
AD3
AD4
ADs
AD6
AD7
G ~
Enable Output con
ALE -
Do
D,
Dz
D,
D,
D.
D.
D,
Fig. 1.10 Latchi ng cln:ult
SV
IN 4148 7SK
1000
+---~~To 8085
....
~
Copyrighted material
Mieropt"ocessors and Interfacing 1 14 An Overview of 8085
As we know that, a fter power up or reset 8085 etches its first in.~truction (rom OIXX)H
address, and it has to be tht> first instn1ction from monitor program. Therefore EPROM
consisting o monHor prot,7"fclm must be located from address CXlOOH in any 8085
micropr<.lCt..~Sor system.
8085
101!:1
R!!
I'm
-"'
_/ IIDm
_/ MEMW
'7
) lOR
= ,/ lOW
Copyrighted material
Microprocessors and Interfacing 1 -15 An Overview of 8085
0 0 1 0 1 1 1
0 1 0 1 0 1 ,
0 , 1 1 1 1 1
1 , 0 1 , 1 0
, 1 1 , 1 1 1
Table 1.1
S.1me truth table can be implemented using 3:8 decoder as shown in fig. 1.13.
y- sv
I
G Vee Yo
Y,
3:8
v,
WR A Decoder v,
Ro B v,
10lM c (74l$13a) v,
Y,
v,
~. ~
I
.l
Fig. 1.13 Generation of control signals using 3:8 decoder
Copyrighted material
,
Unidirectional Buffers : I
20
As we know, the address bus is 1A1 Vee~ m
unidirectiona l. 8hit unidin.'Ction:;tl b u ff~r.
2
"'(.
IY I
I
I._, IY2
..
74lS244 is usc.->d to buffer higher address I
bus. The Fig. 1.14 ~h Ow$ the logic ,...
diagram of 74LS244. ll consists of eight , "1..
IY,
I
noninverting buffers with b'istate
'"
IY,
outputs. Each one can sink 24 mA and 1-?
,...
I
'
sourtt IS mA of current. Th ~ :c bufferS
are d ivided into two groups. The
..... zv,
12'1. 2Y,
enabling and dlsabUng ~these groups ../",
J re controlled by IG a.nd 2G lines. " ,., zv,
'
Bi-directional Buffer : "
To incr~"~se the d riving capacity of 17
..... ,... 2Y,
5 ~
A,
<ll- a.,
e,
18
15
Enable
ll"
Ofredion
control
OIR
Opet atiOn
,
L L 8 Data to A Bus
6
7
Ao ,. ..... .....
e.
a.
14 L
H
H
X
A Data to B Sus
ISOlation
8 A,
"" s,
13
12
H=High tevei,.L=Low levei,X=IrreleYanl
T
9 Ae
DIR ll"
a. 11
1 19
Diledion Enable
conlrol
Copyrighted material
~andlnle<fadng 1 17 An Ov..vt.w of 8085
741.SJ73
J.!--.... - -...
LDw
1085A
SV
J4UI2AS
1K
I ....
8klir'Ktional
""-
-
T-.a131
d loccdlr
It also shows d ock <u\d reset cin:uiht Interrupt lines whkh arc not in usc are
grotmded. This is nccess.u y bccau~efloating intetrupt line may cause false triggC'ring of
interrupt. Similarly, since the DMA controller is not used, HOLD line iot also grounded. As
~'-'C know READY signal is used to synchronize slow peripherals with the mkropn:>ees.~r.
When it is low, microproces.._.;;or enters in the wait s tate and when it is high, it indicak"S
that the memory or pl>Tipher<tl is ready to send or receive data. Here, the READY s ignal is
tied high to prevent the microprocessor from entering the wait state. ALE signal is
connected to the clock input of the latch, to latch the low order oddress in T , of the
mt'lchinc cyc.le. To control the direction of the bi..mrecti<mal buffer 74LS245, RD signal from
8085 is conncct'ed to DIR input of tM bi-directional buffer. Thus, w~ RD signal is low,
DIR is low and data flows f-rom memory or 1/0 device to the microprocessor, performing
read operation. When RD signal is high. DJR is high <'11\d data flows from microprocessor
to memory or l/0 device performing write operation
lhsttuction cycle
Fig. 1.17 Relation between instruction eye'-, machine cycle and T--state
There arc Sl'Ven different types of machine cycles in the BOSSA. nucc status s ignals
10/M, 5 1 and S, identify each type as shown in Table 1.2. These signals are generated at
the beginning of each machine cycle and remained valid for th~ duration of the cycle.
Copyrighted material
Microprocessors and Interfacing 1 -19 An Overview of 8085
10/M $1 So RD WR tNTA
Opoode Fetch 0 I 1 0 1 1
Memory Read 0 1 0 0 1 1
Memo<y Wri1e 0 0 1 1 0 1
110 Read 1 1 0 0 1 1
LfO W rite 1 0 1 1 0 1
INTR Acknowledge 1 1 1 1 1 0
Sus ldte 0 0 0 1 1 1
Representation of Signals
Before btling to see the timing diagram, w~ wiiJ see the signals and thcjr
n...,rescntation u..-;,.."'<1 i1\ the timing diagrams.
1. Clock Signal :
The 8085 divides the dock frcqul'ncy provided at X1 and X2 inputs by 2., which is
c:aUOO operating frequency. All the operations within the 8085 are synchronized with this
operating frequency. lllerefore in the timing d iagram operating frequency clock is shown
on the top and then the signals are s hown with referen~ to opt.~ating frequency dock.
Ideally, the dock signal should be square wave with zero rise time and fall time, as shown
in the figure. But in practice, we don't get zero rise time and fall time. Therefore the dock
and other signals are always ~hown with finite rise :md fall times. Fig. 1.18 shows the
practical way of representing dock signal
Sll)llle Signal :
Single signal is represented by a line. It may have status either logic 0 or logic 1 or
tri--state. The change in the state of the signal takes finite time and hence the state change
of signal is represented with finite rise time and fall time, as shown in the Fig. 1.19.
Copyrighted material
Microprocessors and Interfacing 1. 20 An Overview of 801$5
Logic 1 Log;< 1
( ((
) ))
Logic 0 ~I I
Tri-state /
\ LogicO
T,-i !.- r,-. r -
___,X,- 7
X 1
~ - -~..__
! 1 Tristatet-
_ _X
"-.State cnange !- Valid state- n i
Copyrighted material
Microprocessors and Interfacing , ~1 21 An Overview of 8085
'
;1 Others!
A
'-l 11 '-l
\
~ Actlva
"'-..
signal
(a) Activation of signal with the (b) Activation of signal with the
change in state of other signal change In state of other signal
(e) Activation of a signal with the (d) Activation of signals with the
change in state of othef' signals change in stale of other signals
Fig. 1.21
Signal Timings
In 8085 microprocessor, signals are activah..'<i at spedfic instant for specific time period.
Once we understand thi!', it i~ very easy to draw liming diagrams. The following St."Ction
explains wht'1' the signals are activated and for what period they ren\llin in acti\'C state.
ALE (Address Latch Enable) :
This signal is active high signal It is activated in the lx.>ginning of lhc T 1 state o( each
machine cycle, except btL~ tdlc machine cycle, and it remains active ln the T 1 state as
shown in the Fig. 1.22.
Copyrighted material
Microprocessors and Interfacing 1 -22 An OVerview ol 8085
''
- - - - - - - - - - - + ---Ma<...,.oyde2- ---f
'
T1 I
I I
8
! I
I
'' '' ''
'' '
!' !'
}-------{ 0.1>
~
i ~' - X .,... ~!
Copyrighted material
~lcroprocessors and Interfacing _ _ ' 1 - 23 . An Overview of 8085
To read data from memory or l/0 d(!Vicc it is n l"CCSS.1ty to scled memory or 1/0
devire. Alter selection. devlre will put t.he dota from selecled location on the data bus.
nus action needs finil'e time. ThJs time is rck-rr(.-d to t\S acce:ss Umt " . In case of write
cycle, data is available in the regl~tcrs of the miCTOpi'OCeSI50r and H can put that data on
the data bus with zero access time.
As we know data transfer in 8085 tak'-"S pl.,ce during T2 and TJt lhese signals are
activated during T, and T_,. as shown in the r'S 1.27.
ate
r
r, r, r,
1!0+---+.
Step 1 : (State T 1) In T 1 statt, th" &l65 places the contents of program rowtter on the
address bus. The rugh-order byte of the PC is placed on the A8-A 15 lines. The low-order
byte of the PC is placed on the A00 A07 lines which stays on only during T 1 Thus
microproc:e.o;or activates ALE (Address Latch En.1ble) which is used to latch the low-order
byte of the address in external latch before It disappears.
In T1, 8085 also ..,nds slants s ignals 10/M, 51, and S,. 10/M specifies whether it is a
memory or l/0 operation, 51 s tatus specifies whether it is read/write operation; 5 1 and So
togctht."'!' indici\tes read, write, oprode (etch, machine cycle opention., or whether it is in
HALT state. In opcode retd 1 m.:1<:hine cycle status s:ign.'lls a re: 10/M 0, 5 1 1, So t.
Copyrighted material
IR ~-- dill 1:
r---------------------------------------
Opoode leleh
lnstru<::tlon B c T, r, T, r,
reglsle<
(!R) 0
H
E
l I Cll
\ - 1\ - L 1\ r l
Instruction
dooodor
(!D) '
---
SP
PC
'
........................ I
'''
'''
-''
A,
Ao'::X
High order memory addresa Unspedl\od
\
I
)( oil
'
':Ao7~ADo
:r
AO,
-yLow ...., }-< Opoodo --- -- --
-
AO,
' Tuning AI.E ' Latch
- Mtm<wy
' odd"'" 1
and ~
''' ''
'
1/
t:
: A7 ALE
:
' - - - ~imcwy---------------- ' "" \
101 M
iH Stalus 10 t tlO.S0 1,S,1 Opoodefetoh }
i~
A 15
' - i
J
mli
\) I
' ~
i
IAemoty
...d
0 o.......
0
"0
b
'< - ll'ldltetes dte flow. - - lndicales address f'low
~
Step 2 : (State T,) In T2, low-order addre<S disappearS from the AD0 AO, lines.
(However Ao A7 remain availabl~ as they were Ia~ during T1). In T2, 80&5 scnd'i RD
signal low to enable the addressed memory location. Dle memory device then places the
contents of addressed memory location on the data bus (AD0 AO,).
Step 3 : (State T,)_During T,_ 8085 loads the data from the data bus in its Instruction
Register and raises RD to high which disables the memory device.
Step 4 : (State T4 ) In T4 , microprocessor decodes the oprode, and on the basis of the
instruction received, it decides whether to enter state T5 or to enter s tate T1 of the next
machine cyd e. One byte ins tn tctions those operate on eight bit data (8 bit operand) are
r..
ext."Ctlted in .
For example : MOV A, B, ANA D, ADD 13, lNR L, OCR C, RAL and many more.
Note : For one byte in.o;tructions which operate on eight bit data_, data is a lways available
in the internal memory of 8085 i.e. registers.
Copyrighted material
r---------------------------------------------j ~
'
Me"""" Road
A IR
II
p I-
t-
T, r, r,
H 1- CLK l
SPI-
PC f-
lO
--- -------
''tAD, ADo
A,s - Ae MemOf)' address J
: r t--
11mi11Q
and
ALE ''
j:h
AI.
~
-
control :
: A; Ao '
AO, - ADo - Data from memory --- !:l
---- ----~----- --------
~
Memory t Data bus
I
---------
read ! L
1
0
0
"0
'<
~
- fn$1iC@..teS data flow, - - Indicates address now
<0' {a) Data now from memory to microprocessor (b) Memory read machine cycle !1.
::r
~
3
Fig . 1.29
I
*"'
"'
~-- - - - - - - --- - ------ - --------------- - -- - - -- - ----- 0
A B c r, r, r,
IR
0 E
10 '
H
SP
PC
l
'
''
'''
'''
__,''
CLK
v v v &.
i
~
' :A
--- -------
'
' ~ADo
A15 - Aa
~ Memory address
il
Timing
and
ALE
''
'' Latch ALE V\ -
.''' ,..,
conlrd
h
X..,_... X
- ................M.-.,;;;- ..........................
' "<>
A01 - A00
,..- Data from CPU
tl
10/M ~ 10/ Q a Q, S 1 0. So 1
A,s i Ae
-'
0
0
'
Memory
' ;;.
I'm
r ,..
"
write
I
"0
'<
~
cO.
::r
1tr Data bus
Step 2 : (State T 2) In T 2, 8085 sends RD s ignal low to enable the addressed memory
location. The memory device then p laces the contents of addressed memory location on the
data bu< (AD0 -AD1).
Step 3 : (Sta1e T, ) During T3- 8085 loads the data from the data bus into specified
register (F, A, B, C, D, E, H, and L) and raises RD to high which disables the memory
device.
3. Memory Write Cycle
The 8085 executes the memory write cydc to s tore the data into data memory or ~ lack
memory. The length of this machine cycle is 3T states (T1 - T,). In this machine cycle,
processor places the address on th(' address lines from the stack pointer or general
purpose register pair and through the write process_, stores the data into the addressed
memory location. Fig. 1.30 (~ Fig. on previous page) shows the timing diagram for
memory write machine cydl'. The memory write timing dingram is s imilar to the memory
read timing diagram, except that instead of RO, WR signal goes low during T2 and T3. The
st<ltus s ignals for memory write cycle are : 10/M :: 0, S1 :: 0, 5o :: 1. The following section
describes the memory write machine cycle in step by step manner.
Stop 1 : (State T 1) In T 1 s tate, the 8085 places the add ress on the address lines from
stack pointer or ge1'\crnl purpose regio;ter pa ir and activ<'!tes ALE signal in order to latch
low~rder byte of address. During T 1, 8085 sends status s ignals :
Copyrighted material
1:
~---------------------------------- ------ --- --- - ---,
=: f
A 8 c T,
1/0 Read
r, T,
i
IR
v v v
0 E
H l
'
0
- &
10 ' '
SP
PC
..,.,
lmlng
conlrol
ALE
1- La!Ch
ADr - Allo X 1/ 0Add } 1/00ela
-
IS
'''
',_ ---------------------------
........ '
'
~u
~
\ I
Input
' OOIIJ. $1 ,s, X 10~0 1, S, 1, SoO
OR '
device
0
0 ..,.... 4--'
~
IL
"0 1/0
I
'< rea<!
~ Data bus
<0'
::r
- lndicetes data flow, -- Indicates address flow
~
3
(a) ON flow from Input device to mJcroproceuor (b) UO read memory cycle a
Fig. 1.31
i
*"'
"'
ll:
~----------- ------------- ------ - - - - -- - - --- ---------
1/0 Write
8 c
A
IR
0 E
T, r, ..a
I -
H
SP
PC
L
CLK
v v v i
I' --- '
10 :I
--'' ------- I
AD, l1AD0
ALE
"'
''
nm~~>g
''
''
A,s ... Ae X 1/ 0Addr
-
ALE ~
on<l 1-' La1C11
''
c:onlrOI A~ - AD0
' X "o"""' Data from MPU "'
~
''
---------------------------'
A,Aa '
I
1'\lft
r'
--' IO~ M= 1,S 1 =0.S<l = 1
Output
deYi<:e OR '
10 / M, S1, So X
'
ArAo ~
1/0
wri1e J ~ Dota bus
f
0
0
"0 - Indicates data flow, - ..... Indicates address flow
'<
~
<0' () o.ta now from mlcroproceuor to output devlc. (b) 110 write machine cycle 9.
::r
~
Fig. 1.32
!...
3
*"'
"'
MicroproceHOrs and Interfacing 1-32 An Overview of 8085
r, r,
M
r,
Re$1811 1nsttuc1i0n
M1
r, r,
..,r, r,
r, T,
' T, T,
ClOCK
A 8-A15
J v J v J v J vv J (SP-1)H
V' v
(SP-2)1-t
'-
I
AD4-AD1 R T --- --- --- .... 0 ,(PCH) ..., il!E
AlE_ { \ '\ '\ ...
INTR
~ 1--
INTA
OIM.s,.s,
" (1,1,1 10. ,1} (0,0.1)
1m
1'11'1 r r-
Copyrighted material
Microprocessors and Interfacing 1 - 33 An Overview of 8085
1.: ~ l..
~~ ;..:' 'j
)
l{
;. "
1,: >< c
I'"" ~
~ -t
;,.!' 'j
1,: ) >< ~ c :>::<
"
"
I'""
1.:
I'"'"
s1
~ >< c
---1
~
>
)
~
1>-" I
,r 1.: ~
1.: 'j >< c ><
1,.!' ) ~
t -"
1.: ~ 5 .:~
7. - Idle Cycle
'There are few situations where the machine cycles are neither Read nor Write. These
situations are :
Copyrighted material
Microprocessors and Interfacing 1 -34 An Overview of 8085
1. For exenation of DAD instruction (this instruction adds the contents of a s pecified
rcg:ist~ r pa ir h) the contents of Hl register pair) ten T s tates are required. This means that
after CXL>eution of opcodc fetch machine cycle, DAD instruction rcquir('S 6 extra T-stat~ to
add 16 bit (Ontents of a specified rt"gislcr pair to the contents of HL register pair . These
extra Tstatcs which are divided into two machine cycles do no t involve any memory or
1/ 0 operation. These machine cycles arc called BUS IDLE machine cycles. Fig. 1.35 shows
Bus Idle Machine Cycle for DAD instruction.
;;m __/
INTA __/
In the case of DAD, these Bus Idle cycles arc s imilar to mt.>mory road cycles, except RO
and ALE s ignal'\ are not activated.
2. During internal opcode generations, for TRAP and RST interrupts, 8085 executes Bus
Idle Machine Cycles. Fig. 1.36 shows the Bus Idle Machine Cycle for TRAP. In response to
TRAP interrupt, 8085 enter> into a Bus Idle Machine Cycle d uring which it invokes restart
instruction, stores the contents of PC onto the stack and p1aces ()()24_H (Vector addrcs."'i of
TRAP) onto the progrnm counter.
Copyrighted material
Microprocessors and Interfacing 1. 35 An OvOfView of 8085
TRAP
f._/1
sv v v v v \J \J \J
10/M
s,.s,
......... 0'<-'" ""'
($P.1)l
IN OUT OUT IN
A00 A01 --- PC' --- - f-- -- ---- ""'" PCH
AI.E h h
tNTA
1m
1-'
\VI!
READY
I
Copyrighted material
..
Microprocessors and Interfacing 1 - 31; An Overview of 8085
transfer data or not. lf READY pin is high. the peripheral is r('a d y otherwi~ 8085 enters
wait state.
Fig. 1.37 show~ the timing d i,1 ~nun for memory rt!ad machine ~.--ycle with and without
wait state.
r, r, r, r, r, TWAir
'
1-
CLK
\J \J \J ~ ~ \J \J
1-
tx:Klt'O O(MRI OFt t(JORI. s,1, &, oX
1-
0 (MR) OR I(IOA). S 1
I
I
I ,~ 0
X.
1-
1-
:X I X I
X.
OUT N OUT IN
1-
AD0 - AD 7
1-
:X,._ ., -{ o.-o, A,- A, ~ - o, } 1-~
"( \
ALE h {\ I ',....
1-
I I
Fig. 1.37 Rnd machine cycle with and without wait state
Wait states continue to be inserted as long as READY is Jaw. After the wajt state, 8085
continues with T3 of the- machine cycle. During a wait state the contents of the address
bu., lhe data bus, and lhe conlrol bus are all held conslanl
11le wait state thew\ gives an addl'l"SS4.>d memory or 1/0 port an extra dock cycle time
lo output valid dam on lhe data bus. This feajure allows to use cheaper memory a< 1/ 0
dl~ices that have longer aca..""'S..; times.
Copyrighted material
Microprocessors and Interfacing 1-37 An Overview of 8085
2. MVI M, data (8) This instruction directly loads an 8-bit data given within the
instruction into a mentory location. The memory loc-ation is
specified by the contents of HL register pair.
Example : H =20H and L =SOH
MVI M, 40H ; This in.~truc-t:i ol\ will load 40H into
; memory whose address is 2050H.
3. MOV rd, rs This instruction et:lpies data from the source rcgl<tk.--r into destination
register. The rs and rd arc general purpose registers s uch as A.~ 8, C,
0, E. H and L The C()nten ts of the source register rema.in
unchanged after cx('C'ution of the instruction.
Example : A= 20H
4. MOV M, rs This instruction copies datn from the source register into memory
location pointed by the HL register pair. The rs is an 8-bit general
purpose register >-uch as A, 8, C, D, E, H and l.
5. MOV rd, M This ins truction copie~ data from rn~mory location whose addre:o:-o ito
specified by HL regis ter pair into destination register. Tht.- ronlenl..;
of the memory location remain \lnchanged. The rd is an S..bil
general purpose register such as A, B, C, D, E, H l'lnd L.
Example : HL = 2050H, content~
a t 2050H memory location = 40H
MOVC, M ; This instruction will copy the contents
; of memory location pointed by HL
; register pair (40H) into the C register.
Copyrighted material
.-
Microprocessors and Interfacing 1. 38 An Oveoylew of 8085
6. LXI rp, data (16) This iru;tn tction loads immediate 16 )it data specified within the
in..,truction into register pair or s tack pointer. The rp is 16--bit
rl!g-ister pair such as BC. DE. Hl or 16--bil stack pointer.
Example :
i. !.XI B. 1020H ; This instruction will load lOH into 6
; register and 20H in to C register.
7. STA addr Thi.s instruction stores the contents of A register into the memory
locatiOI\ whose address ls directly specified w ithin the instructiott.
The contents of A register remain unchanged.
Example : A SOH
9. SHLD addr This instruction stores the contents of L register in the memory
location given within the instruction and contents of H register at
address next to it. This instruction is used to store the contcnl~ of H
and l registers directly into the memory. The contents of the H and
L registers remain unchanged.
Example : H=30H, L= 60H
SHI.D 2SOOH ; This instruction will ropy
; the contents "' L register at
; address 2SOOH and the contents
; of H register at address 2SOIH,
10. LHLD addr This instruction copies the contents of the memory location given
within the instruction into the L register and the contents of the
next memory location into the H regisU!r.
Copyrighted material
Microprocessors and Interfacing 1 . 39 An Overview o f 8085
11. STAX rp This instn1ction copies the contents o( ACCtl.muliltor into the memory
location whtloSe address is specifit.'*CI by the sp~fi<.-'d register pair.
The rp is BC or DE register pair. Thi.o;; register pair is used as a
memory pointer. The contents of the nccumulator remain
unchanged.
Example : BC ~ 1020H, A = 50H
12. LOAX rp This ii''IStrucliol\ copies the contents o( memory location whose
address is specified by the rcgish.'r pair into the accumulator. The rp
is BC or DE register pair. The register pair is used as a memory
poin ter.
13. XCHG TIUs instruction exchanges the con ten ts of the regis ter H w ith that
o f D and of L with that of E.
Exemple : DE = 2040H, Hl = 7080H
XCHG ; This instn1ction will load the data into registers as follows
; H = 20H., L = 40H, D = 70H and E 80
Copyrighted material
Microprocessors and Interfacing 1 -40 An Overview of 8085
ADDC ; This instructkm will add the contents of C reg:isrer~ i.e. data
; 30H to the contents of accumulator, i.e. data 20H and it will
; store the rt.--sult SOH in the accumulator.
2. ADD M This instruction adds the contents of the memory location pointed
by HL register pair to the contt..~ts of accumulator and stores rt..'SUH
in the accumulator. Tile HL register p:tir is used as a memory
pointer. This instruction affects all flags.
Example : A = 20H, HL = 2050H,
; (2050H) = lOH
ADDM ; This in..cotruction will .1dd the contents of memory loc.1tion
; pointed by HL register pair, 2050H i.e. data lOH to the
; contents of accumulator i e. data 20H and it will store the
; result, 30H in the accumulntor.
3. ADI data (8) Th.is instruction adds the 8 bit dllta given within the instruction to
the contents of accumulator and stores the result in the accumulator.
Example : A = 50H
AD! 70H ; This instruction wiU add 70H to the contents of the
; accumulator (SOH) and it will store the result in the
; accumulator (COH).
4. ADC r This lmtruction adds the contents of specified rL'gister to the
contents of accumulator with carry. This means, if the carry flag is
set by some previous operation. it adds I and the contents of the
specified register to the contents of accumulator, else it adds the
contents of the specified register only. The r is 8-bit general Plll'J'O""
register such as A. 8, C, D, E, H and L.
Example : Carry flog ~ 1, A c 50H., C 20H
ADCC ; This instruction will add the contents of C (20H) register to
; the contents of accumulator (50H) with carry (1) and
; it will store result, 71H (50H + 20H + 1 = 71H) in the
; accumulator
5. ADC M This instruction adds the contents of memory location pointed by
HL register pair to the conter\ts o( accumulator with c.1rry and
s tores tlle result in the accumulator. HL register pair is used as a
memory pointer.
Copyrighted material
Mlc:topn>cesiOI'S and lnterfaclf111 1 -41 An Overview of 8085
6. ACI data (8) This instruction adds 8 bit data given within the instruction to the
contents of accumulator with carry n.nd ston."S result in the
accumulator.
7. DAD rp This instruction adds the contenl~ of the specified regislcr pair to
the contents of the HL register pair and stores the result in the HL
register pair. The rp is l~b it register pair such as BC. DE, Hl or
stack pointer. Only higher order regLter is to be specified for
register pair within the instruction.
8. SUB r This instntction subtr-acts the contents of the specified register from
the contents of the accumulator and stores the result in the
aurnulator. The regis ter r is s.bit general purpose register such as
A, 8, C, 0, E, H and L
Example: A SOH, B 30H.
SUB B ; This ln.<truction will subtract the contents of B register (30H)
; from the contents of accumulator (SOH) and s tores the result
; (20H) in the accumulator.
9. SUB M This instruction subtracts the contents of the memory location
pointed by HL register pair from the contents of accumulator and
stores the result in the accumulator. Th~ HL register pair is used ns
a memory pointer.
Example : HL = 1020H, A = SOH, (1020H) = IOH
Copyrighted material
Microproc;euors and Interfacing 1 42 An Overview of 8085
SUI 20H ; This instruction will subtract 20H from the contents of
; accumulator (40H). It will store the result (20H) in the
; accumulator.
11. SBB r This instruction s ubtracts the specified register contents and borrow
flag from the accumulator contents. This means, if the carry flag
(borrow for subtraction) is set by some previous operation, it
subtracts 1 and the contents of the specified register from the
()ontents of ac:cumuJator" else it subtracts the contents of the
specified register onJy. The register r is 8-bit register such as A, B,
C, 0 , E, H and L.
Example : Carry flag = I, C = 20H, A = 40H
SBB C ; This instruction will subtract the con t~ ts of C register (20H)
; and carry flag (I) from the contents of accumulator (40H).
; It will store the result (40H - 20H- I e IFH) in the
; accumulator.
12. SBB M This instn1dion subtracts the contents of memory location pointed
by HL register pair from the contents of accumulator and botTOw
flag and s to.-es the r('SUit in the aCcumulator.
Exomple : Carry lias = I, HL = 2050H, A =5oH, (2050H ) = IOH.
SBB M ; This instruction wilJ subtract the contents of memory location
; pointc>d by HL register pair, 2050H, i.e. data !OH and borrow
; (Carry flag ~ I) from the contents of accumulator (SOH) and
; s tores tlw result 3FH in the accumulator (50 - 10 - 1 = 3F).
13. SBI data (8) This instruction subtracts 8 bit data given within the instruction and
borrow nag frorn the contents of accumulator and stores the result
in the accmnulator.
Copyrighted material
MlctOprocessors and Interfacing 1 43 An Overview of 8085
; BCD
If A ~ 1001 0 110 = 96 BCD
and D = 0000 01 11 = (17 BCD then
ADD D ; Gives A 1001 HOI 9 DH
DAA ; adds 0110 because 1101 > 9,
; A = 1010 0011 = AJH
; 1010 > 9 so adds 0110 0000
; A ~ 0000 0011 ~ 03 BCD, CF ~ I.
Copyrighted mat~da]
Microprocessors and Interfacing An Overview of 8085
; data JOH by one. II wiU store the result (30 + l = 3JH) at the
; same place.
17. INX '1' This instruction increments the contents of rc~;ister pair by one. 11le
result is stored in the same register pair. TI\c rp L~ n.--gister pair such
as BC, DE, HL or stacl< pointer (SP).
Example : HL = IOFFH
INX H ; This instruction will increment the contents of HL register
; pair ( IOFPH) by one. It will stnre the result
; (IOFF + I = IIOOH) in the same i.e. HL register pair.
18. OCR r This instnaction decrements the contents of the specified register by
ont.'. It s h.) res the result in till' samt> rt.ogister. The register r is 3-bit
gcner.-d purpose n.--gist('f' s uch as A, 6,~ C, D, E, H and L
Example : E = 20H
OCR E ; This in.o;truction will decrement the rontents of E register
; (201-fi by one. II will store the result (20 - I = IFH) in the
; same, l.e. E register.
Copyrighted material
Mlcrop,.,.,.ssors and Interfacing 1 -45 An Overview of 8035
Copyrighted material
Microprocessors and Interfacing 1 - 46 An Overview of 8085
cc Call on cany CY = 1
CNC Call on not cany CY = 0
CP Call on positive 5=0
CM Call on minus s =1
CPE Call on parity even P 1
CPO Call on parity Odd P= O
SP-+ 27FD 00
27FE 62
27FF
RET ; This instruction will load PC with 6200H and it wiU transfer
; program control to the addre<s 6200H. It will also increment
; the stack pointer by two.
6. R condition This instruction retum'> the control to the main program if the
specified condition is satisfied. Table 1.5 shows the possible
conditions for return.
Copyrighted material
Microprocessors and Interfacing 1. 47 An Overview of 8085
Copyrighted material
Microprocessors and Interfacing 1 48 An OvMView of 8085
Copyrighted material
Microprocessors and lnterfaclng 1 - 49 An Overview of aoas
4. XRA r This instruction logically XORs lhe contents o f the specified register
with the contents of accumu1ator and stores the result in tl'\(>
accumulator. The reboister r ls 8--bit general p urpose n...ob.tcr :-;udl a:;
A, 8, C, 0, E, H and L.
Example A = 1010 1010 (AAH)
; C 0010 1101 (2DH)
XRAC ; This instruction will logically XOR the contents o f C register
1010 1010 ; w ith the oonte1\ts of accumulator. It will store the resu.lt
0010 1101 ; (87H) in the accumulator.
7. ORA r This ins truction log;ic41lly ORs tlw -conten ts vf ~pt.xoili...J r\.!:-;i:.h:l' with
the oontcr.ts of accumulator and stor...--s the result in thl .lC(tunul.lh lr.
Each bit in the accumulator i!' OR(od with cc-.rrl""'puud i n ~~ l'lit in
rt.-g:i~tcr r. i.e. 0.,1 b it in <
lccmnulato r i:-; ORtc-d \Vith D,, bu u1 .....~, ...:.._.,
Copyrighted material
Microprocessors and Interfaci ng 1-50 An Overview of 8085
9. ORI data This instruction logically ORs the 8 bit data given in the in.'itruction
with thl" contents of the accumulator and s tores the result in the
accumu1ator.
Example A = 1011 0011 = (B3H)
O RJ O~H ; This instruction will logically OR the contents of accumulator
1011 0011 ; (B3H) with OSH. It will store the result (BBH) in the
ll(J(JO Ill()() ; accumulntor.
10. CMP r This instruction subtracts the contents of the specified register from
contents of the accumulator and sets the condition flags as a result
u( the s ubtraction. lt set-s Zt.>n> flag if A r and ~ carry flag if
A < r. The register r is S.bit general purpose register such ilS A, B,
C, 0, E, H and L.
Example : ; A 101'1 1000 (B8H) ond D 1011 100l(B9H)
CMPD ; This instruction will compare the contents of D register . ~ith
Copyrighted material
Microprocessor$ and Interfacing 1 51 An Overview of 8oS5
11. CMP M This ins truction subtracts the oon~ents of the memory location
specified by HL register pair from the contents of the accumulator
and s<!'ts the condition flags as a ~"Ult of ~mb traction. It ~ts zertt
flag if A = M and sets carry flag if A < M. The HL regis ter pair is
used as a memory pointer.
Example ; A = 1011 1000 (B8H), HL ~ 2050H
; and (2050H) 1011 1000 (B8H)
CMPM ; This instruction will compare the contents of Memory
; loca tion (88H) and the contents of accumulator. Here A = M
; so zero flag will set after the execution o the instn1ction.
12. CPI data nus instruction s ubtracts the 8 bit data given in the instruction from
the contents of the accumulator and sets the condition flags as a
result of subtraction. It sets zero flag if A = data and sets carry flag
if A < dati.
Example ; A 1011 1010 = (BAH)
CPI 30H ; This instruction will compare 30H with the contents of
; accumulator (BAH). Here A > data !1.0 n>ro and carry both
; flags will reset after the execution of the instntction.
Rotate
1. RLC This instruction rotates the contents of the accumulator lcfl by one
position. Bit B, is placed in B, as well as in CY.
Example
; A 01010111 (57H) and CY I
RLC ; After execution of the instruction the accumulator c:c.mtent->
; will be (1010 l llO) AEH and carry fla~ will reset.
Copyrighted material
Microprocessors and Interfacing 1. 52 An Ove rview of 8085
4. RAR This instruction rotates the contents of the accumulator right by one
position. Bit B0 is placed in CY and CY is placed in 0,.
Example
RAR ; A 1010 0011 (A3H) and CY 0
; After f_)xCCution of the in.nruction nccumulator contents will
; be (0101 0001) SIH and carry flag will :;et.
2. PUSH PSW This instruction decrements stack pointer by one and copies the
accumulator contents into the memory location pointed by stack
l'')inl\.1'. It tlwn ,k..:n.mlnls th< s tack pointer .tgain by one and
cupil.'S th\. flag n:gisll'f into the memory location poiutl.!d by tht.>
~ta..: k pointer.
Example : SP 2000H, A 20H, Flag n.'gi.ter SOH
This ins truction d ,-cremcnts the stac.k pointer (SP = 20<'CH) by one
{SP .::: IFFFH) .m._ t.:upi~.-~ lht. t.:ontcnts of th..- a ccu mul<~: lor (20H)into
the memory locatiun IFFFH. ll t..twm dl.~temcnts Lht." stack pt>i1\ler
~Copyrighted material
.. l@lf~~ssornf'd y!.rt'j!~9
~ . .,... .'h
1. 53
..
An OvervNw of-8085
".
.I
again by one (SP = 1FFEH) and copies the contents of the flag
t'cgister (SOH) into the memory location lFFEH.
3. POP rp This instruction copies the contents of memory location pointed by
the stack pointer into the lower byte of the specified register pair
and increments the stack pointer by one. It then copies the contents
of memory location pointed by stack pointer into the higher byte of
the specified register pair and increments the stack pointer again by
one. The rp is 16-bit register pair such as BC, DE, HL. Only higher
order register is to be specified within the instruction.
Example SP = 2000H, (2000H) 2 30H, (2001H) E SOH
POP B ; This instruction will copy the contents of memory location
; pointed by stack pointer, 2000H (i.e. data 30H) into the C
; register. It will then increment the stack pointer by one,
; 2001H and wtU copy the contents of memory location
; pointed by s tack pointer, 2001 H (i.e. data SOH) into B
; register, and increment the s tack pointer again by one.
4. POP PSW This instruction copies the contents of memory location pointed by
the stack pointer into the flag regis t~U and increm~ts the stack
pointer by one . It then copies the contents of memory loc-ation
pointed by stack pointer into the accumulator and increments the
stack pointer again by one.
Example : SP 2 2000H, (2000H) = 30H. (2001 H) = SOH
POPPSW ; This instruction will copy the contents of memory location
; pointed by the stack pointer, 2000H (i.e. data 30H ) into th<'
; flag register. It will then increment the stack pointer by one,
; 2001 H and will ropy the contents of memory location
; pointed by s tack pointer into the accumulator and increment
; the stack pointc:rr again by one.
5. SPHL This instruction copies the contents of Hl register pair into the s tilck
pointer. The contents of H register a rc copJed to higher order byte
of stack pointer and contl.!nts of L register are copied to the lower
byte of s tack pointer.
Example HL = 2500H
SPHL ; This instruction will copy 2500H into stack pointer. So after
; execution of instruction stack pointer contents will be 2500H.
Copyrighted material
MicfOP"OCUiors and Interfacing 1 - 54 . Ao:t Overvl~ qfJ!IM
of the next memory location with the content~ of. H ~egistq.'f~
instruction does not modify stack pointer contcnt.c;.
Eumple ; HL = 3040H and SP 2700H, (2700H) = SOH, (2701H) = 60H
XlHL ; This instruction witl exchange the contents of L register
; (40H) with the contents of memory location 2700H (i.e. SOH)
; and the contents of H register (30H) w ith the contents of
; memory location 2701 H (i.e. 60H).
Input/Output
1. IN addr(S-bit) This ins truc-tion copies the data at the port whose address is
specified in the instruction into the accumulator.
Example Port address = SOH, data s tored at port address SOH, (SOH) =10H
IN SOH ; This instruction will copy the data stored at address SOH, i.e.
; data 10H in the accumula tor.
2. OUT addr(8-bit) This instruction sends the contents of accumulator to the output
port whose address is specified within the instruction.
Example A = 40H
OUT SOH ; This instruction wiJJ send the contents of accumulator
; (40H) to the output port w hose address is SOH.
4. ' HLT This instruction h..1.lts the proceSsor. It can be restarted by a valid
interrupt or by applying a RESET signal.
5. SIM This instruction masks the interrupts as desired. It also sends out
serial data through the SOD pin. For this instructic;>n command byte
must be lo.1ded in the accumulator.
Copyrighted material
1. 55 An Overview pf 81!~5
Copyrighted material
'I I ' IM.c ,..,.,_...,... and lnterf8clng
~
1 . 56 An Ovei')'~Cft~ !
' ' I ;-
1.7.2 Ove111ll Interrupt Structure .!
2 _n_
ve edge
RST
7.5
M 7.5
TRAP
RESET tN
Copyrighted material
Mictopfoeeuors and Interfacing 1- 58 An Overv..w of 8085
RSl" 6.5 and RST 5.5 : The RST 6.5 and RST 5.5 both arc level triggered. These
intempn; ciln r c mas ked using SIM ins truction. The RST 6.5 has the third priority whereas
RST 5.5 has the fourth priority. The vector addresse; of RST 6.5 and RST 5.5 are 0034H
and 002CH respectively. After recognition of RST 6.5 or RST 5.5 interrupt, 8085 completes
its curn!'nt instmclion; pu<:~ the ?~ddrcss of next instruction onto the stack and loods PC
with c<.nresponding vector ,,ddress.
INTR : INTR ico a maskable interrupt, but not the vector intetTUpt. lt has the lowest priority.
The following sequcr'lcc of events occur when lNTR signal goes high.
1. The SOSS , hecks the status of INTR s ignal during execution of each instruction.
2. I( ll\'TR signal is high, then 8085 completes its cttJTC.nt instmction and sends an
active low interrupt llcknowledge signal (INTA) if the interrupt is enabled.
3. In response to the INTA signal, external logic places an instruction OPCODE on the
data bus. In the case of multibyte instruction, additjonal interrupt acknowledge
m..c,chinc :::ycles are generated by the 8085 to transfer the additional bytes into the
microprocessor.
4. On receiving the instruction, the 8085 saves tM address of next instruction on stack
and execut~ received instruction.
Note : Theoretically, the external logic can place any instruction code on the data bus
in response to the INTA. However~ only CALL and RST codes save the contents of the PC
on the stack and branch program control to the subroutine address.
Response for RST instruction : lf the external device places an opcodc for any one of
the RST instruction (RST 0 - RST 7), then 8085 pushes the contents of PC onto the stack. It
then brnncht.~ the p~ogmm control to the vector address of the corresponding RST
instruction.
.
Response for CALL instruction : If the external device places an opcode for CALL
instruction then~ generates two additional interrupt acknowledge cycles.
1. It sends an actlve low interrupt acknowJedge signal second time.
2. In response to second lNTA signal, external logic places the lower byte address for
the CALL instruction.
3. After receiving lower byte address, 8085 sends the third interrupt acknowledge
signal.
- .
4. In response to third lNTA s ignal, external logic places the higher byte address for
the CALL instruction.
5. After receiving sixteen bit address for CALL. 8085 pu.'lhes the contents of 1M PC
onto the stack and branches the program control to the b-ubroutine whose address
is received from the extema11ogic.
Copyrighted material
MlcroprocHaors and Interfacing 1. 59
Example : The Fig. !.40 shows the diagram of external Logic <that :gixcs .!he ,;RST 7
instTUction opcode on interrupt acknowledge. .
8085A
Mk::roproeessor
A0o-AD7 8
8
Three - state
mTA buffer
R
sv
INTR 5V
1
a ..... 0
Request from
CI.K ""'Lr 110 device for
an inlerrupt
I
Flip-llop
Fig. 1.40 Extei'TUII logic that gives the RST 7 Instruction opeode
External logic controls a tri-state buffer with the INTA signal i.n order to place an
opcode for RST 7 instruction. The INTA s ignal from the microproc!'S""r is used as an
Output Enable signal for the buffer as well a. reset signal for 0 flip flop. The request from
the 1/0 device is routed through the 0 fli p-flop to the INTR. The 0 flip fl o~sed to
hold the INTR signal high until 8085 gives interrupt acknowledge signal. The INTA signal
that ls generated enables the tri-state buffer whose data inputs are hardwired to the value
equal 1o the opoode fo r RST 7 (FFH) instruction. The 8085 receives this opcodc during
interrup t acknowledge cycle. After receiving the opcode 8085 pushes the contents of
progra m counter onto tt,c stack, thus saving the return address. It then branches the
program control to the address 0038H (Vector add'res5 of RST 7). Table I .7 shows the
summary of hardware interrupts in 8085.
' '
Copyrighted material
f nd<l!'!!!f; cing 1 -60 An Overview of 60"'
I>'I
'' .
. ..
'i~t:;:.;M lvi>e
.
,.,.. i'riggor Priority Masbble Vector address
TAAP Edge ana Level 1 (Highesl) No 0024H
RST 7.5 Edge 2"' Yes OOJCH
RST 6.5 Lev~' 3"' y .. 0034H
---
RST 5.5
~TR
te,-ei
l evel
"
5'11 (L.owHC)
Yes
Yes
002CH
.
~-
Table 1.7
Copyrighted material
Mlcropr~oro .and Interfacing 1 61 An Ovoo:view of 8085
El : Enable Interrupt
The El instruction sets the interrupt enable flip-flop, as shown in Fig. 1..38. Thus RST
7.5, RST 6.5, RST 5.5 and INTR are en.>bl<"<l using El instruction.
It is important to note that when any interrupt is lld<nowlcdgcd, interrupt cn.1b!c flip
flop resets and disables all interrupts. 1 o enable intern1pt in further process it is necessary
to execu t~ EI instruction within interrupt service routine.
01 : Disable Interrupt
The 01 instruction resets the interrupt enable flip nop, r.s s hown in Fig. 1..38. Thus H
disables RST 7.5, RST 6.5, RST 5.5 and INTR interrupts.
SIM : Sot Interrupt Mask
This instruction is used to set interrupt mask and to send serial output. Jt tTansfers the
a mtcnts of accumulator to interrupt control logic and serial 1/ 0 port. Thus it is necessary
to load appropriate contents in the 3\.\:umulator before execution of SlM instruclion.
SIM Instruction Fonnat :
Bits 0 2 will set/ reset tht: mils k bits for RST 5.5, RST 6.5, and RST 7.5 of the interrupt
mask reg-L'itcr.
Bit 3 enables th~ functioning of bits 0 2. It enables or d isables the mas king control.
Bit 4 is us.:.-..d to reset RST 7.5 n:oqucst; regardless of whe-ther or not RST 7,.r:; is masked.
Bit 5 ls don~t care.
Bit 6 enables the seria l output if it is set.
Bit 7 decides the data to be St:nt on the seriaJ output pin of 8085.
Copyrighted material
Mlcroproc:. .aon and Interfacing 1. 62 An Overview-~ eoes
Example 1 : To enable RST 6.5 and mask all other interrupts we m ust ex.ecute following
in.'itructions.
Is: I SDE
0
X
0
I :-51 I ;51 :51 ,5.51
R M: E M M M
DOH
MVI A, ODH ; Load control fonnat in accumulator
SIM ; Set interrupt mask.
Example 2 : The following instruction sequence enables RST 7.5 a nd RST 6.5 and
disables RST 5.5
I s:oI S~E X
0
I :51
R
MSE
1
I :51
M M :51 ,5.51
M
:
Copyrighted material
Mic.oprocessors and lnterfaclnu 1. 63 An Overview of 8085
Pending
I ----
Senal inpul interrupts lntefrupt mask
........__ .
,.._.A--., ~ ...... ..-- ~
Pending In
1. Pending
0 0 0 1 0 0 0 0 = 10H
Example 5 : Write a program to diplay real time dock. Assume that a pt"Tiodic signal is
interrupting RST 7.5 signal after every 0.5 seconds.
Main program
MVI C, OOH ; Initialize counter
LXI H, OOOOH ; Initialize seconds , and minutes
0-IVI 0 , OOH ; Initialize hours
MVI A, OBH ;
.. Copyrighted material
Micr,oproces.sors~nd Interfacing 1-64 An Overview of 8085
Seconds= 0
No
and-
Display HOU'S, t.tins,
Enable anttrrupt
Copyrighted material
lotk:topt~"'ora and Interfacing 1 -85 An OYeNiew of 1085
S!M ;
E! ; Enable RST 7,5 interrupt
HERE : JMP HERE ; Wait for interrupt.
ISR - lm.trupl ..Nice Routine
!NR C ; Increment counter
HOY A, c
CPI , 02H
JNZ LAST ; Check for 1 second
MVI C , OOH ; Reset. counter
MOV A, L ; Get seconds counter
AD! OIH ; Increment seconds counter
DM : Ad just for BCD
MOVL, A ; Save seconds counter
CP!60H ; Check fo r 60 seconds
JNZ LAST ; lf not 60 , goto display
HV! L, OOH : Reset seconds counter
HOV A,H ; Get minutes counte r
AD! OIH : Increment minutes counter
DM : Adjust f or BCD
HOV H,A ; Save minutes counter
CPI 60H Check for 60 ainutea
JNZ LAST ; If not 60, goto display
HVI H, OOH ; Reset m.1.nut.e3 counter
HOV A, D : Get hours counter
ADI OIH ; Increment hours counter
DM ; Adjust for BCD
HOV D, A ; Save hours counte t
CPI 24 H ; Ch~c k !or 24 houro
JNZ LAST ; If not 2 4, goto display
HVI D, OOH : Reset hours counter
LAST CALL DISPLAY : Call display subroutine
EJ ; Enable Interrupt
RET ; Return to main pco9ram
Revl- Questions
I. E.xp/llln thr fr<rtur of 8085.
2. Cittt tht rhri out frtq~ itnd lllllt timt, T, ~ n M>BSA opmtlitrg with Midi llj tltt folloui"g
fr"''"""' Ny$1111 : 6.25 MH;. 6.1 U MH;. 5 MH: oot/ 4 MH:..
J. List !Itt 11....., "''illm I OM, tlodr -rviotbu tmllnt.fllto. o...triW tit< pmwry fomdit>n
"' ..... wtifltr.
.. Cirt '"' ,..._ "'fWg ~ in .!085. EzpUi ..... JLrg.
5. 0... tltt fvNtiotwl - 4iogtnt "'""''""'""- .!085 "" ,.... i britf.
6. Ezplam 4tjfrmtt <OIT<ilipols OS<d loy SOIJS.
7. Why AD,.AD1 /Int:~ n ttwlliplc.nl ?
II. W1o.tt t. /Ito' ""' tl{ A l fislll I
9. Wlbtt h tllt' u~ iJf CLKOUT "'rJ RST OlfT sitmds of ,'11"1:5 prot'l':t'!()f' l
Copynghted materio~l
Microprocessors and Interfacing 1. 66 An Overview of 8085
10. Dt."ScriW Ill~ f unctkmof following pittS irr 8085.
n. READY b. IlL c. 10/M d. HOLD t. RST
11. Erploin the sig7wls used in DMA opm~tio11 in 8085.
JZ. Difitu-
1. lnslrutHon cycle 2. Machint' cycle .3. T stttlt
1.3. What is tluo necessity to haw tu.10 status lines SJ and 50 in 8085 ?
14. Explain wrlou$ nurchint tyc.lts $UJ1POrlt'd by 8085.
15. Draw rmd explain tht mrmory rtad cycle of 8085.
16. Drmu nnd explain IJtf mmuny wrltt' cytlt of 8085.
J 7. Drnw tmd uplain tire 1/0 read cycle of 8085.
JB. Ormo ond explain the 1/0 toritt cydf of 8085.
19. Explain the classijirolioll of tht instruction sd of 8085 micropi'OC't$$Or with suitable nnmplts.
20. With tlrt lrt'lp of ont" tXIItllp/(" in tJtCh ca~ explain ''"' effrct of tl1e following imtrudkms In 8085.
n. UIW addr b. ADD M
c. RST 4 d. XTHL
t . Dill! f CP 2000
g. DAD B II. IN 20H
i. RIM f. SIM
21. Write tle two woys to inWnliu stncJ.: poi11lt'T at FFFFH.
12. Compan tlw following ]'XIirs of instrudions with tltdr opcodes, o~rnlions, inslructiott bytes,
ndd~ing modt'S, ajfocUd flag-s tllld tltf m~uts.
[J[J[J
'
Copyrighted material
2
Architecture of 8086 Microprocessor
In 1978, Intel came out with the 8086 processor. The Intel 8086 is a 16-bit
microprocessor, Implemented in N-channeL depletion load, silicon gate technology
(HMOS), and pnckag<'<l II in a 40 pin dual in line package. In this chapter, we s tudy
features, a rchJ tecturc~ rcgllj;tcr organisation, bus operation and memory segmentation.
Gopynghted ma nrii-
Microprocessors and Interfacing 2-2 Architecture of 8086 Microprocessor
8. The 8086 is possible to perform bit, byte, word and block operations in 8086. It
perfonns the arithm(>tic and logical operations on bit, byte, word and docirnal
numbers including multiply and divide.
9. TI'te Intel 8086 is designed to operate in two mock-'S, J"'l mely the 1ninimum mode
and . t~ maximum mode. When : CJiiY. yne. 80~ a ,u . is to be lL<;t.~ in a
microcomputer system, the 8086 is usC!if if! the ri'lin.imum mode of opcrnt:ion. In
thL 'm'Ode the CP U isues the -control si~a~t'<!qtrired by memory and 110 devices.
In multiprCX"CSSOr (more than one processor in the systc m) systef1?.,.~ Oj."'Cratcs in
maximum mode. ln maximum mode, control signals arc genernted willi the help of
extcmal bus controller (8288).
10. The Intel 8086 supports multiprogramming. In multiprogramming, the code for
two or more processes Lo; in memory at the same time and is ex~uted in a
timemu ltiplc.-x..'<l fashion.
11. An interesting feature of the 8086 is that it fetches upto six instruction bytes
(4 instruction bytes for 8088) from me1nory and queue s tores them in ordl'r to
spcL-d up in~truction execution. Later we will discuss this in detail.
12. The 8086 provides powerful instruction set with the folJowing address ing modes :
Register, immediate, d irect, indirect through an index or base, indirect through the
~ur ll u( a b-ase a nd an i nd~x register, relative and implied.
.
2. h fc lcht.~ in~lru ction fmm memory.
3. Jl n..1ds d,,ta from port/ memory.
4. 1t \\'ri ll~ d.lt,l into port/memory.
5. It ..;.upports in:-truction queuing.
V. It f' tu\'ldo.. the .1Jdn"!"S rchKatiOn facdty.
Copyrighted material
Architecture
~
2 3
'" lt ":':
(1=
)
,..-------- ~--- - -- ------- - ----- --- ------- - --- ---- - -------
BJU
~
.~
/. r .\
.,.. .
Bl>us 1 lnSJrucijon
.,..
s......
""""'
,--------- ---- ---- -- -- ~
'' ''
.............................''
Conoo
'
1-------- Sys.'em
'' EU
''
''
'
: ~
: ax p [
: ex
' OX ~
'--
\.' ......... logic Unll
/
''
'''
'--
''
'''
l I ''
' '
'
~---------------Fig.
-----
2.2--- -------
8086 -----------
Internal - ---- --- - ------'
block diagram
To implemlmt lhese functions the BJU contains lhe instnu:tion queue, segmt~nf regis ters
instruction pointer, address summer and bus control logic.
Instruction Queue
To speed up prob'Tam el(ecution, the BIU fetches six instruction bytes ahead of timt;>
from the memory. These prefetched instruction bytes a re held fo r the execution unit in . -,
group of regis ters caUOO Queue. With the help of queue it is possible to fetch~ next
instruction when current instruction is in execution. For example, current instructipn jn
execution is a multiplication instruction. ln 8086, operands for multip lication ?periltions arc
within registers. Still it requiT(.-"S tOO dock cydes to execute multiply ins truction. Like
multiplication there are number of other ins tructions in 8086 which need quite a large
number of dock cycles for execution. During this execution time the BIU ft:!tchcs the next
instruction or instructions from memory into the instruction queue instead of remaining
idle. The BlU continues this proces.~ as long M the queue is not full Due to this, execution
unit gets the ready instruction in the queue and instrUi tiori fetch time' is eliminlt'tcd. This is
illustrated in Fig. 2.J.
The queue operates on the principle first in first out (FIFO). So that the execution unit
gel~ the instructions for exccutjon in the order they are fetched. In C<l ..'W! of JUMP and
CALL instructions, instruction a lready fetched in queue arc of no usc. Hence, in thl'SC
Copyrighted material
Microprouuors and Interfacing 24
OYerla~ { BIU
phases
EU I o, I E, e, o, j E3 .. .
Copyrighted material
2-5 Architecture of 8086 Mlcrsll];rocsssqr,
SP
15 8 7 0
A.H Al cs BP
BX BH Bl OS Sl
ex CH CL ES 01
OX DH OL $$ 8 IP
Copyrighted material
.
II
' .
b . Microprocessors and Interfacing 2-6 Architec.ture of 8086 Microproces,ort
segments at a time, as shown in the Fig. 2.5. For the selection of the four activi segments
1
the 16-bit segment registers are p rovided by the bus in terface unit (BIU) of the 8086. These
four registers are :
Address
FFFFFH
ElClra segment
OOOOOH
I. The CS register holds the upper 16-bits of the starting address of !he ""S''enl from
which the BfU is currently fetching the instruction code byte.
2. The 55 register is u~ for the upper 16-bits of the starting address for the
program stack (all stack related instru,ctlons will operate on stack).
Copynghted matenal
2-7
IH
3. ES register and OS register are used to hold the upper 16-bits !'f the startirtg
address of the two memory segments which are used for data.
2.3.3 Pointers and Index Registers
All segment registers are t~bit wide. But it is necessary to genera te 2()..bit address
(physical address) on the address bu.<. To get 20-bit physical addn.'ss ore or more pointer
or index registers are associated with each segment register. The pointer registers IP, OP
and SP a re associated with code, data and stack segments, respectively. They hold the
offset within the code, data and stack segments, respectively. 1l1e index registers Dl and Sl
are used as a general purpose registers as wcll as for offset storage in Ctl.SC of indexed,
based indexed and relative based indexed addressing modes. The detail description of
pointers and index regi'\tcr is given in section 2..5.
BIT 15 14 13 12 11 10 9
I I
U Undefined
2. Parity Flog (PF) : II is set to I if result of byte operation or lower byte of the word
operation contain an even number of ones; otherwise it is zero.
3. Autlllary Flag (AF):This nag is set if there is an overflow out of bit 3 i.e., carry from
lower nibble to nigher nibble (03 bit to D, bit). This flag is used for
BCD operations and it is not ovailable for the p rogrammer.
Copyrighted material
2-8 Architecture of 8088 MICrot>fOC!tM!!'
4 . Zero Fl"11 (ZF) : "rhe zero flag sets if the result of operation in ALU i.s zero and
flag resets if the result is nonzero. The zero flag is also set if a
certain register content becomes zero following an increment or
decrement operation of that register.
5. Sign Flog (SF): After the execution of arithmetic or logical operations, if the MSB
of the result is 1, the sign bit i.s set. Sign bill indicates the result is
negative; otherwise it is positive.
6. Ove rflow Flag (OF):This flag is set if result is out of range. For addition this Rag is set
when there is a carry into the MSB and no carry out of the MSB or
vice-versa. For subtraction, it is set when the MSB needs a borrow
and there is no borrow from the MSB, or vice-versa.
,. Example 1 Givt> tlr~ contents of tile flag registtr after txtcution of following addWon.
Copyrighted material
...
2. Inte rrupt Flag (IF) : It is used to allow /prohibit the interruption of a program. If se~ a
certain type of intemapt (a maskable interrupt) can be TE.'COb'11ized
by the 8086; otherwise, these interrupts are ignored.
3. Direction Flag (OF) :It is used with string instructions. If OF = 0, the string is
processed from its beginning with the first element having the
lowest address. Otherwise, the string is processed from the high
address towards the low address.
Copyrighted material
, l\liC:roproce$Sors jltW ll)lrfllclng 2 - 10 Architecture ot 8086 Microprocessor
6-tV.
6 K
64 K
~~ 1 1-----;
~V\,IV\I'n -
---old
!;IV\'""'" ate segment
OOOOOH
Ph\ Sk:al momoty
Fig. 2.7 Memory segmentation
Rules for Memory Segmerotatlon
1. Th~ four segments can overlap (or small programs. ln a minimum system -all our
segments can start at the address OOOOOH.
2. Tit SL>grnent (an ll.>gin/Stort a t any m<!ntory address Whic:h is divisible by 16.
Advantages of Memory Segmentation
1. It allows the memory addressing capacity to be I Mbyte even though the address
associated with individual instruction_is only H)bit.
2. It allows instruction code, data, stack,. and portion of program to be more than
64 KB long by using more than one code, data, s ta<k segment, and extra segm<nL
3. lt fadlitares use of separate memory areas for program1 data and stack.
11. ll permits a p1ogram or its data to be put in different areas of memory, each time
the program is executed i.e. program can be relocated which is very useful in
muJtiprogramming.
MiCiOP<ocessOr.ianillnterfKing 2 11 Architec:tu,.. of 80118' Mlcroj!~-
To access a spt..">Ciftc memory II)C(Itiun , from any segment we RL--ed 2Q..bit physicnl
address. The 8086 generates this address using the contents of segment register and the
offset register associated with il Let us b(.>e how 8086 access code byte within the code
segment
We know that the CS register holds the base addross of the code S<'8Jll"nt. 'llw 8086
provides an instruction poinh.r (IP) which holds the 16-bit addl'\..>ss of the next Ct..-xtc byte
within the code segment. The value contained in the IP is referred to as an offset. Tilis
value must lx> ofls<!t from (added to) the segment b - addr<'SS h CS to produce the
required 20-bit physical address.
The content. of the CS register are multiplied by 16. i.e shifted by 4 pusition to the
left by i.J\SC.'tting 4 uro bits and th~n the offset i.e. the contents of fP register are t:tdd&1 to
the shifted contents of CS to generate physical address. As shown in the Fig . 2.8, the
contents of CS register are 348AH, therefore the shifted con ten~ of CS register are
348AOH. When the BJU odds the ofO..,t of 4214H in the IP to thi starting oddress, we get
38A84H as a 20-bit physical address of memory. TI>is is illustrated in Fig. 2.8 (b).
Prl~l AddrH&M
r======~- Top
t-----1 -
of c::oOe aegment
4<489FH
Cocle.,..-
cs 13
Physieal8dclr\liS I~
e2 I 0
e
" .
A - implied zero
-)
4 zero bits
I
-
IP 4214H
CS 2 $48AH - $&111 of Code segment
(I ) (b)
Fig. 2.8
We have S<.'<.'l\ that how 20-bit physical add"""' is generated within the code segment.
In the similar way the 20-bit physical o'kidn.oss is generab..-'d in the ot.h..-r :;t."gmcnb.
However, it is important to note that each segment rc.:.quires particular St.--gment regi'iter
and ofls<!t r<>gistcr to generate 20-bit physical address.
Pointers and Index ReglstlfS
All ~o:rl\L"'\1 n.-gl:-;tc~ are 16--hit. But it is m-~s..1ry to plif 2()..bit addn.>s~ (phy~kal
addtes.~) on th<.- addn.-ss bus. To gt.'t 20-bit physical addn...~ one mon. n.'glstcr is a,:....~ah..'(l
with C'nch ~-ogmen t r(.'gister the way IP is associated with CS.
ThL'SC ad dition.1l l"l'glSh.rs belong to the poi1ltl't l\l'ld ind<.'x broup. Th-. pointt."r 1.1nd
inde-x group consisl, of ins truction pointer (ll'), s tack pointer (SP), BJ> {base pointer),
~l&r'C\. ind t.X (SI) and dt."":'ttin.ltion index (01) l'l>gi~tl'rs.
Copyrighted material
Microprocessors and Interfacing 2 - 12 Architecture of 8086 Microprocessor
Stock Pointer (SP) : The s tack pointer (SP) register contains the 16-bil offset from the
start of the segment to the top of s tack. For stack operation, physical address is produced
by adding the contents of s tack pointer register to the segment base address in SS. To do
this the contents of the s tack segment register are shifted four bits left and the contents of
SP are added to the shifted result. If the contents of SP arc 9F20H and SS are 4000H then
the physical address is calculated as follows. (Refer Fig. 2.9)
SS =4000H after shifting fou r bits left SS =40000H
Now
ss 40000H
+ SP 9F20H
Physical nddress 49F2QH
.SP =9F20H
SS -= 4000H
1 1 - - - 1 - Topotstadt49F20H
These three 1()-.bit registers c-an be used as general purpose registers. However, their
main use is to hold the 16-bit oft.et of the data word in one of the segments.
Base pointer : We can use the BP tegistcr instead of SP for accessing the stack using
the based addressing mode. In this case, the 20-bit physical stack a<ldress is calculated
from BP and SS. Addressing modes are dio;cussed in later section.
Soutu Index : Source index (51) can be used to hold the ofll!et of a data word in the
data segment. In this .case, the 20.bit physic.'! data address is calculated from 51 and OS.
Destination Index : The ES register points to the extra segment in which data is
s tored. String instnactions always use ES and 01 to determined the 20-bit physical address
for the destination.
Defauh and Alternate R1111iater Assignments
Table 2.1 shows that some memory references and their default and alternate segment
definitions. For example, instruction codes can only be stored in the code segment with IP
used as an oft.et. Similarly, for stack operations only SS and SP or BP registers can be
used to give segment and offset addresses respectively. On the other hand, for accessing
general data, string source, data pointed by BX and BP registers; it is possible to use
alternate segments by using segment override prefix. See examples given after Table 2.1.
Copyrighted material
Mlcroproc:eoaors and lnt.rfacin9 2-13 Archltectu,. of 8086 Mlcroprocnoor
Example 3 :
Copyrighted material
Mlc.....-.sson a nd Interfacing 2-14 Archile.c ture of 8086 Microprocessor
4) MOV CS : [BX], A L
Review Questions
1. U# lit<jnJt11m of 8086 microprtX'r'$$dr.
2. Explai" tllt" ardrit~~tun> of 8086 processor <viti! tilr lw.lp of u(dt block dillgranr.
3. What is 111,~ Jimrticm of bus lnkrfudns 1111il ?
4. What i-s t/11 instruction que.u~ ? x11/ain its ndnwtage.
5. Wllat is pipt'litring ?
6. E.xplai" tl1r l'fS;Strr <H'8f'11i..;;..ttio" of 80$6.
7. Wlwll Art segment rtgisltrs ? Explain tlrt f.mr~ of tlwm.
8. xplai11 tllf p11rpo5C' of polnt,-rs and indl!X rtghtm.
9. WINJt is tilt' Junctiou of flag reyi.!itt!r ?
10. H4l pl1ysiarl nddrt$$ ;s gnrmtt~ in 8086 l
1J. Draw tilt' bit pcttttnr for flng rtgisln- of 8086 and explain tire signiflcanc:t of tach bit.
12. List lilt rum for mmrory segmentation.
J.t Wllot tua~ th( n.1m11111gt'$ of ushr,l( mt'fnory ~mmtation ?
14. Wlral do Y""' m~"'m by imkx n-shifl"rs ?
15. Wlftlt llrt tM fimt1ions of 51 and Dl rt:giSlt'TS ?
ODD
Copyrighted material
3
8086 Instruction Set and
Assembly Language Programming
3.1 Introduction
The 8086 instn1<:tion set includes .._--quivaJents of the 8085 instructions plus many fl('W
ones. Tht:' 1tew in$tructions cont.lin operations such as signed/unsigned multipli01ti0n and
division, bit manipulation instruction"i, string instructions, and interrupt instruction....
11\e 8086 has approximately 117 different instructions with about 300 opct:x:les. The
8086 inst.ruction set oont.1ins no operand, single operand, and two operand in.o::;tructions.
Except for string instructions which involve array operations, the 8086 instructh'ms do not
permit memory to memory operations.
In this chapter we study the addrt>$$ing modes, instruction S(!t of 8086 and assembler
directives.
3.2 Addressing Modes
We have seen how the 8086 fetcht-'S code bytes from memory by generating 2().bit
physical addr~ with thE;> help o f IP ;mel CS. We hiiVe also St'-'11 how the 8086 a<..'\..'{_'8..""-~ lhc
stack u~ing SS and SP. In this St.Ytion we will sec the- di/fet'l-'lll ways that an 8086 can
access the dam. The different ways thnt a processor can access data are reft!m.:.d to as
addressing modes.
The addn."SSing modes o( any processor can be broodly classified as :
Data add.n.ssing modes.
.
Program memory addressing modes.
Stade ~"mory addn...~sing modes.
(3 1)
Copyrighted material
Microprocessors and Interfacing
. " . . '
32 80861nstruction Set and ALP
MOV AL. Bl
ExamPles :
M O V BX, CX ; Copies the 16-bit oontents of CX i nto BX
M OV CL, BL ; CopiL.os a.-bit contents o ( BL into CL.
2.. Immediate Addressing Mode
In an immedial' mode, 8 or 16-bit d ata c.an be s pecified as a J>4.Ut of ins truction.
7 0
~---------20H
j I '
_ . MOV AL. 20 H
15 0
Examples :
MOV BL, 26H ; Copies the 3-bit data 26H into BL
MOV CX. 4567H ; Copk'S the 16-bit data 4561H into ex.
Copyrighted material
Microprocessors and Interfacing 3 -3 8086.1notructlon Set and ALP
AL
[~~~~-----t~~O~H~
13001
MOV AL. (3000HI
SOH L SOH : 13000H J
H
OS [==~~==}!~1
1000 OS ~~~~H~+i3000~~Hr----------__j
(10H)+3000H
x
10 13001H
OS [==~~==}!~1~DOCO~HH~JOOO~~H~
1000
0Sx(10 H)+3000 H
_ __ _ :___j
- : 1.AaoJmoOS= 1000
:. Physical address = OS (10H)+ 3000H
1ooolQJ 3000H = 13000H
2. Atrow indicales direcCion of data flow.
Copyrighted material
Mlcroprouss'?rs and Interfacing 3-4 8086 Instruction Set and ALP
Example :
MOV CL, [9323HI ; This ins truction will copy the C01ltcnts oi the
; memory locatio1\, at a displacement of 9823H from the
; data S<>gment baS<>, into tt.> CL register. Here, 9823H is
; the effective address (EA) which is written
; dire<"tly in the instruction.
Memory
M0V8X. (CX)
- 8X
OS 1000H
2000H
ex 2000H
address
Example:
1. MOV [01], BX ; The imnruction copies the 16-bit contents of BX into a
; memory location offset by t'-' value of EA specified in 01
; from t'-' current contents in OS. Now, if [DSJ e 7205H,
; [DIJ OOOOH, and (BX] 8765H, then afll1r MOV [01), BX.
; content of BX (8765H) is copied to memory locations
; 72080H and 72081 H.
Copyrighted material
Microprocessors ond Interfacing 3-5 8088' instiucllori 'S et and ALP
Memory
MOV CX. (BXOI)
. -- - - - - - - - t-;;
, O;H;-1 12031H
BX I 2000H
2000H
01 I 2000H
Copyrighted material
Mlcroprocuoors and Interfacing . 3-6 8086 Instruction Set and ALP
-
MO\ CX. ~UX C i)
CH
'
I 3001 IOt<
CL
-
40H ARRAY+&
AARAY+5
ARRAY+4
ex ARRAY +01
OS ~:m9nt ba58
- ARRAY
ax ; ARRAYI>ase I I
Fig. 3.1
4. Regis ter Relative Addressing :
Register relative addressing is similar to b.1se--plus-index addressing. Here, the data in
a segment of memo?' are addn..-ssed by adding the displacement to the contents or a b.,se
or on index register {BP, BX, 01 or Sl). Rerru=ber that displa=ent should be added to
the register within the I ]. This is illustrated in the Fig. 3.2. Displacement can be any 8-bit
or 16-bit number.
MOV CX. (BX 0003HI or MOV CX. (BX 31
I-1;.;0;.;H-1 61004H
IOH I 20H 20H 61003H
-
CH CL 6t002H
ex
OS I 6000H
6000imH
DS {IOH)
IOOOH 1003H
ax I
.....
IOOOH +
Olsp&accmont
03H
Fig. 3.2
Copyrighted material
" ..>
Microprocessors and Interfacing 3-7 8086 lo'i'atriictiori Set and ALP
Note :
Example : MOV AL, LAST [SI + 2) ; Thi< mstruction copios the contents of the 20-bil
address computed from the displacement LAST, SI + 2 and OS into AL.
The Fig. 3.3 shows how to address d<tta elemE"Ot within the array with register relative
addressing.
30H A~FtAY+6
ex ARRAY3 01 Index
'--....--"
ARRAY+2 .. 1
OS Segmenl base +
ARRAY
Displacement in the
tegment register
Fig . 3,3
S. B~ Relative Plus Index Addressing :
nw base relative plus index addressing mode is simi1ar to. ,.the ba~e plus index
addressing mode, but it adds a displacement, besides using a base register and an index
register to generate a physical address of the memory. This addressin~ mode is suitable to
address data within the two dimensional array.
Copyrighted material
Microprocessors and Interfacing 3 8 8086 Instruction Set nd ALP
-
ex 0100H 0300H '+\ 03tOH
T
So
: 0200H
I 1
10M
20000H
OS
I 2000M
OS x (11J1)
Fig. 3.4
Addressing Arrays with Base Re lative-Pius~ndex :
As mentioned earlier this addressing mode is useful in addressing two dimensional
array. Two dimensional array usually stores records. For example, student record ~-uch as
its name, roll no etc. Thcndorc, each n>eord _c ontains number of data elements. To access
data element from a particular record we use base regjster to hold the beginning address
of the array of records, index register to point a particular record in the array of records
and displac-ement to point a partictllar element in the record. This is iUustrated in Fig. 3.5.
........,
I
~ ~~
,. .._ ....... !! ___,
; I
........
I
;- , I 51
-
2
1
OS I
I
Fig. 3.5
Copyrighted material
3-9 808e lnatruc:tlon Set nd ALP
StaJ,dard 1/0 devin.'S uses port addressing modt."S. For memory..mapped 1/0, n\emory
addressing mod~ are used. T~re are two types of port addressing modes : dirt"CI ,md
indirect.
In direct port mode, th e port number is an 8-bit immediate ope.rand. This allows fixed
acxess to ports numbered 0 to 255.
Ex.mple :
01.11'05H, AI. ; Sends the contents of AL to 8-bit port 05H.
IN AX, SOH ; Copies 16-bil contents of port SOH
In indirect port mode, the port number is taken (rom OX allowing 64K 8-bit ports or
32K 16-bit po<ts.
ex....ple :
IN AL, OX ; If (OX( = 7890H, then it copies lH>il coolent or port 7890H
1
; into AL.
IN AX, OX ; Copies the 8-bit contents or ports 7890H and 7891 H into AL
; .md AH, r<"$pcorlivcly.
Note : Titc &bit and 16--bit 1/0 trc\nsfers must take place via AL and AX. rest'III..'Ctively.
Copyrighted material
Mictoprocessors and Interfacing 3 -10 80861nstruction Set and ALP
In lhi~ addrcssinh mode addn...s;s whtn to lrnn.'ifer program cuntrc:JI is s pt.--cifiOO within
the instruction alongwith the opcode. The Fig. 3.6 shows the direct intersegment JMP
instruction and the four bytes required to store the address 20Xl0H. This JMP instruction
loads CS with 2<KX>H and ll' with OOOOH to jump to memory location 20000H for the next
instn1ction. An intersegment jump is a jump where destination location is from a different
St.--gment; it can be any memory location within the entire memory locations. Therefore,
intel'S4.-ction jump is also known a.s far jump.
JMP2000H EA 00 00 00 00
Fig. 3.6
Like JMP instruction, CALL ins truction also lk~ direct PI"'h7am addressing with
inte&--gmt-"'1\t or far CALL in.;tnlction. U:maiJy. in both instructions OMP or CALL) th'-'
name of a memory addrt"SS, called a label is spedfiai in the instruction instead of addn_--ss.
In this addressing mOOc, the t'e rm rcl'-'tive is restricted to instruction poinh~.r (IP). For
example, if n JMP instruction skip~ the next 5 bytes of memory, tht- address in relation to
the instructjon pointer is <1 5 that adds to the instnadion pointer. ThLo; generates the
addrcs.<~ of the next progr<-1m in..:;l'ruction. ThLo; is illustrated in Fig. 3.7.
Opoode
20000H
20001H
~JMP(OS)
20002 H
20003 H
-'--Oflset
20004 H
20005 H
20006 H
20007 H
20008 H
Fig. 3.7
It is importilnt to note thc1t in JMP instruction, oprode takes ont> byte and di.splacem(.nt
may take one or h\'l) byt~. Wlwn displacement i~ onl.' byte (8--bit), it is called short jump.
\Vht>n displacement is two byte ( 16--bit), it is called near jump. ln both (short and near)
case::> onJy ronten~ of IP register are modified; contents of CS register are not modified.
Such jumps are called intra.segment jumps ba.."Causc jumps ore within the current code
segmtnt.
Tht. rclativl' JMP and CALL ins tructions can have either an S~bit or a l6bit signed
displacement that allows a forwfltd memory reference or a reverse memory referenC('.
Copyrighted material
MicroproceMors and Interfacing 3 -11 80861nstruction Set and ALP
Thl 80.% nUow:-; :o~oevcrnl (orm..o; ~,( program indin,-'CI mt!mnry addre-.-sing (or the JMP
and CALL ins tructions. ln this addressing mode, it ls possible to use any 16-bit register
(AX, BX, CX, OX, SP, BP, 01 or 51); any relative register ((BP(, (BX], (01(, or (51]); and any
reliltive register with displacement to specify the jtmlp address. This is illustrated in
Table 3.1. /
lnstruetion Operation
JMP ex Jumps 10 tnell'!Of)' lOcation adcttcssed by ex <Mthin current COde
&<>gment.
tP +- ex
JMP NEAR PTR (BX) Jumps to memcwy location addressed by the COntents ot the dat<t
segment memory location addressed by 8X Witfin the CUIT8nl code
segment
tP <- ( (8X + t1 (6Xl)
High byte low bylo
JMP NEAR PTR (0 1 21 J umps to memory location addtessed by the contents 04 the data
segment memory tocation addressed by 0 1 plus 2 within the current
cooe segment.
IP +- ((Dt 3), (Dt 21)
Hlon byte Low byte
JMP ARRAY [BX) Jumps to memory location OO<lfessed by the contents of the data
segment memory location addressed by ARRAY plus ex with the
curTent oodo segment
IP ~ ((ARRAY + ex 1], [ARRAY eXI)
High byte Low byte
Table 3.1
3.2.3 Stack Memory Addressing Modes
The stack is a portion of read/ write mt>mory set asidr by the user fo r t~ purpose of
s toring infonnation temporarily. When the informatic)n is written on the stack. the
Opt."fation is c..lJicd PUSH. When the hl(onnation is read from stack, the operation is called
a POP.
t he :njcro prucl-"S.-<OOT :oton.>S the infonna t10n, mud1 like stackmb p l ate~. Using thi ...
analogy of s tacking: plah.>s . il is (>asy to illu.o;trilte th e stack operation.
Fig. 3.8 shows the stacked plates. Here, we rl'a Hzc
3
that if it is desired to take out the fi rst st.1cked plate we
2 will h ow~ It) rcmove all plate-s a.bovc the firs t plate in the
t reverse order. TI1is me.a ns that to remove first p late we
will have to rem<we the third plate, then the second
Fig. 3.8 Stacked plates plato and finall y lhe first plote. This means tha~ tho first
information pushed o n to the stack is the last
information popped off from the sta.ck. This type o f opcrJtion is known as a first in, last
out (fl LO). This stack is implemented with the help of special me mory pointer register.
Copyrighted material
Microprocessors and Interfacing 3 12 8086 Instruction Set and ALP
The special pointer register is called the stack pointer. During PUSH and POP operation,
stack pointer regil.iter giv~ the address of memory where the information is to be stored
or to be read. The stack pointer's contents arc automatically manipulated to point to stack
top. 1be memory location currently pointed by stack pointer is called top of stack.
SP 9F20H 1
-
SS =4000H - Start of stack segment 40000H
Copyrighted material
Microprocessors and I-cing 3 -13 80861nstructlon Set and ALP
End of slatk ~
- 4FFFFH
4FFFEH
4FFfOH
t FFFCH
<tff'FBH - Topol slack
4FFFAH
ssi401Xlt1 1-
=
S -= - sladl segment
.... . ...
nd ciNe* segmM End of stack segmenl 4Ff"FFH
- 4FFFFH $P )FFFFH)- - Top ol slad;
4 I'f'1'f'H 4 FR'EH
-
FFFOH 56 H - FOH
12H FFFCH 12 H
FFFCH
"'" 4 .......
4fFF8H- Topol sUet 34H
''"'"'"
"""""
""""'"
ss(AOOOH)- """''"
-
-
Sbr'l of---~ SS(-4000H
Fig. 3.11
I-
CALL Operation
The CALL instruction is used to transfer execution to a subprogmm or procedure.
There ..., lwo basic typ<'S of CALL, near and fur. A neor CALL is a call to a procedure
which is in the same code St."gl1'lml as the CALL ino;;ttuction. When the 8086 t.."Xu~ a
Copyrighted material
Microprocessors and Interfaci ng 3-14 8086 Instruction Set and ALP
near CALL in~ITuctin n it d(.ocrement~ the stack pointer by two and copies the offset of the
next ins tructiOil ~lfl~r the CALL 011 the stack. It loads IP with the offset of the first
instruction of tht pn:>~.X'\i urt in ..:,\11\(~ scg1nent
A fa r CALL is <1 call to .1 pnx.-c.~ure which is in a d ifferent segment from that which
contains thl' CALL instructio' When the 8086 executes a far CAll U decrements the stack
pointer by two and copies the contents of the CS register t'O the stack. It then d ecrements
the stack pointer by two again and copies the offset of the instruction afte r the CALL to
the stack. r.1naUy, it loads CS with the segment base of the segment w hich contains the
prQc:\.-'dure and IP with the offset of the fi rst instruction of the procedure in that segment.
RET Operation
The RET instruction wilt retum executi(m from a procedure to the next instruction
after the CALL inl'truction in the calling p rogram. If the pn..lCl.'<.iure is , neilr p rocedure (in
the :;ame code segment as the CALL instruction), then the return will be done by replacing
the instn1ction pointer with a ''"Ord from the top of the ~tack.
I( tht> pn:x.:edtlrC is ,, far pn>et>dure (in a diffen.."Tlt code segment from the CALL
instruction which calls it), then tht..> instrtction pointer will be replac;ed by the word at the
top of the stack. The stack pointer w ill then be incremented by nvo. The code segment
rcooister i.s then replaa.."CC \vith a word from the new top of the stack. After the code
segm~.m t word i!i: poppt.'rl off the s t:tck, tht:' stack pointer is nga in incremented by two.
Thl'S<> words/word art' the offset of th<' next instmction after the CALL. So 8086 wiU fetch
th'- next iru;tn.a<.tiou nflcr th\.' CALL.-
We hl.'lve se-!'n thl PUSH opcmtion. During this operatio n st.., ck pointer i~ dccrementt..~
by two. Wl' know that maximum length of stnck segment is 64K. lf we go on performing
PUSH UJX'fl.llions s ut.'Ce':'Sivcly, 41t ,_me time tht;> contents of SP will be OOOOH. Any further
attempt to PUSH data on the stack will l'\.Sull in stack overflow.
On the other hand, if we go on perfonning POP operation:-; succes...-ivdy. ill 00(' time
the contents ,,f SP will be FFFFH. Any furtbcr a ttempt to POP data from the stack will
result in stack underflow.
Copyrighled malerial
M i~roprocessors and Interfacing 3. 15 8086 lnstructio ~JcSet and ALP
The MOV instruction copies a word or a byt(' of data from some source to a
destitaalion. The destination can be n register or a rnemory location. The.> source can be a
register.. a memory location, or an immediate number. The source and destination in an
instruction can't both be memory locations. The source and destination in a MOV
instna.:tion must be of same type i.e. either both must be byte or word.
MOV instruction does not affect any fla~.
Examples:
MOV BX. 592FH ; l..ood th i mmediate number 592FH in BX
MOV CL. (357AH( ; Copy the conh>nts.. of memory l oca tion~ at a
; displacement of 357AH from data segment base,
; into the CL register.
MOV [734AHI, BX ; Copy the contents of BX register to two memory
; Locations in the data segtru..."nl. Copy the contents
; of BL register to memory location a t a
; displacement of 734AH and BH register
; to memory location at a displacement of
; 734BH.
MOV DS, CX ; Copy word from ex register to data
; segment register.
MOV TOTAL (BPL AX ; Copy AX to two memory locations. AL to
; first location., AH to s.t."CCnd. Efftoctive
; address, EA, is the sum of displacement
Copyrighted material
Microprocessors and Interfacing 3-16 8086 Instruction Set and AU'
PUSH source
The PUSH instntction decrements sto.1ck pointer by two and copies a word from some
source to the location in the stack whe re the stack pointer puints. Here the source must be
a word (16 bit). The source o( the word can be a general purpose register, a segment
register or memory.
It is important to note that wht.>never data is pushed onto the stack, the first (most
s ignificant) data byte moves into the stack segment memory location addres._.;;ed by SP-1.
The second (least s ignificant) data byh. moves into the stack segment memory location
addressed by SP-2.
Examples :
I. PUSH ex ; DecrcmL'fllS SP by 2. copy ex to s tack
The Fig. 3.12 shows the execution o! PUSH CX instruction.
30036H
3003511
ex
CH Cl 30034H
[ 20 (30 30 30033H
l 20 300J2H
30031H
30030H
1 oo34
30000H
30000/"
ss 1 3000
ss )l 10H
Fig. 3.12
Copyrighted material
Microprocessors and lntMfacing 3 11 8086 Instruction Set and ALP
POP destination
11le POP instruction copies a word from the s tack location pointed by the stack pointer
to the destination. The destination can be a general purpose register, a segment rebrister, or
a memory I0<'41t'ion. Afte r the word L<> copied to the s pecified destination.. the s tack pointer
is automatically incrementt.'Cl by 2. Whenever data L-; removed from the stack, the byte
from the stack segment memory location addressed by SP moves into the most significant
byte of the destination register and the byte from the stack segment memory )()('.{ttion
addressed by SP + 1 moves into the least significant byte of the destination register.
Examples :
1. POP CX ; Copy a word from top of stack
; to CX n.nd increment SP by 2.
The Fig. 3.13 shows the execution o POP CX instruction.
30045H
30044H - - - - 1
'
40 30043H '
)40150
''
50 30042H
CH Cl..
3000 1H
ex 30040H
SP 1 0042
~
30000H
30000
ss I 3000
SS a 10H
Fig. 3.13
Copyrighted material
Mlcroproce~ors !'!! Interfacing 3 - 18 8086 lnstTuc11on Sat and ALP
POf'F
Remove:; the \yor<:J. from top of stack to the flag register. Whenever this instnlction is
cxecutt.:>Cl, the byte from the stack ~ent memory location addressed by SP moves into
the most s ignificant byte of the flag n.~ister and the byte from the stack segment memory
location addressed by SP+ 1 moves into the least significant byte of the flag register.
METHOD 1 :
STACK SEGMENT
STACK ENDS
Note : ., (\!latter typed in Bold letters is included to initialize s tack. This program
sequence ....,.,.,.. 100 byt"" fa< the stack operation.
METHOD 2 :
Copyrighted material
Microprocessors and Interfacing 3-19 8086 lhstructlon S.l and ALP
LOS
LES
nus instruction determines the offset of the variable or memory location named as the
source and loads this address in the specified IG-bit "'1,-ister. Flags are not aff<!Ctt.>d by lEA
instruction.
Examples:
LEA ex, TOTAL ; Load ex with offset of TOTAL in OS.
LEA BP, SS: STAeK_TOP ; Load BP w ith offset of STACK_TOP
. in SS.
LEA AX, [BX] [01] ; Load AX with EA = [BX] + [Dl]
LOS Instruction : Load register and OS with words from memory. LOS register,
memory address of first word.
This instruction copies a word from two memory locations into the register specified in
the instTuction. It then copies a word from the next two memory locations into the OS
register.
Examples :
LOS CX, [391AH) ; Copy contents of memory at displacement of
; 391AH and 391BH to CX. Then ropy contents at
; displacement of 391CH and 391 Ofi in OS.
L5 Instruction : Load register and llS w ith words from memory. LES n.'gister, memory
address of first word.
Thi.~ instruction loads new values into the specified register and' intO the ES register
from four successive memory locations. 1lle word fTom the fir5t two memory Jocation is
copk!d into the ~pecilied register and the word (rom the nexl two memory locations is
copied into the llS register. ., .
Example :
LES ex, [3483H] ; Copy contents of memory at displacement of 3483HO
; in OS to eL, oontents of 3484H in OS to CH and
; ropy the rontents of memo<y at displacement of
; 3485H and 3486H in OS to ES register.
These instructions ropy a byte or word from a location in the data segment to a
location in the extra segment. The of&et of the source byle or word in the data segment
must be in the SI register. The offoet of the destination in the exlr;\ segment must be
rontained in the 01 register. For multiple byte or multiple word moves the number of
elemenlll to be moved is put in the ex register so that it can function as a counter. After
the byte or word is moved SI and 01 are automatically adju$led to point to the next source
.
Copyrighted material
Microprocessors and Interfacing 3 - 20 80861notructlon Set and ALP
and the next destination. If the direction flag is 0, then SI and 0 1 wi_ll be incremented by 1
after a byte move a1ld they wi11 i.ncreme.r1ted by 2 after a word move. 1( the OF is a 1, then
Sl .md Dl will be dt>Cremcntcd by 1 after a byte move al\f.i they will be dercremented by 2
after a word move. MOVS aff<.-'CIS no flags.
The way to tell the assembler whether to code the instmction for a byte or word move
is to ndd a "'8 " or a "W" to the MOVS mnemonic. MOVSB, for example, says move a
string as bytes. MOVSW says move a s tring as words.
Examples :
eLO ; Clear Direction Flag to autoincrement SJ and 0 1
MOV AX, OOJOH
MOV DS, AX ; Initialize dnta segment register to 0
MOVES, AX ; lnitiali:te extra segment register to 0
MOV 51, ZOOOH ; l..ood offset of start of source string into 51
MOV 01, 2400H ; load offset of start of destination into Dl
MOV ex, 04H ; l..ood length of string in ex as counter
REP MOVSB ; Decn>ment ex and MOVSB until ex will be 0.
After move SJ will be one greater than offset of last byte in sourct:! s tring. OJ will be
one greater than offset of last byte of destination string. ex will be 0.
REP is a prefix which is written before MOVSB to repeat execution of It until ex 0.
REPIREPEIREP2/REPNE/REPNZ Prefix
REP is a prefix whlch i.~ writte1\ before one of the s tring instructions. These
instructions repeat until specified condition exists.
Examples :
REPZCMP 58 ; Compare string bytes until CX 0
; or until string bytes not equal.
LODS/LODSB/LODSW
This instnoction copies a byte from a string location pointed to by 51 to AI.,, or a word
from a string location pointed to by 51 to AX. LODS does not affect any fL1gs. LODSB
copies byte and lODSW copies a word.
Copyrighted material
3-21 8086 IMtruc:tion Set and ALP
Examples :
CLD ; Clear di.rcction flag so SI isautoincremented
MOV 51, OFFSET S_SI'R!NG ; Point Sl at s tring
LODS S_STRING.
STOSISTOSBISTOSW
The STOS instruction copies a byte from AL or a word from AX to a memory l(.)oCation
in the extra segment. 01 is US4.."CC to hold the offset of the memory location in the extra
segment. After the copy, 01 is automa tically incremented or decremented to point to the
I'K'xt string clement in memory. If the direction flag. OF. is cleared, then 01 will
automatically be incremented by on<.' fo r a byte string or incremented by two for a word
string. lf the direction Aag is set, 01 will be automatically dt.>Cremented by one for a byte
string or decremented by two for a word string. STOS does not affect any flags. STOSB
copies byte and srosw oopies a word.
Examples:
MOV Dl, OFFSET D_STR!NG ; Point 0 1 at destination string
STOS D_STRING ; Asscmbk.~ uses string name to deterntine
; whether string is of type byte or' type word.
; l( byte string, tht."'f'' string byte replaced
; w ith contents of Al... lf word string, then
; string word replact.'<i with contents of AX.
MOV Dl, OFFSET D_STRING ; Point Dl a t destination string
STOSB ; s added to STOS mnemonic directly
; tells assembler to replace byte in string with byte from
; AL. STOSW would tell assembler directly to repla<e a
; word in the string with a word from AX.
Copyrighted material
Microprocessors and Interfacing 3-22 8086 Instruction Set and ALP
Copyrighted material
Microprocessors and Interfacing 3 -23 80861ns'ittctlon:S~and ALP
Examples :
MOV OX. 30F8H ; Load 16-bit address of the port inf>X.
IN AL, OX ; Copy a byte from 8-bit port 30F8H to AL.
IN AX, OX ; Copy a word from 16-bit port 30P8H to AX.
OUT Instruction : Send a byte or word to a port.
The OUT instruction copies a byte from AL or a word from AX to the specified port.
1he OUT instruction can be executed in two different addressing modes.
I. DirL~ : In direct addressing mode 8-bit address of the port is a part of the
in.~truction.
Examples :
OUT OFSH, Al ; Copy cont""ts of AL to 8 bit port OF8H.
OUTOFBH, AX ; Copy contents of AX to 16-bit port OFBH.
.
2. lnditect : In indirect addressing. the address of the port ~ ref~~ from OX
rf:b"ister. It has advantage of accessing 216 i.e. 65536 ports as mentioned earJier.
Examples :
MOV OX. 30P8H ; Load H)-bit address of the port in OX.
OUT OX. AL ; Copy the contents of AL to port 30P8H.
OUT OX, AX ; Copy the contents of AX to port 30F8H.
3.5.1 Addition
This group of instructions consist of following instroctions
ADD : Addition
ADC : Addition with carry
INC : Increment (Add l)
Copyrighted material
Microprocessors and Interfacing 3. 24 8086 Instruction Set and ALP
These instruction~ add a number from source to a number from destination and put
the result in the destination. The ADC, instruction also adds the status of carry flag into
the result. The source may be an im.mt.dhHe number, a register, or a memory location. The
~urce and the destination in an instruction cannot both be memory locations. 1he source
and destinltion both must be a word or byte. [{ you want to add a byte to a word, you
must copy the byte to a word location and fill the upper byte of the word with zeroes
before adding.
Flags affected : Af, CF, OF, PF, SF, ZF.
Examples :
ADD AL, OFOH ; Add immedi<lle number OFOH to contents of AL.
ADC DL, CL ; Add contents o( CL to contents of DL w ith carry
; and s tore result in DL i.e. DL ~ DL + CL + CY
ADC DX. BX ; Add contents of BX to contents of OX with carry
; and s tore resuh in OX i.e. OX ~ OX + BX + CY
ADD CL, TOTAL (BX) ; Add byte from effective oddrcss
; TOTAL [BX] to contents of CL
ADD CX. TOTAL [BX] ; Add word from effective address
; TOTAL [BX] to contents of CX.
INC Instruction : Increment destination.
The INC instruction add 1 to the speciAed destination. The destina tion may be a
register or memory location. The Af, OF, Pf, SF and ZF flags ore affected.
Examples :
lNC AL ; Add I to contents of AL.
lNC BX ; Add I to contents of BX.
NOTE : The carry flag CF is not affected.
If contents of 8-bit register are FFH and !~it register are FFFFH, after INC instruction
contents of registers will be z.ero without affecting carry flag.
INC BYTE PTR [BXI ; Increment byte at offset of BX in DS.
; BYTE PTR directive indicates to the assembler
; that the byte from memory is to be Incremented.
INC WORD PTR [BX) ; Increment word a t offfiet of BX in DS.
; WORD PTR directive indicates to the assembler
; that the word from memory is to be incremented.
Copyrighted material
3-25 8086 Instruction Set and ALP
3.5.2 Subtraction
This group of instructions consist of following group of instructions.
SUB : Subtraction
SBB :Subtraction with borrow
DEC : o.crem..>nt (subtract I)
NEG : 2's complement of a number
SUBISBB Instruction : SUB destination, Source.
The DEC instruction subtract I from the specified destination. The destination may be
a register or a memory location. The AF, OF, PP, SF and ZF flags are affectt-d.
Copyrighted material
M~on and lnteffacing 3 26 8088 Instruction Set and ALP
ElUimples:
DECAL ; Subtracts I from the contents of AL.
DEC BX ; Subtracts I from the contents of BX.
Note : The carry flag CF is not affected.
If the contents of 8-bit register are OOH and 16-bit register are OOOOH, after DEC
instruction contents of registers will be FFH and FFFFH respectively without affecting
carry flag.
DEC BYTE PTR (BX( ; Decrement byte at offset of BX in DS.
; BYTE PTR directive indicates to the assembler
; that the byte from memory is to be decremented.
DEC WORD PTR (BX) ; Decrement word at offset of BX in DS.
; WORD PTR directive indicates to the ns."K"mbler
; that the wOfd from memory is to be decremented.
NEG Instruction : Form 2's complement.
This instntction repi<K:eS the number in a destination with the 2's complement of that
number. Tile dcstin.'\tion can be a register or a memory location. This instruction can ~
implemented by inverting each bit and adding 1 to it.
The OL>gate instruction updates the AF, CF, SF, PF, ZF and OF flags.
Examples:
; AL 0011 0101 35H
NECAL ; RepL'Ice number in AL with its 2's complement
; AL = 1100 1011 = CBH
3.5.3 Comparison
The comparison Instruction (CMP) compares a byte/word from the specified source
with a byte/word from the specified destination. The source and destination both must be
byte or word. ihe source may be an immediate number, a register, or a memory location..
The destination may be a register or a memory location. However the source and
destination both can't be memory locations. The comparison is done by subtracting the
source byte or word from the destination byte or word. But the result is not stored in the
destination. Soun:e and destination remain unchanged, only flags are updated.
Flags : The AF, OF, SF, ZF, PF and CF are updated by the CMP instruction.
ExompiH:
CMP BL, OJH ; Compare immediate number OIH with byte in BL.
CMPCX, BX ; Compare word In BX with word in ex.
CMP CX, TOTAL ; Compare wot<l at displacement
; TOTAL in DS with word in CX.
Note : It is not possible to compare segment registers.
Copyrighled malerial
I
3. 27 aoa& lrmructlon s.t nd ALP
3.5.4 Multiplication
This group of instructions consist of following group of instructions.
MUL : Unsigned multiplication
IMUL : Signed multiplication
MUL Instruction : MUL source.
This in..-;truction multiplies an unsigned byte from source and unsigned byte in AL
register or unsigned word from source and un..;;.igned word in AX regi.stM. 'The source can
be a register or a memory location. When the byte is multiplied by tile contents o AL, the
result is stored in AX. 1he mos.t significant byte is s torOO in AH and least significant byte
is stored in At.. When a word is multiplied by the contents of AX~ the most significant
word of result is s tored in OX and least significant word of result is stored in AX.
Flags : MUL inslruction affect AF, PP, SF, and ZP Oags.
Examples :
MULBL ; AL x BL, result in AX.
MUL BX ; AX x BX, result high word in OX low word in AX.
MUL WORD PTR IBX] ; AX tiOK'S word in OS pointed by IBX]
; result high word in OX low word in AX.
IMUL IMtruction :
This instruction multiplies a signed byte from some source and a sigru.>d byte in AL. or
a signed word from so~ soum! and a s igned word in AX. 1'he source can be register or
memory location. Wilen a signed byte is multiplied by AL a signed result will be put in
AX. Wilen a sigN!<! word is m ultiplied by AX. the high-order word o the signed result is
put in OX and the low-<>rder word of the signed result is put in AX.
If the upper byte of a Hi-bit result or the upper word of 32-bit result contains only
copies o the sign bit (aU O's or all J's), then tile CF and the OF Hags will both be O's. The
AF, PF, SF, and ZP lags are undefined after IMUL
To multiply a signed byte by a signed word it L< """""sary to move the byte into a
word location and fill the upper byte of the word with copies of the sign bit. This can be
done using CBW instruction.
Exampleo:
IMUL BL ; AL < BL, result in AX
IMULCX ; AX X ex, high-order word of result in, ox and
; low-order word of result in AX.
Copyrighted material
Mleroproc:esiiOf'S and Interfacing 3-28 8086 Instruction Set- ALP
3.5.5 Division
This group of instructions consists of following group of instructions
orv
IDIV
Copyrighted material
Mlcropn>cessors and Interfacing 3 - 29 8086 Instruction Set and ALP
1. If the value of the low-order four bits (03-Do) in the Al is greater than 9 or if AF
is set, the instruction adds 6 (06) to the low-order four bits.
2. U the value of the high-order four bits (O,.D,) in tl>e Al is greater than 9 or if
carry flag is set, the instruction adds 6 (60) to the high-order four bits.
Examples :
I. ; AL = 0011 1001 = 39 BCD
; Cl = 0001 0010 = 12 BCD
Add AL, CL ; AL = 0100 1011 = 4BH
DAA ; Add 0110 Because 1011 > 9
; Al = 0101 0001 = 51 BCD
2. = =
; Al 1001 0 110 96 BCD
; BL = 0000 Olll = 07 BCD
ADD Al, BL ; Al = 1001 1101 9DH
DAA ; Add 0110 Because 1101 > 9
; AL 1010 0011 A3H
; 1010 > 9 so add 0110 0000
; AL 0000 0011 = 03 BCD, CF = I. The result is 103.
The instruction updoHes the AF, CF. PF1 and ZF. The OF is undefined after DAA
instruction.
No le : only work... for AL.
I. If the value of the low-order four bits (03-Do) in the AL is greater than 9 or if AF
is set; the instruction subtracts 6 (06) from the low-order four bits.
2. If the value of the high-order four bits (O,.D,) in the Al is greater than 9 or if
carry flag is set, the instruction subtracts 6 (60) from the high-order four bits.
Copyrighted material
Microprocessors and Interfacing 3-30 8086 Instruction Set and ALP
Examples:
I. ; AL 0011 0010 a 32 BCD
; CL = 0001 0111 = 17 BCD
SUB AL, cL ; AL = 00011011 = 1BH
; Subtract 0110 Because 1011 > 9
; AL = 0001 0101 = 15 BCD
2. ; AL 0010 0011 23 BCD
CL = 0101 1000 = 58 BCD
SUB AL, CL ; AL = 1100 1011 = CBH CF = I
; Subtract 0110 (6) Because 1011 > 9
; AL 1100 0101 = CSH
; Subtract 0110 0000 Beca""" I 100 > 9
; AL = 0110 0101 = 65 BCD CF = I,
; CF 1 means borrow
; is Meded means numb<!r is ru>gative (- 65).
The OAS instruction updates the AF, CF, PF, and ZF. The OF flag is undefined a.fter
DAS instruction.
Note : DAS only works for AL
1be number,; from 0-9 are rep"'"""ted "" 30H-39H in ASCD oode. When you want to
add two dimal digilll whidt are represerued in ASCD oode, it is necessary to mas1c upper
nibble (3) from the <Ode before addition. 1be 8086 allows you to add the ASCD oodes for
two decimal digits without ma.'lking off the :r in the upper nibble of each digiL 1be AAA
instruction can b<! used afte< addition to get the current result in unpacked BCD form.
~ =
; AL = 0011 0100 ASCII 4
; CL = 0011 1000 ASCII 8
ADO AL,CL ; AL = 0110 1100
; 6CH a lncom!ct temporary result
; AL = 0000 0010 Unpacked BCD for 2.
Copyrighted material
Microprocessors and Interfacing 3. 31 8086 l(latruction Set and ALP
Copyrighted material
Microprocessors and:fntiOI'facing 3 -32 8086 Instruction Set and ALP
Eumples :
; AX = 0400 unpacked BCD for 43 decimaL CL = 07H
AAD ; Adjust to biruuy before divi;on,
; AX 002BH a 2BH c 43 decimal.
DIV Cl ; Divide AX by unpacked BCD in CL.
; AL = quotient = 06 unpacked BCD
; = =
AH remainder 01 unpacked BCD
Now by adding 3030H in AX register we get the quotient and remainder in ASCfl
form.
We know th.'\t, AND operntion with two inputs produCt..)$ res ult logic 1 only when both
the inputs are logic 1. i.e. Y = A B.
A 8 y
0 0 0
0 1 0
1 0 0
1 1 ,
Table 3.2 : Truth table for AND gate
This instruction logically ANDs each bit of the source byte or word with the
corTcsponding bit ln the destin.,tion and stores result in the destination. 'The source may be
an immediate number, a register or a memory location. The destination may be a register
Copyrighted material
Microproe<~saora and ll!lerfacing 3 - 33 8086 Instruction S.t and ALP
or a memory location. ~ source and destination both cannot be memory locations in the
same instruction. The CF and OF are both 0 <liter AND. The PF, SF and ZF are affected.
Af is undefined.
Eumpleo :
I. ; AL = 1001 0011 = 93H
; BL = 011 1 0101 = 75H
AND BL, AL ; AND byte in AL with byte in BL
; BL 000 1 0001 = llH
2. ; ex = OliO lOll 1001 lllO
AND CX, OOFOH ; ex oooo oooo
= 1001 oooo
11\e AND operation dears bits of a binary number. The task of dearing a bit in il
binary number is rolled masking. The Fis. 3.14 s hows the prore;s of mnsking.
X X X X
A 8 y
0 0 0
0 1 1
1 0 1
1 1 1
Copyrighted material
Microprocessors and Interfacing 3'- 34 8088 Instruction Set and ALP
or a memory location. The source and destination both can not be memory locations in the
some instruction. The CF and OF are both 0 after OR. The PF, SF and ZF are affected. AF
is Ul'ldefin('<f.
Examples :
I. ;
AL = 1001 0011 = 93H
Bl 0111 0101 75H
;
OR BL, AL ;
OR byte in AL with byte in BL.
;
BL = 1111 0111 = F7H
2. :ex = 0110 1011 10011110
OR CX. OOf()H :ex= 0110 1011 nn 1110
The OR instruction is used to ..,t (make one) any bit in the binary number. This is
illustrated in Fig. 3.15.
c:= ,, ,,
1 1 1 1
0000
xxxx
S8111ng pattem
Result
0 0 0
0 , 1
1 0 ,
, , 0
Copyrighted material
Microprocessors and Interfacing 3 - 35 8086 ins~ucuOn Set and ALP
~n~ry number
c=c0 xxxx
0 0 0 0
xxxx
xxxx
1 1 1 1
x x xxl
Unknown e.-bi1
Resutl
Eumpleo :
; AL e 0110 liOO
NOTAL ; AL = 1001 0011
; ex 1010 11 11 0010 OliO
NOT ex ; ex= 0101 oooo 1101 1001
Test and bit test instructions :
The TEST in.o;truction performs the AND oper.ltion. The difference is that the AND
ll\.o;truction changes the destination operand, while the TEST instruction does not. A TEST
only affects the condition of the flag register, which indkates the result of the test.
PF, SF and ZF will be updated to s how the rt>Sults of the ANDing. PF has meaning
only fo r the lower 8 bits of the destination. AF wi.U be undefined.
Copyrighted material
Microprocessors and Interfacing 3 . 36 80861nstruction Set and ALP
Examples :
TEST AL, Cl ; AND eL with Al.
; Update flogs, resttlt is not stored.
TEST BX, ex ; AND ex with BX.
; Update flags, result is not ston.od.
Th.: TEST instruction functions in the similar manner as a CMP instruction. The
di((crcnre is that the TEST instruction normally tt.-sts a s ingle bit (or occasionally multiple
bits), while the CMP instruction tests the (.'1\tirc byte or word. The Fig. 3.17 shows the bit
pattern and h.>St operation fo r t~ting of bit 0. lf zero nag is set (Z = 1) after this operation,
the bit under test bit..O is zero ; oth~rwise bit 0 is 1.
4
The cro flag is usually tc'Sted by JZ or JNZ instmctions. Therefore, the TEST
instruction is usually followed by either the JZ or JNZ instruction.
0 0 0 0 0 0
3.5.8.1 Shlft
Shift instructions positjon or move binary data to the left or right by shifting them
within the register or memory location. They also pe:rfonn multiplication by powers of 2"
Oeft shift) and division by powers of 2 (right shift). The shift operations can be classified
as logical shifts and arithmetic shifts. The logical shifts move a 0 into the rightmost bit
pooition lor a logical left shift (SHL) and a 0 into the leftmost bit pooition lor a logical
right shift (SHR). The arithmetic left shift (SAL) and logical left shift operations are
identical. However, arithmetic and logical right shifts arc different because the arithmetic
right shift (SAR) copies the sign bit through the number, while the logical right shift
copi<!s a 0 through the number. This is illus!Tated in Fig. 3.18. logical shift operations are
used with unsigned numbers; they perform multiplication or division of unsigned
numbers. On the otherhand, arithmetic shift operations are used with signed numbers;
they perform multiplications or division of signed numbers.
Copyrighted material
Mlcroproceuora and lmerfac:lng 3 - 37 8086111Siruc1ion.Set and ALP
SHL Of--(==~==~~- 0
CY
SAL D-
-{1== ==:=JI- 0
CY
SHR
o -IC:::=:::=::=J---0
Ltt,I :::=:::=::=J--- 0
Sign blt(MSB)
After Execution [J
Flags : All flags are affected.
Copyrighted material
Mlcroproeest,Gtf.andlnterfaclng 6086 Instruction Sot end ALP
Examples :
SAl. CX. I ; S hift Wt)rd in ex 1 bit pt_')!tition Jdt. 0 in LC)B
M OV CL, OSH ; Lvad desired number of shifts in CL
SAL AX, CL ; Shift word in AX left 5 times
; Os in 5 least-significant bits.
SHR Instruction : SHR destiniltion. count
This instnaction shift~ each bit in the specified destination to the right and 0 is s tored
a t MSB position. The LSB is shifted into the carry flag. The destination can be a byte or a
word. U can be in a register or in i-'1 memory location. The number of shifts a re indicated
by count. If number of shifts required is one, you can place 1 in the count position. But if
the number of :ohifts are bl'ft'aler than l then shift count must be loaded in Cl regis ter and
CL must tx p la cl'<'l in the count p<'~ition of the instm ction.
Di.t))r;:un 1-ohows SH R instru ction fo r byte uperatlon.
After Execution
.
Flags : AU flags an.o affected .
Examples :
SHR CX, 1 ; Shift word in CX 1 bit position right, 0 in MSB.
MOV CL, OSH ; load desired number of shifts in CL
SHR AX, CL ; Shift word in AX right 5 limes
; O's in 5 most significant bits.
SAR Instruction : SAR dt.~ti na tion~ count.
This instruction ~hifts t>ach bit in the spedfied destination somt~ number of bit
po:-iti~~n~ to lh l: ri):.ht. r\ :- a hit i!'l- ~hiflt.-d o ut l'lf the ~lSI~ po~ilic)rt, a t:t'PY of the old MS B is
put in tiw ~tSB positil)J\. The LSO \\'ill l.x ~hift..:d into CF. In th~ case or mu1tipl" shifts, CF
will ctmt41in the bit most n."Ccntly ~hift(.od in from the LSB. Bits shifted into CF previously
w ill be lost.
Tht' ~..-t estiau1 tion (an t;>e a byte or a word. It can bot in a register or in a memory
h.K.ltion. The number of shi fts are indicated by count. If number of shifts required is one,
you can place 1 in the count position. J( numb<-r of shifts are greater than 1 then shift
count must be loaded in CL rt.~iS IN and Cl must be pla'd in the count position of the
instruction.
Copyrighted material
Mlc:tJ>prOCHSors end lnterfeclng 3. 39 8088 lnllnic:tion set and ALP
~CY
~ 1-G
Examples:
SAR BL, I ; Shift byte in BL one bil position right.
MOV CL, ()IH ; Load dl>sired number of shifts in Ct.
SAR DX, CL ; Shift word ston..'Cl in OX 4 bit posilions right.
3.5.8.2 Rotate
Rotate instruction." position or move binary data by rotating the infonnation in a
register or memory lorntion,. either from one end to another or through the carry flag. This
is illustrated in Fig. 3.19.
CY
h
RCR
( Rotate right through carry )
I D-J
ROR
( Rotate right )
Copyrighted material
Micn>processors and Interfacing 3-40 8088 Instruction Set and ALP
Examples :
ROL ex, I ; Word in ex one bit position left, MSB to LSB and eF
MOV eL. 03H ; Load desired number of bits to rotate in eL.
ROL BL, CL i Rotate BL thrt.--e positions.
ROR Instruction : ROR destination, count.
This instruction rotates all bits in a specified byte or word to the right some number of
bit positions. LSB is placed as a new MSB and a new eF.
The destination can be a byte or a word. It can be in a register or in a memory
location. The number of shifts arc indicated by count. if number of shifts required is one,
you can place 1 in the count position. JJ number of shifts are greater than 1 then shift
count must be loaded in eL register and eL must be placed in the count position of the
instruction.
Diagram shows ROR instruction for byte rotation.
Copyrighted material
Mlcropn>ceQO,. and Interfacing 3-41 8086 lna1ructlon Set and ALP
Examples :
RORex, I ; Rotated word in CX one bit position right.
; lSB to MSB and CF.
MOV CL, OOH ; Load number of bits to rotate in CL.
ROR BL, CL ; Rotate BL three positions.
RCL Instruction : RCL destination, count.
11\is instruction rotates a ll of the bits in a specified word or byte some number of bit
positions to the left along with the carry flag. MSB is placed as a new carry and previous
carry is p laced as a new LSB.
The destination can be a byte or a word. It can be in a regL~ter o.r in a memory
location. The number of shifts are indicated by count. lf number of shifts required is one,
you can place 1 in the count position. If number of s hifts are greater than 1 then shift
count must be loaded in CL reglstcr and CL must be placed in the count position of the
instruction.
Diagram shows RCL instruction for byte rotation.
Examples :
RCL ex, I ; Rotated word in CX I bit left, MSB to CF, CF to lSB.
MOV CL, 04H ; Load number of bit pooiHons to rotate in CL.
RCL AL, CL ; Rotate A L 4 bits loft.
RCR Instruction : RCR destinatiot,, count.
This instruction rotates all of the bits in a spt>cified word or byte some number of bit
positions to the right along with the carry flag. lSB is placed as a new carry and previous
carry is placed as a new MSB.
The destination can be a byte or a word. It can be in a register or in a memory
location. The number of shifts a re indicated by count. If number of shifts ri.>quired is oale
you can p lace I in the count position. If number of shlfts are greater than I then shift
count must be loaded in CL register and CL must be placed in the count position in the
instruction.
Copyrighted material
110M 1nstruc:t1on Set and ALP
8~
r ~KJJ
CY
Eumples :
RCR ex, I ; Word in ex I bit righ~ LS8 to CF, CF to MSB.
MOV CL, 04H ; Load number of bit positions to rotate in CL.
RCR AL, CL ; Rotate AL 4 bits right.
A string is a series of the same type of data items in sequential memory locations. The
CMPS instruction can be used to compare a byte in one string with a byte in another
string or to compare a word in one string with a word in another string. SI is used to hold
the offset of a byte or word in the source string and Dl is used to hold the offset of a byte
or a \\'Ord in the other string. The comparison is done by subtracting the byte or word
pointed to by Dl from the byte or word pointed to by 51. The AF, CF, OF, PF, SF, and ZF
nags are affected by the comparison., but neither operand is aifected.
Copyrighted material
Microprocessors and lntlffaclng 3 43 8086 Instruction Set and ALP
Examples :
; Point St at source string. Point Dl at
; destination string
MOV 51, OFFSET F_STRING
MOV Dl, OFFSET S_STRING
CLD ; OF dcart.'<l so 51 and Dl will
; autoincrement after compare
eMPS F_STRING, S_STRING ; The assembler uses names to determine whether
; strings were declared as type byte or us type
; word.
MOV e x, 100 ; Put number of string elements in CX, Point 51 at
; source of string and 0 1 at destination of string
MOV 51, OFFSET F_STRING
MOV DL OFFSET S_STRING
STD ; OF set so SJ and 01 will autodecremcnt after
;compare
REPE CMPSB ; Repeat the comparison of string bytes until end
; of string or until comparro bytes are not equal.
After the comparison 51 and Dl wilJ be a utomatically incrc:mcnted or decremented
according to direction flag to point to the next element in the two strings (if OF = 0, 51
and OJ t otherwise l ) CX functions as a counter which is decre.ll'llented after each
comparison. This will go on until ex = 0.
SCAS/SCASBISCASW Instruction :
SCAS compares a string byte with a byte in AL or a s tring word with word in AX.
The instruction affects the flags, but it doc'S not change either the operand in AL (AX) or
the operand in the string. The string to be scanned must be in the extra ~~lent and 01
must contain the offset of the byte or the word to be compared.
After the comparison OJ will be automaticaUy incremented or decremented according
to direction flag to point to the next clement in the two s trings (if OF = 0, 51 and 01 t
otherwise J. ) CX functions as a counter w hich is dC'Crcmentcd after each comparison. This
will go on until ex = 0. SCAS affects the AF, eF, OF, PF, SF and ZF flags.
Examples :
; Scan a text string of 80 charnciC'r.:l
; for a carriage return
MOV AL, OOH ; Byte to be scanned for into AL
MOV 01, OFFSET TEXT_STRING ; Offset of string to 01
MOV ex, 80 ; ex used as element c<mnter
CLD ; Clear OF; so 01 autoincremcnts
Copyrighted material
Microprocessors and Interfacing 3--44 8086 Instruction Set and ALP
Copyrighled malerial
MICfoprocesson and Interfacing 80861nstruction Set and ALP
CALL Instruction :
The CALL instmction is used to transfer execution to a subprogram or p rocedure.
11tere are two basic types of CALLs, near and far. A near CALL is a call to a proc:edure
which is in the same code segment as the CALL instruction. When the 8086 executes a
near CALL instruction it decrements the stack pointer b)' two and copies the offset of the
next instmct:ion after the CALL on the stack. It lo<lds IP with the offset of the first
instruction of the procedure in same segment
A far CALL is a call to a procedure which is in a different segment from that which
contains the CALL instruction. When the 8086 executes a far CALL it decrements Ule stack
pointer by two and copies the oontenlo:; of the CS n..~ister to the stack. It then dccrcmetlts
the stack pointer by two again and copies the offset of the instruction alter the CALL to
the stack. Finally, it loads CS with the segment base of the segment which contains the
procedure and JP with the offset of the first instmction of the proct->dure in that segment.
Examples :
Direct within segment (near)
CALL PRO ; PRO is the name of the proo.>dure.
; The assembler determines displacement of pro
; from the ins truc:tion after the CALL and codes
; this displacement in as part of the instruction.
Indirect within.-$egment (neu)
CALL CX ; CX contain., the offset of the ftrst instruction
; of the procedure. RepiMes contents of IP with
; contents of register ex.
Indirect to another segment (fad
CALL DWORD PTR (BXJ ; New values for CS and IP are fetched from four
; memory locations in OS. n.e new value for CS
; is fetched from (BXJ and (BX + I], the new IP
; is fetched from (BX + 2] and [BX + 3).
RET Instruction :
The RET instruction will return execution from a procedure to the next instruction
after the CALL instruction in the calling program. 1f the procedure is a near procedure ( in
the same code segment as the CALL instruction), then the return will be done by reptoclng
the instruction pointer with a word from the top of the stack.
If the procedure is a far procedure (in a different code segment from the CALL
instruction which calls it), then the instruction pointer will be replaced by the word at the
top of the stack. The stack pointer will then be incremented by two. The code segment
n>gister is then replaced with a word from the new top of the stack. After the code
segment word is popped off the stack, the s tack pointer is again incremented by two.
These words/ word are the offset of the next instruction after the CALL. So 8086 will fetch
the next instruction after the CALL
Copyrighted material
MICI'oproeessors and Interfaci ng 3-46 80861nstruclion Set ond ALP
A RET instruction can be followed. by :1 number, for example. RET 4. ln this case the
stack pointer will be incremented by an additi.o na) four addresses after the lP or the lP
and CS are popped off the ~tack. This form is used to increment the s tack pointer up over
parameters passed to the procedure on the s tack.
Flags :The RET instn1ction affects no flags.
Copyrighted material
Microprocessors and Interfacing 3 47 808G Instruction Set and ALP
~
....,.,
I I
EB Dlsp
opcode
near
I I I
E9
Oisp
Low
Disp
Hilt!
opcode
'"' I I
EA
IP
Low
IP
Higll
I cs
Low
cs
High
Fig. 3.20 Instruction fonnats for short, near and far jumps
Copyrighted material
lllicroproc:esoors and lntarfaeing 3 - 48 8086 lnslruclion Set and ALP
As explained earlier, a near type jump instruction can cause the next instruction to be
fe tched from anywhere in the current code segment. To prodtK:e thE' new instntction fe tch
address, thi-; instruction adds a 16bit signed db'Piacetnmt ront.l incd in the in.,010truction to
U'e contents of the instruction pointer register. A 16 bit signed displacement means that
the jump can be to a location anY""here from +32.767 to -32,768 bytes from the current
instruction pointer location. A positive displacen\ent usually means jump is ...ahead" in the
program, and a negative displacement usually means jump is "'backwa rd" in the p rogram.
A special ca:,;. of the direct near jump instrudion is direct short jump. If the
destination for the jump is within a displacement range of +127 to -128 bytes from the
current instruction pointer loation, the destination can be r~acht."'Cl with just an 8 bit
dispL1cernent.
3.7.3 Cond - Conditional Jump
Conditional jumps are always short jumps in the 8086. These in.o;tructions will cause a
jump to a label given in the instruction if the desired oondition(s) occurs in the program
before the execution of the instruction. The destination must be in the range of -128 bytes
to +127 bytes from the address of the instruction after the CQnditional transfer in.o;truction.
H the jump is not taken, execution simply goes on to the ~xt instruction.
Note : The terms greater and less are used to refer to the relationship of two signed
numbers.
Copyrighled material
Microprocess ors and Interfacing 3. 49 8086 1nstruc:11on Set and ALP
Copyrighled malerial
Microprocessors and Interfacing 3 . 50 80861notruction Set and ALP
CLO Instruction :
TI\is instruction is used to reset the d in..>etion flag to zero, so t.hat Sl al'td/or 0 1 can be
incren\L'I'Ilcd automatically a fl t:or CxL-cutinn of string in$tructiOI\S. CLD dOl'S not a ffect any
other flng.
This instruction St'ts the interrupt flag to one. This enables lNTR interrupt of the 8086.
STI does not affect any other flag.
This instruction reoets the internpt flag to zero. Due to this 8086 will no t respond to
an interrupt signal o n its INTR inpul Cll does not affect any o ther flag.
~VA IT
ESC
LOCK
NOP
HLT Instruction :
Tl\\ H LT in!"tructinn will cause th<! 8086 to stop (f.'tchinJ:; .md t>.xccuting ins tructions.
l1'\c 8086 will m ter a halt s tate. The only w ays to get the proet'Ssor out of the halt s late
are with an interrupt signal on the INTR pin, an interrupt signal on the N MI pin.. or a
n.-"Set ~is'al on the RESFT input.
WAIT Instruction :
When this ins truction executes, the 8086 enters an idle condition w here it is doing no
proc.:'e:'Sing. The 8086 wiiJ s1.1y in thjs idle sta te until a signal is asserted on the 8086 TEST
input pin, or until a valid interrupt signal is receivt.>d on the INTR or the NMI interrupt
input pins.. If a valid interrupt occurs while the 8086 is in this idle st.Ue, the 8086 will
r~tutO JO the idJe s tate after the execution of interrupt service procedure. WAIT affects no
flag.-;. 11tc WAET instnction is used to synchronize the 8086 with external hardware such
<\S the 8087 math ropNCl'SSOr.
ESC Instructi on :
This instruction i.s lL'"C'd to pass instmctions to a coprocessor such as the 8087 math
copmo..~~r '''hich ~httrcs the addn-s.c; and data bus with an ~. Instructions for the
copn ll-\.>S~r arc rcpn.~!ntl:.d hy ,, 6-bit C'o dc cmlxodd~..>d in the ~1pe in~ITu ction.. Wl'l(.'l"' the
8086 fete~ an ESC instn1ction, the ooprocX'SSOr decodes the instructio n and carries o ut the
Copyrighted material
Microprocessors and Interfacing 3 - 51 80861nstructlon' Set and ALP
action specified by the 6-bit code specified in the instruction. In m ost cftses the 8086 tre.1ts
tlw ESC ins truction as :. NOP. In ~nne. c,tstos tht> 80S(; will iiC'C'e$:-> a c.lnta item in rnt"mol'y
for the coprocessor.
LOCK Instruction :
In a multiprocessor system each microprocessor has i t~ own local bus...--s and memory.
The individual microprocessors are connccte d together by a system bus so that each can
access system resources s uch as disk drives or memory. Each microproc:essor onJy takes
controJ of the system btL-; when il needs to access some system resources. The LOCK pr.:-fix
allows a microprocessor to make sure that another processor docs not take control o( the
system bus while it is in the middle or a critical instruction which uses the system bus.
The LOCK prefix is put ln front of the critical instruction. When an instnu; ti(m with a
LOCK prefix CX('Cutcs, the 8086 w ill assert its bus Joc-k s ign.1l output. TI\iS signa l is
connected to <1n external bus controller device w hich tht!n prevents .my other processor
from taking over the syste m bus. LOCK affects no flags.
Examples :
LOCK XCHG SEMAPHORE, AL ; lllo XCHG instn tction rcquiros two bus ocC'<.'SS<'S.
; Tht:! LOCK prefix prevent$ another p rocessor
; from taking control of the system bus bctw("("n
; the h\'0 accesses.
NOP Instruction :
At the time of execution of NOP inst:n.rction, no operation is perfonned eXcept fl'tch
and dt'C'Od,~. It ta k~ thn:-"C dod: cycle~ to t'Xt'('ulc the inslruc:tic-m. NOP in~lnu.ti t)fl dtx"l" n.t, t
affect any flag. This instruction is uSL~ to fill in time delays or to delete and insert
instructions in the program while trouble s hooting.
This instruction causes the 8086 to caJI a far p~~ure. The term type in the
instruction reJers to a number between 0-255 which identifies the interrupt. The address of
the procedure is taken from the memory whose address is four tim~-s the type numbc.>r.
INTO Instruction :
1( the o v<.>rflow nag i~
set. this instntction will cause thc 8086 to do an indin.'Ct (.,r .:all
to a procedure you write to handle overflllW condition. To do call the 8086 will read a
. . OOOIOH and a new value of CS from address CXXJ12H.
new value for W from addn:>ss
Copyrighted material
Mlcroproe:euors and Interfacing 8086 Instruction S.t and ALP
IRET Instruction :
The fRET in~lmC't-icn'l is used at lhe end of the interrupl 5'<.'rvicc routine to return
execution to lhe lntcrrupt'Cli program. The 8086 copies return address from stack into IP
and CS r(."'gisters and thE" stored vaJue of Hags back to the flag rt"gister.
Note : Tiu~ RET instruction dOL~ not copy the lings from the stack back to the Ht1g
register.
Copyrighted material
Mleroproc:easors and Interfacing 3-53 80861natructlon Set and ALP
Example :
TABLE OW I 0 DUP (0) ; Reserve an array of 10
; words of memory and iniHaliu all tO
; words with 0. AlTay is named TABLE.
END : The END directive is put after the last statement of a program to tell the
assembler that this is the end of the program module. 'The as.o;emblt.--r ignores :my
statement after an END din."'Ctive.
EQU : The EQU directive is u......_~ to redefine a do'lla namt' or vari.lblc with an'-llh~r
dat.., name, variable, or immediate value. 1lle directive should be dlfirw..od in a pn'J~ra m
beJorr it i~ referenced.
Fonnats :
Numeric Equate : name EQU expression
String Equate : nnmc EQU <:String>
Example : PORT EQU 80 ; Numeric value
NUM E.QU <'Enter the first number :'>
MES DB NUM ; Replace with string
EVEN : EVEN t~Us the assembler to advance its location oounter if neccss..,ry so that
the next defined data item or label is aligned on an even storage boundary. This feature
makes processing more efficient on processors that access 16 or 32 bits a t a time.
Copyrighted material
Microprocessors and Interfacing 3. 54 8086 Instruction Set and ALP
Example :
EVEN LOOKUP DW 10 DUP (0) ; Ot."CI."Ir-es the array of ten words
; starting from even address..
EXTR.N : The EXTRN directive is used to inform assembler that the names or labels
foUowing the dir\.>ctivc are in some other as....;embly mOOule. for exrunple; if you want to
a
c.1U a procedure which is in a program mOOule assembled at different time, you must
teU the assembler that the procedure is EXTRN. The assembler will then put information in
the object rode file so that the linker can connect the two modules together. For a
reference it is neo..:.S..'M'ltY to specify whether the label is near or fa r.
NOTE : Names and labels referred to as e.xtem.'ll in one module must be declared
public:.
Exampie :
CALLING PROGRAM CALLED PK(X;RAM
DATA SEGMENT EXTRN VAR : FAR
I'UDLIC VAR DATA SEGMENT
VARDW
MOV AX, VAL
DATA ENDS
DATA ENDS
GROUP : A program ""'Y contain several segments of the same type (code, data, or
stack). The purpose of lhe GROUP is to collect them all under one name, so that lhey
reside within one segment., usually a data segment.
Formal : Name GROUP Scgn>mc, .. . , Scg name.
Example :
SEG G ROUP SEG!, SEG2
SEGl SEGMENT PARA 'DATA'
ASSUME DS : SEG
~E\. 1 1"'11 ~
:'lot.: ~EG~IfNT I'ARA 'D.-\TA'
ASSUME DS : SEG
.'
SEG2 ENDS
LABEL : Assembler uses a location counter to keep track of how many bytes it is
from the start of a ~gment at any time. The LABEL directive is used to give a name to
the curre-nt value in the location counter. The labd directive can be used to specify
destination for jump or call instruction or to specify refe-rence to a data item. When labe.l
is lL"'-.'<i r.s dt.-stination for a jump or a call, then the label must be specified as type nea.r or
Copyrighted material
Microprocessors and Interfacing 3. 55 8086 Instruction Set and ALP
as type far. When label is uSL"'CJ to refe-r a dnt..l item it mu:-:t tx- SJ>l-"'Cificd a.s type by te,
type word. or type double word.
Example:
NEXT LABEL FAR ; Can jump to NEXT from
; another segment
NEXT: MOV AX, BX ; Cannot do far jump directly to a label
; with a colon.
; lnitialization of s tack pointer using
; label directive
LENGTH : II is an operator which tells the asS<"mblcr to dclemtine tht.~ number of
elements in some named data item such as a string or array.
Example :
MOV BX, LENGTH STRING! ; Loods the Length of string in llX
MACRO and ENOM : Tht macro~ in the programs can bt.~ ddim-d by MACRO
'
directive. ENDM directive L~ uSL-d along with the MACRO directive. ENDM defines th~
end of the macro .
.MODEL : It is available in MASM version 5.0 and above. This din.""Ctivc provides
short-cuts in defining segments. h is initializes memory model before defining any
segment. The me mory model can be SMALL, MEDIUM, COMPACT or LARGE. We can
choose the memory model based on our requirement by referring foiJowi!'S Wble.
Table 3.5
NAME : The name d irec-tive is used at th(> star t of a :o'I'Ur(l' progr,1m to ~i v(' !'pl>c:ific
n..'mcs to c\lch a~sembly modull'.
OFFSET : It is an operator which tells the ilS..~mbkr to determine the offset ur
displacement of a named dahl item (variable) from the start of the ~gmtnt which cnnt.1in..
it.
Example :
MOV AX, OFFSET MESI ; Loads the of6;el of variable, MESI in
; AX regi.<iter
Copyrighted material
Microprocessors and Interfacing 3-56 8086 Instruction Set and ALP
ORG : The as.~mbler uses a location counte.r to account for its relative position in a
dat.l or code scgm~nl.
format : ORG !!Xptt...-ssion
PTR : PTR is used to ossig:n a sp<cilic type to a variable or to a label. It is alo;o used to
override the decJared type of n variable.
Example : WORD_LEN DW
MOV BL. DYTE PTR WORD_LEN ; Byto nccess..'S byte from word
PAGE : The PAGE din.--ctive helps to control tho: forma t of a listing of an assembled
program. At the !'~tart of a program the PAGE directive specifies the maximum number of
lin'l"S to list on a pagl." and the n.aximum number of characters on a line.
Format : PAGE [length), )width)
Example : PAGE 52, 132; 52 linos per page and 132 ch.1mcters per line
PROC and ENDP :
PROC : 1be procedures in the prog.rams can be defined by PROC d.in.ctivc. 1hc
procedure name must be p~nt, must be unique, and must follow naming conventions
lor the language. Alter the PROC directive the tenn NEAR or FAR are L'"ued to sp<cify
the type of the procedure.
Example : FACT PROC FAR ; Identifies the start of a procedure named FACT and tells
the assembler that the procedure is far (in a segment with a different name from that
which contains lhe in.o;;tructicm which calls the procedure)
ENDP : ENDP dirt!Ciive is used a long with the PROC directive. ENOP defines the end
of the pron>dure.
PUBLIC : Large probrrams are u::oually written as several separate modules. Each
mod1~e is individuilll) assembled, testro and debugged. When all the modules are
working et')rrc<:tly, their object code files are linked together to fonn the complete program.
In order for the modules to link together correctly, any variable name or k1bel referred to
in other modules must be declared public in the module where it is defined. The PUBLIC
directive is used to tell the assembler tha t a specified name or label will be accessed from
other moduJes.
Format : PUBLIC Symbol I . . .. I
Copyrighted material
3-57 8086 Instruction Set and ALP
name ENDS
Example : CODE SEGMENT
CODE ENDS
SHORT : A s hort is a operator. It is us..>d to tell the as.~mbler that only 1-byte
di.:,1>la~ment is la'ded to codt: a jump instruction. If the jump destination is after the
jump in.o;truction in the program. the assembler will automatic..'llly reserve 2.-bytcs for the
displacement. Using the short opt>rator s.1vcs 1-bytc of memory by telling the assembler
that it only needs to reserve 1-byte fo r thl~ particular jump. The short operator should be
used only when the destination is in the ronge of - 128 bytes to +127 bytes from the
address of the instructions after the jump.
.STACK : This directive provides shortcut in definition of the stack segment. General
fonnat for this directive ls as shown below.
.stack (si7,e)
The default siz.c is 1024 bytes.
Example : .STACK 100 ;This reserves 100 bytes for the stack operation.
When stack is not used in the program .stack command can be omitted. This will
reserve in the waming message "no stack segment"' after linking the program. This
warning may be ignored.
TITLE : The TITLE directive help to control the fomlat of il listing of an a!'sembl t~
program. TmE directive causes a title for a progrclm to print on line 2 of e.,"'ch page of the
program listing. Maximum 60 characters are allowed as title.
Format : TITLE text
Example : TITLE Program to find maximum number
TYPE : Tt is an operator which tells assembler to determine t~ type of specified
variable. Assembler determines the type of specified variable in number of bytes. For byte
type variable the assembler gives a value of 1. For word type variable the assembler gives
a value of 2 and for double word type variable the assembler gives a value of 4.
Copyrighted material
Microprocessors and Interfacing 3 . 58 8086 Instruction Set and ALP
Table 3.6
Copyrighted material
Microprocessors and Interfacing 3-59 8086 Instruction Set and ALP
,... Example 1 : "FUt1.asm"' coutains a program segmtnt wllidr calls a subrouNtu (procedurt)
;, '"FUt 2 .asm'". Give tile ntef'.SSIIry declarations in FU~1.nsm nud HFife2 asm " (to maY
the subrouliut! of file2.asm availnblr to filt!1.asm which is uot /QC.n/Jy tr.Jailable) aud tile
as~mbliug n11d li11king to obtain the r xtculnblt' Jilt.
Copyrighted material
8086 Instruction Set and ALP
ROUTINE ENDP
Specifying the problem : The first step in the programming is to find out which
tas k is to be perfonned. This is called specifying the problem. II the programmer
does not understand wMt i~ to be done, the programming proces.o; cannot begin.
Designing the problem-solution : During thi< proccs.<, the exact step by s tep
process that is to be followed (program logjc) is developed and written down.
Codi_ng : Once the program is specified and designed. it can be lmpl.eme:nt<.-d.
Implementation begins with the process of coding the program. Coding the
program means to tell the pro<:es-<Or the exact step by step process in its
language. Each processor has a set of instructions. Programmer has to choose
appropriate instructions from the instruction set to build the program.
Debugging : Once the program or a part of program is coded, the next step is
debuggjng the code. Debugging is the process of testing the code to see if it does
the givon task. If program L< not working properly, debugging process helps in
finding and correcting errors.
To write a program, programmer should know :
Copyrighted material
Mlcrop<ocessors and Interfacing 3-61 8036 Instruction Set and ALP
Flow Chart
To develop the p rogramming logic programmer has to write down various actions
which are t<) ~ performed in proper ~uence. The flow ('hart is a graphical tool that
allows programmer to "'J'reserlt various actions which are to be p<!rformed. The graphical
"'Presentation is very useful for clear understanding of the progranuning logic.
The Fig. 3.21 shows the graphic symbols used in
(..._____.) the flow chart.
Oval : It indicates start or s top operation.
Anow: Jt indicates flow w ith direction.
<>
CJ
operation.
Double sided rectangle : It indicates exec:ution of
pre-defined process (subroutine).
used In now chart The Fig. 3.22 shows sample flow chart.
Start
Cal subroutine
Sic!>
Fig. 3.22 S.mple flowchart
Copyrighted material
Microprocessors and Interfacing 3. 62 8086 Instruction Set and ALP
Copyrighted material
Microprocessors and Interfacing 3. 63 8086 Instruction Set and ALP
M
\ /oo= o~nd
AGAIN : ADO AX. price (BX) ; Add prke of item to AX
'\
Sr. No.
Label
Machine Language
""'
Assembly Language
Comment
Copyrighted material
Microprocessors a nd lnteffaclng 3-64 8086 lns tructlon Set and ALP
space and time. let us see the space and time requin..>d for ~ two
instmctions. The ins truction ADD BX, 0001H is 4 byte in."ilruction and requires 4
dock cydes to execute. On the other hand, INC BX Lot a single byte instruction
and requires 2 cyc.les for the execution. Tha t is instruction INC BX requires less
memory space and exccutlon thne than instruction ADD BX, OOOl H. Therefore,
programmer must use INC BX instrnctio(l in such situation.
Use of advanced instructions : We must optimally utilize the pl"()C(!S_o;or
capabilities. For example, when it is necessary to write a program to move a
block of data from the source to destination location, a programmer may
initialize a p""'inte.r to indicate source location, a pointer to indicate destination
location, a counter to count tht' number of data elements to be transf('rred. Aftt>r
transfer of one data clement from source to destination location programml'!r
may use INC, DEC and JNZ instructions to increment source and destination
pointers, decrement cmmter and to check whether all data elements are
transerred or not, respectively.
The same task can be implemented by MOVS instruction supported by 8086. Let us sc.>e
the p<'lrt listing of the program with both the approaches and then we compare them.
1. Part listing of program with general approach
MOV SI, lOOOH ; Initialise source pointer
MOV 01 ,2000H Initialise destination pointer
MOV ex, 0020H ; Initialise counter
BACK MOV AX, I S II ; Get data element from souroe
MOV (Oil, AX ; Store it at destination
INC sr ; Incre-ment source pointer
INC OI ; Increment destination pointer
DEC ex ; Decrement counter
JNZ BACK If count is not zero, repeat
2. Patt listing of program wtttl MOVS lnslruetlon
MOV SI~ 1000H ; Initialise source pointer
MOV OJ, 2000H Initialise destination pointer
MOV CX, 0020H ; Init ial ise counter
CLD ; Cl ear direction flag
REP MOVS8 ; Move the entire block
Looking at the lwo programs we can ily notice lhat the MOVSB instructlon needs
neilher counter decrement and jump back nor pointer up<fute instructions. All these
functions are done automatically. S.Causc MOVSB instruction copies multiple bytes fTOm
source to destination. After each byh! transfe< it automatically incremmts SJ and 01
pointers by I (since OF is 0) and decrements count in CX n:gister and il repeats this
process until ex = o.
In the second approach, we require less numbe< of instructions and memory space. As
numbe< of instructions are less, fetching time required for the instructions is also wed
and hence we can say lhat the ...,i>nd approach requi""' less memory space and less time
to exute the same task. So skill programmer ......,. second approach.
Copyrighted material
Mlcroprocosoors and Interfacing 3-65 8086 Instruction Set and ALP
Use of prope.r addressing modes : We know that the diffe rent ways th3t a
p~r can ac:.cess data a re n>ferred to as addl"\.:.ssing modes. If we compare the
variOlL"J addrcs..~ing mod~ n><1grding acces...o; time required for acce!>~ing ope-rands,
we can easily make out that the register addressing takes less time to access
operand than the index and ind irect addressing modes. lt is obvious that when
operands arc available in CPU registers they a rc immediately available for
operation; however when they are in memory we have to fetch them from
memory. Fetching operands takes more time. So it is advisible to store most of
the operands in the CPU registers. We know that CPU registers arc limited in
numbers. Therefore, when they are not enough then only we should use memory
space for storing the operands.
Prepare documentation : Program mus t provide enough information so tha t
other tL<;CtS can utilize thl" program moduJe without having to examine its
internal s tructure. So along with program it is ad\rised to give the following
information.
1. Description of the purpose of the pr<)gram module.
2. In case of subroutine program IL<il ()f passing parameters and retun\ value.
3. Register and memory locations used.
4. Proper c::ommc:nts for e-ach inslruction uSL"'<i.
3.13.3 Programming with an Assembler
let us see what arc the steps involved in developing and executing assembly language
programs. Fig. 3.24 s hows these steps. The left side of the figure shows t~ time pl--*fiOd, a t
which each step in the overall pn~ takl'S place.
Assembty WJnguage
nme period program tel!l wrlnen
~ -------------------I
in 3tY'f text edltot
Program li5ting I I
I
I Etrot messages
I
I
J.- ~
( Assembler
'
Olofect code Other object code
module In binary modules from library
I
Link time ( linker y
I Lil'lked module$ I
..---:-::..
~
.....
"''- ~~' Pro<:o5$01'
...... -
~ - "'...
~
~~
memo<y
Loade< } ""
CPU I
Exoeucion lime
Fig. 3.2.. Steps in program development and execution
Copyrighted material
Microprocessors and Interfacing 3-66 8086 Instruction Set and ALP
The first s tCp in the development process is to writ~ an assembly language program.
The assembly language prog-r am can be written with an ordinary text editor s uch as word
star. edit and so on. The assembly language program text is an input to th~ assembler. The
assembler tran.slat<.-'S assembly language statements to their binary equiva l enL~, usually
known as object rode. Time required to trans la te assembly code to object code is caUed
assemble time. During assembling process assembler checks for syntax errors and displays
them before giving object rode module.
The object code module contains the information about where the progr;,m or module
to bl.> loaded in memory. If the obj\.>ct code module is to be linked with other separately
assembled modules then it cont<tins additional linkage information. At link time, separately
assembled moduk--s ;.\r(' combint.'Cl into one s-ingle load moduJe, by the linker. The linker
also adds any required initialization or finalization code to allow the operating system to
s tart the program nanning an d to return control to the operating system ilfter the program
has completed. Mo~t linker$ allow assembly language modules to be Linked w ith object
code modules compiled (roan highlevcl l:mguagcs as well. lltis allows the programmer to
insert a time-critical assembly language routines, library modules into a program.
.' .
At load time, the program loader copies the program into the computer's main
memory, and at exution time:, program l"XOCution begins.
.
3.13.3.1 Assembling Process
As mCI\tioned ~ rlier. as.<;embler translates a sourc:e file that was created using the
editor into machine Lmguage such as binary or obj1.."C't rode. TI\C' asst."lllbler reads the
SOlli'Ce fil~ o( our program from the disk where we saved it afte:t' editing. An as:.wmbler
usually reJds our sout'C(' file more than once.
The assembler generates two files on the Ooppy or hard during th<>se two P"-''"""' 1lle
first file is calkd the object lilt. The object file contains the binary rodes for the
instructions and information about the addresses of the instructions. The second file
generated by the as..o;cmblcr is called assembler list file. This file contains the assembly
language s tatements, the binary code for each instruction. and the offset for each
instmction.
ln the first pass, the assembler performs the following operation" :
l. Reading the sc.lun:e pn.wam instructions.
2. Creating a symbol table in which ali symbols used in the progmm, together with
their attributes, are ston.---d.
3. Replacing ali mnemonic rodos by thc,;r binary oodes.
4. CNtecting any syntax errors in the source program.
5. Assigning relative addres..-;es to instructions and data.
On a second p.us thnlugh the source program, the assembler extracts the symbol from
the operand field and searches for it in the symbol !able. If the symbol does not appear in
Copyrighted material
Microprocessors and lnterfaclng 3 -67 " Set and ALP
80861nstructlon
.
the tl'lble, the corresponding statement i$ obviously erroneous. I( the symbol docs appcnr in
the table, th~ symbol is rep laced by its addrt'S~ or value.
We can use 0'1 s uitable Editor to type .asm flit.-.. We can runvcrt object (iJc from .asm (if('
using popular assemblers MASM (Microsoft mac-ro assembler) or TASM (Turbo as~mb l cr).
The command on command prompt pcrfom1ing this operation is as given below
C:\ MASM\ BIN\> MASM myprog.asm;
where myprog.asm is name of the .asm file w hich is to be converted to .obj file.
Copyrighted material
MleroP<OCessors and Interfacing 3-68 8086 lnsb'uctlon Set and ALP
Debug Commands
~ I
- H value 1 value 2
H command performs addition and subb'action on two hexadecimal nurnbetl.
load - l (add<ess) (drive) (fitst sectO<] (number]
L command loads a fie (or disk sectors) into memory.
M<MI - M range address
M command oooies a block of data from one k>cation to another.
Name N (pathname) (etglist)
N command initializes a fitell3me (and file control blodt) in memory before using
load or write commands.
PIOC$e(l - P ( address)(nlmber)
P command traces the program without entering the subroutine or intet'T\4)t. If
SUCh instruction appears in the program it executes entire subroutine or ~terrupt
routrle and immediately pnxeeds to next instruciton in the sequence.
Quit - a
a ~ Quito rrom debug.
Register - R (register)
R command diOD!ays the
. r conhmt:s on the screen.
Searcn - S range list
S command seardl a ranoe of add<esses lor a list or bvtes or a otrino.
Traoe - T (= address) (value)
T oomm81nd execute one Ot mont lnsVuc:tionl from the current CS : IP location or
1 address, if
.
Unassemble - u (nlnge)
U command translates memorv into Ia """""""ics-
Write - w (address) (dr1vel (flr1l sector! (n...-,
W oonvnand wrlle a bkldt of memory 10 a file or to indMdual disk aedors.
Copyrighted material
lllcropi'ClCHSon nd lnterfc:lng 3 - 69 8088 Instruction S.t and ALP
Copyrighted material
Miuoproeesao~ and Interfacing 3. 70 8086 Instruction Set ond ALP
ov
>!OV
ES , J!..X
CX. OOOAH tni t ial i se counter
LEA Ol , AFO.AY !nitiall5e ba3e point~ r for a rra y
i'10V AL, SEK_t:J Gel the n\:mber to be searched in AL
CLD Clear direction flag
REPNE SCAS ARRAY Repeat until match occurs or ex 0
MOV AL, 10 { F i nd the searc hed number position
sua At.,CL in the array i f SER_POS is 0
t-10 V SER POS, AL numbQr is not in array; othe rwise
SER_POS gives the position of
number in t he array J
END START
Program 5 : (Soitcopy o( this program, PS.asm i~ avo1ilabl~ at www.vtubooks.oom)
NAME Array sum
PAGE 52 , 90
Copyrighted material
llllcroproceuors and lnterfac:ing 3. 71 8086 InstrUction Set and AlP
Copyrighted material
Microprocessors and Interfacing 3-72 80861notruction Set and ALP
Copyrighled malerial
llillcroprocessOO'S and lnlllffllclng 3 . 73
value is applied when the condition is not met, and the larger value is applied when it iS
met. The first instruction MOV CX, count is executed only once and it requires 4 clock
cyclc.-s.. There are cmmt-1 passes through the loop where the condition is 11'let and control
is transferred back to the first instruction in the loop (DEC CX). The number of dock
cycles that elapse While CX register is not zero 3n! (COunt-J) X (2 + 16). Qn the last pass
through the loop the condition is not met and the loop is terminated. The number of dock
cycles th3t e.Lapse in this pass are 2 + 4.
:. Total dock cycles required to execute the given program
:. Total time required for execution o( a given progrnm with count equal to 100 is
1?9.2 "sec (1?92 x 0.1).
In the above example, we have calculated the time required for the execution of
program or delay introduced by the program when count value ls given. However, in
most of the situations we know the waiting time or delay time and it is neces...~ry to
detennine what count should be loaded in the ex register to get the specified delay. Let
us consider that we have to generate a deJay of 50 ms using an 8086 system that runs at
10 MHz frequency. Then using same program we can calculate the count value as follows :
500000 - 4- 6
= (16 +2) +
1
~ 27778 = 6CS2H
Copyrighted material
Microprocessors and lntert.clng 3. 74 8016 Instruction Sat nd ALP
For count = 100 and multiplier count 50, the number of dock
cycles required are
= [ 4 + (100 - I) X (2 + 16) + (2 + 4)) X 50
Copyrighted material
Mlcropr...,....,... and lnterfaelng 3-75 8086 Instruction Set and ALP
1000000-4-6
1
(16 + 2) +
G 55556 D904H
,. . Example 3 : Write arr 8086 ALP to gf!m7alt 11 delay of 1 mimtle if 8086 systt-nl freque,cy
is 10 MHZ.
S olution :
Program
MOV ax, mu l tiplier count
RE PE MOV CX, Count ; 4
BACK ' DEC CX ; 2
JNZ BACK ; 16/4
DEC BX
JNZ REPE
S tep 1 : Ca lct~ate the delay generated by iiUl<'r loop with maximum ootmt (FFFFH)
Delay generated by inner loop for count (FFFFH ~ 65535)
= (4 + (65535 - 1) X (2 + 16) + (2 + 4}) X 0.1 flS
= 118.1422 msec
Step 2 : Calculate the multiplier oount to get delay o( I minute
Rt.'quin.>d delay
multipHer count =
Delay provided by inner loop
1 x 60sec
= 118.1422 m sec
~ 509 = IPDH
Copyrighted material
Microprocessors and Interfacing 3. 76 8086 Instruction Set and ALP
device. On the other hand, processor docs not und erstand the ASCll format. It uses binary
numbers. Therefore, it is necess.ny to convert input from keyboard to its binary equivalent
(ASCJJ to bin..1ry conversion) and convert processed data by processor into ASCII forma t
for the dis play (binary to ASCD conversion). Let us see how we can perform these
conversions. ln this St.--ction we s tudy the routines for these conversions. Once we
underst;md these routines we can use these routines to accept input using keyboard and to
display dat:'l on video monitor.
AXjoo Jssj
AH Al
. AAM--EB
AH Al
Now : 38H and 39H are the ASCU equivalents ~ 8 and 9 resp6Clivel'y
Copyrighted material
Mlcroptocessor:s and Interfacing 3-n 8086 Instruction Set and ALP
Flow Chart
l Start
I
I Save registers 1
I
Get me hex nl.II'I'Oer
I
Convert it into Its
decimal (BCD) equlvolenl
I
Unpack the BCD digits
I
Add 30H in each BCD
dlgh to get its ASCII equlvcdent
I
Display eoch dlgil
I
Remre registers
I
( End )
Copyrighted material
Microprocessors and Interfacing 3. 78 80881nolructlon Sat and ALP
P\)SH BX
PUSH AX
p n hr 1 n
Microp<ocessors and Interfacing 3-79 8086 Instruction Set and ALP
12 c - 01
10) 123 A J 7BH
- 120 - 78H 02 l\
3 03 03 ~)
1 1 :--,/
~
10) 12 A) c -\
- 10 - A
30H - 31H
2 2
0 0 ' 02. 30H- 32H
10) 1 A) 1 03+ 30H - 33H
- 0 - 0
1 1
Let us see the algorithm for converting number from binary to ASCII rode.
Copyrighted material
Microp<ocessors and Interfacing 8086 Instruction Set and ALP
Flowchart
( Start
I
Save~
I
Get the hex nl.W'I'Ibe:r
J.
No Check W
~uotient is 0
v..
Gellhe remainder
I
Convert 10 ASCU and dl$play
No Check W
11 remai'lclers a
""'' v..
Retrive reglaler contents
I
( Stop )
Copyrighted material
Microprocessors and Interfacing 3-81 8086 Instruction Set and ALP
PUSH BX
PUSH AX
MOV ex, 0 ; Clear diglt counter
HOV BX, 10 ; Load 10 decimal in BX
BACK: MOV ox, 0 ; Clear ox
OJV BX .
Divide ox : AX by 10
PUSH ox ; Save rema.indar-
INC CX Counter remainder:
OR AX, AX ; Test i f quotient equal to zero
J NZ BACK ; I f not zero divide again
MOV AH , 02H ; Load !unction numbeJ:
OISP: POP ox ; Get remainder
ADD DL, 30H ; Conve-rt to ASCI I
INT 21H ; Display digit
LOOP DTSP
POP AX ; Restore .ccgisters
POP BX
POP ex
POP ox
RT
ENDP
END
Sample Program
; Sample proqr._m to convert 4diglt hex into its decimal
; and then to ASCII equivalen t, and displdy it
I'IJ~ cl<
PIISII Ill<
l'tlSH AX
MDV ex, u I Clriar digit countec
>tOY ax, 10 ; Load ~o deci.nl~l >.n BY.
,BACK~ MOV !>X, a ; C!'lea& OX
DIV ax ; ctivida DX : AX by 13
I'llSA Q)<. ; Save r.main dl>r
INC C'X I ..:'nun tee re.mainde~
0~ 1\1., Ml ; Te*'t" H qu"'tlen.t eqtl~l o "Zero
J1'!ll l!ACII ; :! 1\C!l zero dlvl-Mo a.;a.ln
OOV AN, o:m .
Lo~ct tunction numher
Ol$t': I?OP DX ; Get .rema.lru:i.er
ADD t>L, :()B ; Cortvc: r:L to 1\SCI.I
i y11 Itt
Micr oprocessors and Interfacing 3. 82 8086 lnstruclio n Set a nd ALP
C: \tasm\tlink s bta4d.ObJ
Turbo Lin k Ver-~n on 5 .0 Copyrigh t I C) 1992 Borland International
C: \tasm\s bt.a4d
10940
-
Key~. t<.ylnput SUBlCII't ~
2 - 32H - 32H-30H
~OA
02
Multiply by 10
14H
,
s- 35H
- 35H-30H
-
xOAH
05H
19H
- """' digit
MUltiply by 10
FAH
s- 36H
- 361i-30H
- +
06H Md next digit
100H - Resull
2560edmal - 100H
Y'lt ,fr.'t_'''
Microprocessors and Interfacing 3-83 8086 Instruction Set and ALP
Let us see the algorithm for converting number from ASCII to binary code
Algorithm
1. Save contents of all registers which a.rc used in the routine.
2. Make binary n.">Su1t s=: 0.
3. SubtTact 30H from the character typed on the keyboard to convert it to BCD.
4. Mt~tiply the result by 10, and then add the new BCD d igit.
5. Repeat steps 2 and 3 until the character typed is not an ASCII coded number.
6. Restore register contents.
Flowchart
l Start )
I
Save register oonlent5
I
Result= 0
No
().9
Yes
-
Convtwt it to 8CO
( Sub 30H ) d;g;c Save result
I t
Result = Result 10 + BCD digit Reskn reglsler contents
I ~ 5J.
l Slot> ) '
..\
-
. ~
Copyrighted material
MletOprocessors and Interfacing 3 84 8086 Instruction Set and ALP
~lP:
l.T!dP eAt~;
rdOV NltMBER, BX
"" ; ReptMt
..- 54\t~ tne .t .;;ul t.
1-a51.1 H
l.n NOMP.EP.
~"
POf
E'()P GX
I'OP ox
P.E.tt'
NDP
tll!l
C: \tasm\tasm .s_atb.ascn
Turbo Asse-mblet Ver$lOn "'3.0 copyriqht {C} 1 988 , 1991 socland
International
Assembling tile : s atb . asm
Erro.r messages: None
Wurn ing messages: None
Passes: 1
Remaining memory: 410k
0 I 0 I 0 I HI
Shifllefl4-bi1al o I o I HI o 1- o
Key
o i HIAL '"""t
2
0 0 I HI HI
Slllftleftbo1ol o I HI HI o 1-o
Key
oiHIAL ii\I)Ul
3
I HI HI HI
Shiflleft4-bi1al HI HI HI o 1- o
Key
loiHIAL ii\I)Ul
I HI HI HI HI
Not ; H represents any heJCadeeimat digit (Q-;F).
Algorithm
I. Sow~! rcgistc~
2. Make res~t =0
3. Get the ASCII code of character from keyboard and
S-ubtract 30H from it i( du1racter is 0 - 9
Subtract 37H fl'om it if character is A - F
Copyrighted material
3-87
Flowchart
'
~
Mk:roproceuors and lnterfloclng 3 &088 lnotructlon Set ond ALP
Copyrighted material
MlaoptocHaors ond lnt.rfaclng 3 . 88 8086 Instruction s.t and AlP
.DATA ; Strt data acgment
NUMBER OM? : Do tine NUMBER
.COO& : StJrt code ae~nt
START,HOV AX, @DATA ; I tnit ialize
MOV OS, AX ; dlolta seqmont1
CALL o< 11: K ; F n 4-jl~ ~ hex nu1 L r
,.,. . Ali, 4~t ; lO
H~ 2l.H~-----------
PMI:' 11: .
IUSH CX ; '~'I req.!.sto
JtSH X
1'\JHA.l(
~H s
MOV Ct, 4
II V ol, 1
MI)'V ~,. ;
MOl .:..s, I
rt
A L VNV n::~ry
HL BY,
lll'D Bl., Al. :
$!
5 ;
"
MOll NI.IH B.~ :
I'OP SI :
f AA
'
p(p
f BX
...
F:uor
. T ov t f AI. l
quh
MP LAS!
I
I
rr))ct 5111
,. ... f HL H
SUS AL, 3 8 : v r.
H LA!TI
f118T~T, ~1. :.;;us AL, 37t : (" ez=-t r.l.fo' ca&"' t"V"r
... ;srt.
yrr 11 m
Mlcn>processors and Interfacing 3 - 90 8088 Instruction Set ond ALP
C: \ta sm\tasm s r dhex . asm
Turbo Assemble r Ver sion 3 . 0 Copyr i gh t (c ) 1988, 1 991 Borl a nd
Interna tio nal
Assembling f ile : s _ rdhe x . a s m
Err o r mes sages : None
Wa r ni ng messages : None
Passes : 1
Re ma ini n g memory : 410 k
16 bH
,-------A~------~
<1s 12 11 s a o)
I
l)tqllay
I
130H .. 37H :::::::::> Digit (LSD)
Nibble
Copyrighted material
Microprocessors and Interfacing 3-91 8086 lna1ruc:tlon s.t and ALP
Algorfltlm
1. S.we registers.
2. Get the number and unpack digit from it.
3. Add 30H if d igit is 0 - 9 or add 37H if digit is A - F to got the ASCII code of
digit.
4. Display digit.
5. Repeat steps 2, 3 and 4.
6. Restore regt.o;ters.
Flowchart
Unpack nibble
Add 37H
Display digit
No
Re:sw-e registers
Stop
Copyrighted material
Microprocessors and Interfacing 3-92 8088 Instruction Set end ALP
Routine
; Routine to displ ay 4-digit hex number in AX
MODEL SMALL
STACK 100
. CODE
Copyrighted material
Mjcroprocessors and Interfacing 3. 93 8086 Instruction Set and ALP
0 _RE:< ~ROC NEAP
PlJBR DX
PUE'H CX
PVljR A.'(
t-'\)P ril-!
POl ex
E'"'~'P DX
RET
&I!DP
ENP
C:\tasm\tasm s d hex.asm
Turbo Assembl er -version 3 . 0 Copyri9ht fc) 1988, 1991 Borland
International
Assembling file: s d hex . asm
Error messages: NOne
Warning messages: None
Passes: 1
Remaining memory : HOk
C:\tasm\tlink s d hex.obj
Tur bo Link VerS.iOn 5.0 Copyright. (c) 1992 Borland Inc.ernar.iona l
C: \tasm\s d he<
12A8 - -
g
Code forrno1ion byte
c 0 g
I
Fig. 3.25 7-segment code formation
A look-up table can be stored in the program memory (code segment) or in the dabl
memory (data segment). Let us see the program which uses lookup table stored in the
data memory to convert BCD code into its 7--scgment equivalent code.
Copyrighted material
Microprocessors and Interfacing 3-95 8086 Instruction Set and ALP
'
HOV AH, OOH : [Multiply the AL by 2
ADD AX, AX : to point to correct
ADD SI , AX : month of the year ]
HOV ox, [SI ) ; Get month of year
MOV AH, 09H : (Display month
l Copyrighted material
Microproces sors and Interfacing 3-96 8086 Instruction Set and ALP
I NT 21 H ; o f ye a r s tring)
MOV AH, 4CH ; (Exit
I NT 2 1H ; t o DOS )
END ST>.RT
END
3.17 Procedures
Whenever we net.~ to use a group o ( instructions several times throughout a program
there are two ways we can avoid having to write the group of instructions each time we
want to usc them. One way is to write the group of instructions as a separate pn:x:edure.
We can then just CALL the pr<>c.."t..">dure whenever we need to execu te that group of
instructions. For c.:11Hng the procedure w e have to store the reh1m address onto the s tack.
This process takes some timc. Jl the gro up ol instructions is big enough then this overhead
time L.;; nt..:.gligiblc with respect to execution time. But if the group of instructions is too
short, the overhead time and execution time are comparable. In s uch cases, it is not
dc..>sirable to write procedures. For these cases, we can use macros. Macro is also a group of
ins truc;tions. Ench time we "'CAL'L" a macro in our program, t~ assembler will insert the
defined group o ( instruction-; in place of the .. CALL"'. An important point here is that the
assembler generates machine codes fo r the group of imtnctions each time macro is called.
So there is not overhead time involved in calling and returning frum a procedure. The
d isadvantage of rnacro is tha t it generates inline rode each time when the macro is called
which takes more memory. ln this section we discuss the procedures.
From the above dL~ussions, we know Ulat the procedure is a group of instructions
s tored as n scpnrnte prog:ram in the memory and it ls called from the main program
wheJ\L""Ver required. 11\c type of procedure depends on where the procedure is s tored in
the memory. If it is in the same code segment where the main program is stored then it is.
rnlk'CI neilr procedure otherwise it is referred to n.o; far procedure. For near procedure
CALL instruction pushes only the fP register contents on the stack, since CS register
contents remains unchanged fo r main program and p rocedure. But for fa r procedures
CA LL instruction pushes both II' and CS on the stack. Let us see the detail description and
example'S of CALL instmction to enter the p rocedure and RET instruction to return from
the p r<K:edu re.
CALL Instruction :
The CALL instruction is used to transfer execution to a subprogram or procedure.
There are two basic typt."S of CALL<~, near and far. A near CALL is a call to a procedure
which is in the same code segment as the CALL in..ttru<:tlon. When the 8086 executes a
near CALL instruction it decrements the s tack pointer by two and copies the o ffset of the
1\ext ino;tructiot'l a fter the CALL on the s tack. It loads r.P with the offset of the first
instruction of the procedure in s ;\me ~en t.
A far CALL is a call to a procedure which is in a different segment from that which
contains the CALL instruction. When the 8086 executes a far CALL it decrements the s tack
Copyrighted material
Microprocessors and Interfacing 3 . 97 80861ns truction Set and ALP
pointer by two and oopies the contents of the CS register to the stack. It then decrements
the stack pointer by two again and copies the offset of the instruction after the CALL to
the stack. Finally, it loads CS with the segment base of the SL>gment which contains the
procedure and JP with the offset of the first instruction of the procedure in that segment
Examples :
Direct within segment (near)
CALL PRO ; PRO is the name of the procedure.
; ThC' assembiC'r determines displacement of pro
; from the instruction after the C ALL and codes
; this dis placement in as part of the instruction.
Indirect within~segment (near)
CALL CX ; CX contains, the offset of the first instruction
; of the procedure. Replaces contents of IP with
; contenl") of register ex.
Indirect to another ~gmen t (far)
CALL DWORD PTR fBX) ; New values for CS and TP are fetched from four
; m~mory locations in DS. nu~ new value for CS
; is fetched from fBXJ and [BX + 11. the new IP
; is fetched from [BX + 2[ and (BX + 3].
RET Ins truction :
The RET instruction will retun\ cxocuti01\ from a procedure to the 1\CXt instruction
after the CALL instruction in the calling program. H the procedurt> is a near procedure (in
the same code seJ,oment as the CALL instruction), then the return will be done by replacing
th(! instmction pointer with a word from the top of the stack.
If the procedure L-; a fa r pr<X'edure (in a different rode segment from the CALL
instruction which calls it), then the instruction pointer will be r~ l accd by the word a t the
top of the s tack The s tack pointer will tht.'l\ be incremc1\ted by two. The code segment
register is then replaced with a word from the new top of the stack. After the code
8e!,'l'nCnt word is popped off the stack. the s tack pointer is again incremented by hYO.
These words/word arc the offset of the next instruction after the CALL So 8086 will fetch
the next instruction after the CALL.
A RET instruction can be follow~.---<! by a number. for example, RET 4. ln this case the
stack pointer will be incremented by an additional four addres..CO(.>s after the IP or the lP
and C:S are popped off the stack. This foml is used to increment the stack pointer up over
parameters passed to the p rocedure on the stack
Flags : The RET instruction affects no flags.
Copyrighted material
.,
Mic.roprocessors and Interfacing 3 . 98 8086 Instruction Set and ALP
PROCEDURE 2
CALL
PROCEDURE 1
NEXT MAINUNE
INSTA.UCllON
AFTERCAI.L
RElVRNrO
UAIN PROGRAM , '
MAINliNE
lfN>I(I
OCR!MH1' N
CALL Rt.OUI:tSIVE
ElSE
R<TURN
Copyrighted material
Mlcroprocessol$ and Interfacing 3 . 99 8086 Instruction Set and ALP
.,
3.18 Macro
Macro is a group of instructions. The mac-ro assembler generates the code in the
program each time where the macro is 'caUed'. Macros can be defined by MACRO and
ENDM assembler directives. Creating macro is very similar to creating a new opcode that
can be used in the program, as shown below.
Table 3.8
Passing Parameters in Macro
l.n Macro, parameters are passed as a part of statemc:nt which calls Macro.
Example:
PROMPT MACRO MgssAGE ;Defi ne macro with MESSAGE as a parameter
MOV AH, 09H
LEA MESSAGE
INT 2 1H
ENDM ;End macro
DATA
ME$1 DB 10, 13, 'Student Name : $'
MES2 DB 10, 13, 'Student Address : $ " .'
. CODE
START : NOV AX, @data Initialize
MOV OS, AX
;
Copyrighted material .
Microprocessors and Interfacing 3-100 80861nstruction Set and ALP
Body of the Macro can use local variables. A local variable defined in the Macro is
available in the Macro, howcv~r ll is not available outside the Macro. To define a local
varit~blc, LOCAL dir~tivc is u:o:ed. Example shows how local variable is used as a jump
address. If this jump address is not defined as a local, the assembler give an error mess.1ge
on the second and subsequent attempts to use the Macro.
Example
DISPLAY MACRO A Displ ays ASCII character i n uppercase
LOCAL J LABEL ; Defines J LABEL as local
PUSH OX
C.MP J.L , ' Z '
JB J l l\JleL Check if uppercase
SUB AL , 20H Convert to uppercase
J LABEL: MOV DL, hL
MOV 1\H, 0 2H
tNT 21 H
POP OX
ENDM
The above Macro aoccpt~ ASCII code for character. (AZ or az). H it is (or lowercase
character, Macro conv(.rts it to uppercase character and displays the uppercase character
on video screen.
H is important to note tho.l l local variable or variables must be defined using LOCAL
d irec-tive immediately after MACRO directive.
Copyrighted material
Microprocessors and Interfacing 3 101 8086 Instruction Set and ALP
Qooode
IOooodl Rog I
Opoode
..
Re It is 1u 1o I from m c m o ry w It h :. u dIS p ill c e 111 e n t
Oisp
Qooode II ModjOpcode IRIM I !Oow-oroe< Olsij IHigh.orde< Oispl E<'d"OP8i@ (igl><le< "*'"'4
Fig. 3.28 Sample 8086 Instruction fonnats
The opcode and the addressing mode js specified us ing first h.,ro bytes of an
inslnoction. The opc()(le/addressing mode by te(s).
The opc()(le/addressing mode byte(s) may be follow<'<~ by :
No additional byte
Two byte EA (For direct addressing only).
One or two byte displacement
~ or two byt~ immOOiatl! operand
One or two byte displacement followed by a one or two byte imml...:iiate operand
Copyrighted material
Microprocessors and Interfaci ng 3 102 8086 Instruction Set and ALP
Two b)tc d isp l ac~mcn t and a n ..o byt~ segment address (for direct intersegment
Jddrc:;sing only).
Most o( t-he opcodcs in 8086 has a spcc:ial 1--bit indicotors. They arc :
W-bit : Some instructions of 8086 can operate on byte or a word. The W~bit in the
oprode of s uch instruction specify whether instruction is a byte instruction
(W = 0) or a word instruction (W = 1).
D-blt : TI1e O-bit in the opcode of the instruction indicates that the register specified
within the instruction is a source n..~ste r (D 0) or destination regis ter (D 1).
S-bit: : An 8-bit 2's complement number can be extended to a 16~bit 2's complement
number by mn.king all of the bits in the Wgher..order byte equal the most
significant bit in the low order byte. This is known as s ign extension.. The S--bit
along with the W-bit indicate :
5 w Operation
0 0 S.bfl operation
0 1 16-bit operation with 16-bit immed~te operand
1 0 -
1 1 16-bit operation with a sign extended 8-bit immediate operand
Table 3.9
V-bit : Vbit d-.'Cides the number of shifts for rotate and shift instructions. lf V = 0. then
count = 1; if V I, the count is in Cl register. For eXt"tmple, if V = 1 and CL = 2
th(''' shift or rota te in~truction shifts or rotates 2bits.
Z-blt : It i~ \tSt.>d for s tring: primitives :o:uch as REP for comparison with ZF Flag. If it is
I, the instruction with REP prefix is executed until th~ zero nag matcht.'S the
Zbil.
(Refer Appc1\dix A for instruction formats)
As seen fro~ the Fig. 3.28 if an instruction hn.<> two opcode/addn:..-ssing mode bytes,
then the second byte is of one of the following two forms :
I MOD Opoode
or
I MOD Reg
I
Copyrighted material
Microprocnaora ond Interfaci ng 3 103 8086 lnatructlon Set and ALP
where Mod, R4'g ond R/ M Aclds -pecify operand as dl-scrib<'<i ll\ the following tables.
Modo Otsplac:et~Mnl
11 1 01 1 I 1 BH
Copynghted matenal
Microprocessors and Interfacing 3 - 104 8086 Instruction Set and ALP
Solution : This instructjon will copy a word from the CX register to the AX register.
Refer-ring the table in Ap~ndix A we find the 6-bit opcodc for this in.~truction is 100010.
Because we are moving a word, W=1. The 0 bit for this instruction may be somewhat
confusi'S . Sinc~ two regi.o;tcrs M C involved, we can think of the move as eitMr to AX o r
from CX. It actually does not matter which we assume as long as we are consistent in
coding the rt.-'S t of the instruction. If we think of the instruction as moving a word to AX.
then moke D=l and put 000 in the REG Aeld to repr...,.,t the AX register. The MOD field
will be 11 to represent register addressing mode. We make the R/ M field 001 to represent
the othe r register CX. The rcsultont code for the instruction MQV AX, CX w ill be 10001011
11000001. The Fig 3.30 shows the meaning of all these bits.
I Byto1 I Byte2 I
I'iololol +1111t!ol+lol+l
~,
~
RIM CX
To REG
MOVword - - '
L REG =AX
I( we chang'-' D field. to a 0 and swap the codes in the REG and R/ M field, we will get
10001001 11001000, which is another equally valid code for the instruction.
Copyrighted material
Microprocessors and lnbtrfaclng 3-105 80861nstructlon Set and ALP
,,... Example 6 : Write l11e ;ustmt tiorr ftmnnt for MOV 56H(SI), BH
Solution : This instruction will copy a byte from the BH register to a memory location.
The BIU will compute the effective address of the memory location by adding the
indicated displacement of 56H to the contents of Sl register. The BIU then produ tM
physical address by adding the effective address with the base represented by H)bit
contents of OS register. The 6-bit opoode for this instruction is again 100010. We put Ill in
the REG field to represent the BH register. D = 0 because we are moving data from BH
register. W = 0 !><.'Cause we are moving a byte. The R/M field will be 100 because 51
contains part or the effective address.. The MOD field wiiJ be 01 because the displacement
cont-ained in the instruction_, 56H, wiiJ fit in J byte. The S.bit displacement forms the third
byte of the instruction. The resultant sequence of code bytes will be 10001000 01111100
01010110.
+
I+ 1o1 lol olol oll111 +lol + Iol 11 +I +
OPQOde latMOV~ =ISIJ
FromREG_ I L ~/M
~EG BH
Olsptaccmetll e: 56 H
II... E.xample 7 : Write tl1e ;nstruC'tfou fomrnt for MOV DL; {8X}.
Solution : This instruction will copy a byte to DL from the memory loctttion whose
effective address is contained in BX. The effective address will be added to the data
segmon t base in OS to produce tho physical address. Referring the table in Appendix A,
Copyrighted material
Microprocessors and Interfacing 3 -106 8086 Instruction Set and ALP
we find opcode for this instruction is 100010. We make 0 = 1 because data is being moved
to register OL. We make W = 0 bt..>cause the insln.lction is moving a bytl" into Dl. We put
010 in REG field t(l represent Dl. register. We make MOD field 00 to represent memory
with no displacement. For this instruction R/ M field will be 111. The resultant sequence of
rode bytes will be 100010 1000010111 .
I Byte 1 I Byte2 I
,,... Example 8 : Writ< the iustructio11 fommt for MOV BX, 11234 HI
Solution : This instn1ction copies thl" contents of two memory locations into the BX
regis ter. The direct address or displacement of the first memory location from the sta rt of
the data segment is 1234H. The BIU will produce the physical memory address by adding
this displacement to the data segment base represented by the 16-bit number in the OS
register.
The 6bit opcodc for this instruction is again 100010. We make D = 1 because we are
moving data to the BX register, and we make W = 1 because the data being moved is a
word. We put 011 in the REC field to reprcst.-nt the BX register. Referring tables 3.11 and
3.12 we get MOD = 00 and R/ M field = 110. Then the fi rst two bytes of instrucrion code
will be 10001011 0001 1110. Tiocse two bytes will be followed by the low byte of the d imct
address, 34H (00 1I 0100 binary), and the high byte of the d irect address, 12H (0001 0010
binary). n~ i nstruc~ion will be coded into four s ua:essive memory addresses as 8BH, I EH.
:WH and 12H.
D1rec1
Orract addross
lowetbyte
Direct address
H igher byte
addressing
Copyrighted material
Microprocessors and Interfacing 3-107 80361nstructlon Set and ALP
II... Example 9 : Write tire inslmction formnt for MOV CS : !BX}, CL.
Solution : This instruction copies a byte from the Cl register to a memory location. The
effective address for the memory location is contained in the BX register. Usually an
effective address in BX will be added to the data segment base in OS to produce the
physical memory address. ln this instruction, the CS in fron t of [BXJ indicates that we
want the BIU to add the effective address to the code segment base in CS to produce the
physical e1ddress. The CS : is called segment override prefix.
Whel\ an instruction containing a 5eb'Tnent override p refix is coded, an 8-bit code fo r
the segment override prefix is put in memory before the code for the instruction. The rode
byte fo r the segment override prefix has the format 001 XX 110. We can be replace XX
with : the segment code. The segment codes ore : ES = 00, CS =01. SS =10 and OS = II.
The s~men t override prefix byte for CS, then, i1:> 00101 11 0.
The opc<x:le for this instruction is 100010. 0 = 0 because we are moving data from the
CL register. W = 0 because we arc moving a byte. We put 001 in REG field to !\.>present
Cl reboister. We make MOD field 00 to represent memory with no displacement. For this
instruction R/ M field will be 111. The resultant sequence of code bytes will be 00101110
10001000 00001111.
Review Questions
1. xplsi11 vsrious datil addrt$sing m"'les of 8086 witl1lite help of t'Xt:Jnrples.
2. E.xpl.ni11 tht diffi.wn ~lfUtfll direct and iudir.t addrt':,-sing modt.
J. E.xplni.11 boS<plusil1dtx nddmsi11g mode.
4. xplsi11 lunu bast>-plus-iudt'x addressing mode am bt tr51'4 to loet:Jtt' array data.
5. E.xpl!lit1 rtgis.t.er rdnting nddre$$h!g.
6. Explain bast n'.tatiw-plus-indt'x addressing.
7. E.xpiJtin IJOW ba~ l't'lalit~plu~oind.u Nidmsbrg can bt usN to ltllt dAta from two dimensionAl
army.
8. fxplni11 tht> string addressing moM.
9. E.xplniu IKI,;OIJ$ 1/0 nddrt'SSing modes supportrtl by 8086.
Copyrighted material
Microprocessors and Interfaci ng 3 108 8086 Instruction Sot and ALP
Copyrighted material
Microprocessors and Interfacing 3-109 8086 Instruction Set and ALP
O QQ
Copyrighted material
(3 . 110)
(; y ned Male
Assembly Language Programs
In this chapter, we S4...lC the programs lnvolving logical, branch and caJI inslTuctions,
sorting, evaluation of arithmetic expressions and string manipulation. Most of the
programs usc DOS function calls. The details of DOS function caUs are given in chapter 9.
Copyrighted material
Microprocessors and lnterfacJng 42 Assembly Language Programs
Copyrighted material
MIC>Oprocnoors and Interfacing 4-3 Assembly Language Programs
tnitilliZt COunttt
Oecremen1 Counter
Copyrighted material
Microprocnsors and ~nterfllcing Aasembly Lln&U-u Programs
Copyrighted material
.
Microprocessors and Interfacing 4-5 Assembly Language Programs
Flowchar1 :
.MODEL SMALL
. STACK 100
. DATA
MS1 08 10 , 13 , 'ENTER THE NO.: $ '
MS2 DB 10,13, ' THE FACTORIAL IS S'
NUM ow 0
AN$ ow 0
.CODE
START : MOV DX, @data ; I Initialise
MOV OS, OX ; data seqrnent
ERROR : LEA DX, MSl
MOV AH,09H ; Display message MS1
! NT 21H
MOV AH,OlH ; I nput number with echo
!NT 21H
CMP AL, 30H ; It zero display I
JE DISPLY2
CMP AL,JOH ; I f ( 30 then input
Copyrighted material
Microprocessors and Interfacing 4-6 Assembly Language Programs
JB ERROR Next no
CMP AL, 39H If >39 then input
JA ERROR Next no
SUB AL, JOH ; Convert to HX
MOV AH , OOH
SUB SP, 0004H ; Space in stack for
PUSH AX , Factorial
CALL FACTO
ADD SP, 0002 ; After execution
POP AX ; Of facto space for
POP ox ; Result
NOV BX,OO!O ; Convert HEX to BCD
MOV CX,0006 ; Max input no is 9
BACK: DIV BX ; To get remainder
OR DX , OOJOH ; Conver t to ASCII
PUSH ox
XOR ox , ox ; Clear ox
LOOP BACK
L1\ OX , MS2 ; Output MS2
l10V AH , 09
INT 21H
MOV CX, 0006
DISPLYl : POP ox
t10V AM,02M Output factorial
INT 21M
LOOP DI SPLYl
JMP LAST
DISPLY2 : ~lOV AH, 09
LEA OX,M$2 Display factorial ot
INT 21 11 ze ro 1
MOV AH, 02H
MDV DL, 31M
INT 21H
LAST : MOV AH,4CH ; Terminate and
!NT 21M ; Exi t to DOS l
FACTO PROC
PUSHF
PUSH AX
PUSH ox
PUSH BP
NOV BP, SP ; Point BP at TOS
MOV AX, (BP + 10) ; Copy no from stack to
. CMP AX , OOOlH ; AX & if no not 1 then
; GO ON
JNE GO ON ; To compute fac torial
MOV WORD PTR(BP+l2) , 0001M
; Else l oad FFACT
MOV WORD PTR (6P+l4),0000H
; 0 and 1 in stack
JMP EXIT
Copyrighted material
MiCTOprocn oors and lhtei'foclng 4-7 Assembly Language Program
Copyrighted material
~
Set poin&er IO
End of the stri~
Pointer =Pointer -1
Count = Couot - 1
Copyrighted material
Itn vJ:
Mlcroprocesoors and Interfacing 49 Assembly l.itnguage Programs
Flowchart :
c.... )
l
/ Ge<lhe sblng /
l
Sec alphabet counter 0
$4tt numbof tounler 0
Set s0Eteia1CI'Waeter counter ... 0
l
I Count length of,. Stmg I
I
Set pointer to irs!
owa~er In the siting
J.
< "
CharacMr = H001bef
YH
I
I lnQ"emenl number COt.lnttr I
Is
"" Yes
< cnaracw = AJphabe
I
I No 1h::rement alphabet oo~er J
IS Yes
< Character = Special chcw'aelot
(lncromtnl special dlantt* coUnter(
No
l
1Pon.,. = Pointer .. t I
l
I Count Count t I e
J..
7
No
~ Display
Oi&:play number eountef'
alph~ counter
play apedal Character counter
I
If
( .... )
j_
Copyrighted material
Microprocessors and Interfaci ng 4 - 10 Assembly Language Programs
. HODEL SMAt.t.
.STACK 100
TITLE TOTAL
(THIS ~ROGRht1 GIVES THE TOTAl. NUMBERS, ALPHABETS, SPECIAL
; CHARACTERS I N THE GIVEN STRINGI
. DATA
sur DB 80 ; (MAX LENGTH OF ARRAY I
DB 00 ; (ACTUAL LENGTH OF ARRAY I
DB 80 DUP <01 ; (STARTING OF ARRAY}
STRl DB 10 , 13, 'ENTER THE STRING:$'
STR2 DB 10,13, 'TOTAL NO:$ '
STR3 DB 10 , 13 , 'TOTAL ALPHABETS:$'
STR4 DB 10,13, 'TOTAL SPECIAL CHAR:$ '
NUM DB 0
SPC DB 0
At. PH!\ DB 0
. CODE
START: AX,@data. Initialise
t10V
MOV DS,AX .
;
'
data segment
110V AH,09H
MOV OX, OFFSET STRl ; Address of STRl
INT 21H ; Display message STRl
t10V AH,OAH
110V DX,OFFSET BUf' ; Get address of the buffer
!NT 21H ; Input the string
MOV BX,OFFSET BUF ; Get address of the buffer
I NC BX ; I nCrement address of buffer
MOV DL, I BX) ; Get the length of string
INC BX ; Get the starting of array
NEXT: MOV AL, (BX) Read the character
CMP AL,30H Check for special character
JB INCSPC ; If yes qoto INCSPC
CMP AL, 3AH Check for number
JB INCNliM If number goto INCNUI1
CMP AL, 41H Check for special character
JB INCS PC I f yes goto INCSPC
CMP AL, 5BH Check for a lphabet
JB I NALP If yes goto INALP
CMP AL, 61H Check for special character
JB INCSPC I f yes goto INCSPC
CMP AL, 7BH .
Check for alphabet
JB I NALP ; If yes goto INALP
I NCSPC : MOV AL, SPC
ADO AL,OlH ; INCR special character
; counter and
OAA ; adjust it to decimal
MOV SPC,AL
INC BX ; Increment pointer to point
; the next character
Copyrighted material
Mlc:roprocenon ond lnt.rfaclng 4-11 Assembly Lang.._ Programs
Copyrighted material
Mi~roprocessors and Interfacing 4 - 12 Assembly Language Programs
Copyrighted material
MICtOprocessors and Interfaci ng 4-13 Assembly Language Programs
DEC OI
SAR CL, l
MOV SI,OOH
BACK: MOV AL, {BX + Oi l ; Get the riqht most character
HOV AH, {BX + SI I ; Get the left most character
CMP AL,AH ; Check for palindrome
JNZ LAST ; If not exit
DEC DI ; Decrement end pointer
INC SI ; Increment starting pointer
DEC CL ; Decrement counter
JNZ 3ACK ; If count not 0 , repeat
#
Copyrighted material
Microprocessors and Interfacing 4 14 Assembly Language Programs
MOV CL, BUFF+ I ; Take character count in CX
LEA BX , BUFF+2
MOV OI , OOH
BAC.:K MOV DL, {BX+OI) point to the first cha r acter
ADD OL, 20H convert to lowercase
MOV AH, 02H
!NT 2 1H Display the character
INC or
DEC ex Dec rement character counter
JNZ BACK ; If not 0 , repeat
MOV AH,4CH ; [ Terminate and
!NT 21H ; Exit to DOS )
END START
Start
lnitialle counter
array pointer and sum = 0
Stop
Copyrighled malerial
MlctOprocesoors and Interfacing 4 15 Auembly Langua~ Program
Algorithm :
l . Initialize counter N
2. Initialize array pointer.
3. Sum 0
4. Get the a rray element pointed by array pointer.
5. Add array clement in the sum.
6. Increment array pointer decrement counter.
7. R~at steps 4, S and 6 until counter equal to zero.
8. Display sum.
9. Stop.
Copyrighted material
M~811d lnterfllclng 4-11 Auembly U.ngu-se Prognms
RET
1 ENDP
I END
Copyrighted material
Mlcroproceaora encllnwrfllclng 4-17 Aanmbly Lenguege PYognoma
1\RRI\Y DB 12 , 24 , 26, 63 , 25 , 86 , 20, 33, 10 , 35
SUM IY" 0
MES DB 10 , 13, ' Sum of array elements is $ .
.CODE
S TART : MOV AX, @data. ( Initialise
MOV DS,AX data seqrr.ent
MOV CL, 10 Initialise counter
XOR Dl , DI Initiali$e pointer
LEA BX, .~RRAY Initialise array base pointer
91\C : MOV AL, IBX+DII Get the number
MOV AH, OOH ; Make higher byte OOh
ADD SUM, AX ; SUM = SUM + number
INC DI ; Increment pointer
DEC CL ; Decrement counter
JNZ BAC ; if not 0 90 to back
MOV AX , SUM ; Get. the result
CALL ATB40 ; Display sum of array
MOV AH, 4CH
INT 21H
Copyrighted material
Mlcroproceaaora and lnt-clng 4-18 Aaaambly Language Programa
OISP ' POP ox get rema i nder
ADD DL, 30H Convert to ASCII
!NT 21H display digit
LOOP DISP
RET
ENDP
END
I
Copyrighted material
MlcroprocesOO<S and lnterfaclng 4 19 Assembly Language Programs
Flowchart :
Start
Initialize counter
Initialize SOU'ce block pointer
lni1iali2e destination block pointer
No
. STACK 100
DA.TA
ARRAY DB 12H , 2 3H,26 H,63 H,25H, 86H,2FH , 33H, l0H , 35H
NEW ARR DB 10 DUP (?)
.CODE
START : >'.OV AX ,@data ; ( Initialise
!',OV OS, AX ; data segment and
>'.OV ES,AX ; e xtra seqment 1
MOV ex, 10 Ini t i a lise co\lnter
LEA SI,ARRAY I nitial ise s ou.rce_pointer
Copyrighted material
Microprocessors and Interfacing 4. 20 Assembly Language Programs
ENDP
Microprocessors and Interlacing 4. 21 Assembly Language Programs
We caU two blocb are overlapped when some portion of source and destination
blocks are common. As shown in the Fig. 4.1. source and destination blocks can be
overlapped in two ways. In first case Fig. 4.1 (a) we can begin transfer from starting
location of source block to the s tarting location of destination block, i.e.
(20000H( <- (20005H)
2000EH . - - - - - - - , end
IDe=~..,1- - i ~-
'' '
20000H .. ......................' stan 20000 H ' -- - - - ' stan
(a) (b)
Fig. 4 .1
We can then increment source and destination block pointers and carry on byte
transfer until the pointers reach the end of two blocks, i.e. upto
(20009H) <- (2000EH].
In second case Fig. 4.1 (b) we cannot use the same block transfer procedure, because
there will be over writing of data within the source block, i.e. a t first byte transfer contents
of 2(XK)()H will be over writh..~ in the location 2000SH and data at 2000SH in the source
block get lost. To avoid over writing in such cases we have to transfer data from source
block to destination block from the end of the block, i.e. we have to begin with the
Copyrighted material
Microprocessors and lnt.rfacJng 4-22 Assembly Language Programs
transfer I2000EH) .-. 120009Hj, decrement the source and dct>tination pointers and carry on
the byte transier untiJ the pointct reach the start of the blocks, i.e. upto
I20005HI+- I20000H)
PAGE 52 , 80
TITLE Overlapped block transfer .
MODEL SMALL
STACK 100
. D~.T.,
AAR!>.Y DB, 12H , 23H , 26H , 63H , 25H ,86K, 2FH, 33H, l0H, 35H , ? , ? , ? , ? , ?
.coos
START : MOV AX , @data ; ( Initialise
MOV DS , AX ; data segment and
MOV ES , AX ; extra segment J
MOV CX , IO ; Initialise counter
LEA SI. ARAAY+9 ; Inic.ialise source_pointcr
LEA Dl,ARRAY+l4 ; !ni tial ise destination_pointer
STD ; SET direction flag to
autodecrement SI and or
MOV AL, [$!) ; Get the number
MOV I 01) ' AL and save number in new array
REP MOVSB ; Decrement e x and f.jOVSB until
Cx will be 0
Copyrighted material
Mieroproeeasora and lnl erfac1ng 4 . 23 Assembly Language Programs
PUSH CX
I~ I CL, 04H ; Load r ot..s-:.e eour.t
H, o;.H ; !.oad d!.g 1 t ccunt
BI.C : 110~ AX , CL ; r-ota-::e d i'9~ta
~ Aid30 to
ADO AL , 3'?H ; i ts
JMP Ol.;P ; ASCII
Aod)O : AO~ AL , 30fl i eqi.iiva'ent)
O!SP : tV AH . 02H
:v Dl . AI
It ~ II nu:nber}
i'l.)f AX restorr- C'""ntenta of .\X
E<; '"H ; oecre~e>nt dtg:.lt cour.t
J'Z : 1 f nc-:: :eco repeat
POP
PET
" ~f
!NT 21H
POP c.x rest o re regieter:s
POP AX
RET ; r t1.n:n t o ll'8ln proq r am
!lOP
EfJt'
Program 12: Write 8086 ALP to find and count negative numbers from
the array of signed numbers stored In memory.
In sign number n.oprt.osent.ltion.. number is C4llled negati\'e when it! most s1gnificant bit
(MSB) L< l. Thi< bit can be ch<'<:ked by masking all other biL with tl><: help ol logical AND
instruction.
Mlcroproc<~ssoro and Interfacing 4. 24 AsMmbly Language Programs
Algorithm : '
t . Initialize counte r.
2. Initialize array pointer.
3. Initialize negative number count.
4. Get the number.
5. Check sign of number by checking its MSB. If negative increment negative number
count and display the number.
6. Decrement counter and increment array pointer.
7. Repeat steps 4. 5 and 6 until count.,. equal to zero.
8. Display negative number count.
9. Stop.
Flowchart
Yeo
Display number
No
No
Oisptay ~tive
nu-count
Copyrighted material
Mlctoprocessors and Interfacing 4-25 Assembly ~~~guage Programs
PAGE 52 ,80
TITLE Find and count the negative numbers in the array .
. MODEL SMALL
. STACK 100
.DATA
ARRAY DB 92H , 23H , 96H,OA3H,25H, 86H , 2FH , 33H,l0H,35H
MES DB 10, 1 3 , 'Negativ e nu.mbers are $'
M51 DB 10 , 13 , 'Total Negative number count is s.
. CODE
MOll AX, @data ; ( initialise
~1011 OS, AX ; data segment
MOll ex, 10 ; Init.l.alise counter
t"'OV BH, O ; Initialise negative number count
equal to 0
LF.:A BP, ARRAY ; Initi alise array base_pointer
LEA OX , MES
11011 AH; 09H
!NT 21H
MOll AL, OS ' [BPI ; Get the number
11011 AH , AL ; Save number in AH
AND AL, 80H ; Mask all bits e xcept l1SB
JZ NEXT ; If MSB 0 go to next
CALL O_HEX2 ; Othenfise display number
CALL SPACE
INC BH Increment negat.ive number count
NEXT INC BP ; Increment array base_pointar
LOOP BACK ; Decrement counter
; if not 0 qo to back
LEA OX, MES l
MOll AH , 09H
!NT 21H
MOll AH , 02H
ADD BH , 30H
MDV DL,BH
!NT 21H
MOll AH , 4CH ; Exit
INT 21H ; to DOS
Copyrighted material
Mlcroproe9ssors and Interfacing 4-26 Aseembly Language Programs
END
In this program we use the standard routines explained in the chapter 3 to convert
data from one form to other. However, to ~lect the conversion we di!iplay menu on the
Kreen and display proper messages on the scre...--n to guide user. Therefore. in this
program separate macro named PROMPT is written for display the message. After
accepting the option from the user, the option is checked and proper routine is called to
perform desired operation.
Algorithm :
1
Oisplav menu
a. HEX To BCD
b. BCD To HEX
c. EXJT
ENTER THE CHOICE :
2. Read Ule option
It option is ~x i t
Display menu
1. HEX to BCD
2.. BCOtoHEX
3. EXIT
React opCioo
Yes
Yos
CAI.L HT8
Yes
CAI.L BTH
Copyrighted material
Mlcroprocenors and Interfacing 428 Anembly Language Programs
Copyrighted material
Microprocessors and Interfacing 4-29 Asoembly Language Programo
PROMPT MES7
CALL R HEX
PROMPT MESS
CALL D BCD
RET
ENDP
Copyrighted material
Microprocessors and Interfacing 4-30 Assembly Language Programs
Copynghted matenal
MlcroPfOCeaaotS 111<1 lnart.c:lng 4. 31 Aseembly Lang..-ge Program
END
Flowchart :
( Sian )
-- I l
I Read multiplicand I Decrement iteration
counle<
J
( Read multiplier
I "
Coun t-= 1
No
Make result = 0
Iteration count = 8
I
Rotate multiplier
an d check currenl
MSB of multiplier
Yes H
M$8 1
I
I Add multiplicand in the resun J
No
I
Copyrighted material
Microprocessors and lntarfaclng 4-34 Assembly Language Prog....,.
PROMPT >1ES1
CALL REAO HEX2
HOV MUL_AND, BL
PROMPT MES2
CALL REAO HEX2
MDV MUL_ER, BL
MDV DH , OO
MDV DL, MUL_AND
MOV cx,oooa
MDV AX , OOOO
REP1 : SHL AX,l
ROL BL, 1
JIJC SKIP
ADD AX, OX
SKIP : LOOP REP1
PROMPT ME$3
CALL D HEX
>JOV AH,02H
MOV OL, ' H'
INT 21H
MOV AH , 4CH ; !Exit to
INT 21H ; DOS)
Copyrighted material
Mlcroproceaao111 and Interfacing 4-35 Assembly Language Programs
Copyrighted material
Microprocessors and Interfacing 4 36 -'*mbly Language Prognoms
DEC CH decre ment digi t count
JNZ BACI ; if not zero repeat
RET
ENDP
END
Muttlplication of BCD numbers
PROMPT MACRO NESSAGE: ; Define macro with MESSAGE as a parameter
PUSH AX
MOV AH , C9H
LEA ox, r~ESSAGE
!NT 21H
POP AX
ENDM
PROMPT MESl
CALL llTH
MDV MUL_ANO, AL
PROMPT r<52
CALL BTH
r10v MUL_ER, AL
fo!OV BL, AL
Copyrighted material
Mlcroprocosson and Interfacing 4-37 Assembly Language Programs
MOV OH , OO
MOV DL, MUL_ AND
MOV cx.ooos
MOV AX , OOOO
REP!: SHL AX , l
ROL BL,l
JNC SKIP I
ADD AX, OX
SKI PI : LOOP REP!
PROMPT M8S3
CALL D BCD
Copyrighted material
Microprocessors and Interfacing 4 . 38 Assembly Language Programs
SND
PROMPT HSI
CA~~ ATB
PROMPT MES2
CA~L 8TH
MOV DIVISOR, AL
MOV BX,AX
PROMPT ME$3
MOV AH, 00
CALL D_BCD
PROMPT 1'.53
MOV AH, OO
MOV AL, BH
CALL D BCD
-
MOV AH , 4CH ; (Exit t o
I NT 21H ; DOSJ
'
PUSH BX
r~ov CXi
. 0 .
Clear
~..
cligi~. coUnter-
.
MOV BX, 10 ; Load 10 decimal . in ..BX
~KI : MOV OX, 0 ; Clear OX 'it'I ,
DIV BX ; d i vide ox : x AX by 10
fOSH OX ; save r~ma.i:nder t
INC ex ; Counter : remainder
... ... .:;
OR AX, AX ; te$t if quotient equal to 'zer:o "'
JNZ BACKl I if not 2.erp di_-vide a_q ain
MOV J\H, 02H .
load fun <;;i9D ~ numb~ ;r
DISP : I'P ox .
q:et r emainder '
ADO OL, 30H ; Convert to ASCI I
INT aH ; display digit
LOOP OISP /
I'OP BX
RT
ENDP
ijACK :
~IOV
MOV
~lOV
ex.
BX,
AH , OlH
10
0
l oad10 decimal ln ex
clear r esult
; [Read
- '
key
!NT 21H I wi th echo)
C~lP AL., 0 '
EIID
PROMPT MESl
MOV AX , NUMBER
SUB AX , 20H ; Subtract 32
MOV NUMBER, AX
t-10V BX,05
MOV CX , 09
MUL BX ; Multiply by 5
DIV ex ; Divide by 9
Copyrighted material
Mlcroproceooora and lnt.rfaclng 4 43
,-
~.'Ito
--
..: ....
MOV ; clear diqit , c;Oiu i.ter
Load 1 0 de<;.l:ma 1
., .
Clea..c DX .. ~
'
i
AX, ,. AX lc f:
BACKl ;" .it )'lO:t zero
"' ~'
t' '
MOV J\lj, 02H ~ ;
DfS.I' : P.OP Ox " -
30H
~.'
; Save
with echo1
'
lf
,.
jUmp if' above 9'
.
. '
cOnvert t'O ~!'- .
; save tligl ~ .
1
..
lri~itip>y .pt1!V~~ result by 10
"
qet the resulj; _in BX i f .,
;. r~ t,r4.eve %<,J dfg1 t ' '
r
.
'4'
Copyrighted material
Microprocessors and Interfacing 4 44 Assembly Language Programs
ADC BX, AX : Add d!qit value to result
.JMF 8ACII : Rep~at
SKIP: HOV t~UMBER1 B.X save tbe- re3U 1t in lWMBr:R
POP AX
POP sx
POP ex
RET
Ellll.P
END
d . Cht.>ck p,1Jindrome.
c.-. Exit.
Here we usc PROMPT macro to display the mess.1ge on the screen, accept choice from
the u...er and call _proper prvcedure to perform desired tolsk. To enter a string we use
function OAH of INT2!. This function accepts a string and stores it in tl\e buffer along
with its length. Let us see the algorithm and flow chart.
II
Microprocessors and Interfacing Anembly Langu- Programs
Algorithm :
1. Display Menu
a. Enter the string.
b. Calculate length of the string.
c. Reverse the string.
d . Check whether the string is palindrome or not.
-. Exit.
Enter the option : -
2. Read the option
If option is
a. Read the string.
b. Read the string length and display it.
c. Initialize pointer at the end of the string and display the string from end to
start.
d. i) lnitializ.e two pointers one at s tart and other at the end.
ii) Compare two bytes; if not t..:.qual s top and display string is not palindrome.
ii.i) Increment start pointer and decrement end pointer.
iv) Repeat s tep ii) and iii) until two pointers overlap i.e. until sta_rt pointer
reach the half the string.
e. Exit to DOS.
3. Stop.
Copyrighted material
Microprocessors and Interfacing 4. 46 Assembly Language Programs
Flowchart :
Read option
I
Yes
Check palindrome
No
OispJ.ay meuage
enter OOtre<:l option
Stop
Copyrighted material
Mlcroproc:esoors ond lnt.rfaclng 4. 47 Aoumbly Language Progroms
Set poln1er 10
End ot me $1r1ng
POinter Poln'ler - 1
Count Count - 1
No
I
lnltlallze pointer at
the end of the string
I
J1nitia1ite counter= lcngMI
Compare charaetets
pointed by two strings
Are
characters
No
equal
I Oecremenl oounter I
Yos
No
1,.
oountet = 0 Display message
sbing is not palindrome
Tves
OISf)l&y meuage
string is palindrome
I
( St<>p)
Copyrighted material
Mlcroproceaaors and Interfacing 4 48 Assembly unguage Programs
PRO~lPT ~lliCRO
PUSH
MESSAGE : Define macro with MESSAGE as
AX ; save AX register
parameter
t~OV AH, 091! ; disp lay message
LEA ox, ~!ES SAGE
!NT 21H
POP AX ; restore AX re9ister
NOM
. DA"l'JI. .
start data segment
MESl DB 10 , 13, 'L ENTER THE STRING s .
MES2 DB 10, 13 , 2' CALCULATE THE LENGTH OF STRING $ '
MES3 DB 10, 13 . 3 . REVERSE THE STRING s.
H.ES4 DB 10, 13 . q PALINDROME $ '
><ESS DB 10, 13 . 5 . EXIT $.
MES6 DB 10 . 13. 'ENTER THE CHOICE : $.
MES7 DB 10, 13. 'ENTER CORRECT CHOICE : $.
MESS DB 10, 13 , $.
MES9 DB 10, 13, ' FAILED : STRING IS MISSING - PLEASE
ENTER THE STRING$'
~1ESI 0 DB 10, l3, ' STRING LENGTH IN DECHlliL IS $'
MESll DB 10 . 13, ' STRING IS NOT PALINDROME $.
MESI2 DB 10 , 13, ' STRING IS PALINDROME $.
fLAG DB 0
MES13 DB 10, 13, ' ENTER THE STRING : $'
>IES14 DB 10 , 13 , ' THE STRING IS : $ '
BUfF DB 80
DB 0
DB 80 DUP(O)
COUNTER! ow 0
COUNTER2 ow 0
Copyrighted material
lollcroprocen ors and Interfacing 4-49 Anembly Language Programs
Copyrighted material
Microprocessors and Interfacing 4-50 Assembly Langug Programs
Copyrighted material
Mlc:roproceaaora and l nt.rfllc:lng ... 51 Assembly Langu- Programs
Copyrighted material
Microprocessors and l ntarfltc:l ng . 452 Assembly Language Programs
Write 8086 ALP to perfonn string manipulation. The strings to be accepted from the
user L' to be stored in code segment Module_! and write FAR PROCEDURES in code
St..:.gment Mlxiule_2 fo r following operations on the string.
a. Concntenation of lw o strings.
b. Compare two strings.
c. Number of occurrences of a sub-string in the given string.
d. Find number of wo rd~, characters and apitaJ letters from the given text in the
data St."'gment
i'
Copyrighted material
Mlcroprocenora and Interfacing Anembly Langu19e Prog,.ms
Note : Use PUliLIC and EXTERN directive. Create . QB) files of both the modules and
link them to create an EXE file. Command : Tlink Ml.OB) M2.0BJ
In this experiment we have to write two . asm programs one for accepting strings and
one for procedures.
Algorithm : Module_1
1. OispJar Menu
a. Enter the strings.
b. C.oncatcnation of two strings.
<:. Compare two strings.
d. Find number of occurrences of a substring.
e. Find words, characters and capital letters.
f. Exit.
2. Read option
It's option is
1. Read two strings.
2. Concatenate two strings.
3. Compare two strings.
4. Find number of occurrences of a substring.
5. Find words, characters and capital letlers.
6. Exit.
3. Stop
M1 : String operations
PROMPT MACRO 1<1ESSAGE ; Define macro '.iith t1SSAG as a parameter
'PUSH AX save registers
PUSH ox
MOV
LEA
AH,
OX,
09H
MESSAGE
d isplay message
. ..
..
!NT 21H
POP OX restore registers
POP AX
ENOM
Copyrighted material
Mlcroproc:nsors and I..Wrfaclng
FLAG 08 0
MES14 DB 10, 13 , ' ENTER THE STRING : S '
MES15 OB 10, 13, ' THE STRING IS : S '
BUFF! oB so
DB 0
DB 80 OUP(0)
BUFF2 DB 80
oB o
DB 80 DUP!Ot
BOFF3 DB SO
DB 0
DB SO DUP (0)
. CODE ; start. code segment
Copyrighted material
Mlcroprocouorsnd l~ng <1 55 Assembly~ Proarw
Copyrighted material
Microprocessors and Interfacing 4. 56
END
Copyrighted material
Microprocessors and Interfacing 4. 57 Assembly Language Programs
.STACK 100
. DATA
EXTRN BUFFl : BYT
EXTRN BUFF2 : BYTE
EXTRN BUFF3 : BYTE
MESS1 DB 10 , 13, 'STRINGS .~ RE
SAME $ '
MESS2 DB 10 , 13 , 'STRINGS ARE NOT SAMES'
MESS3 DB 10 , 13, 'NUMBER OF ALPHABETS TN THE STRING
ARE:$'
MESS4 DB 10 , 13 , ' NUMBER OF CAP!T~. L LETTERS IN THE STRING
ARE:$'
HESS5 DB 10,13 , ' NUiiBER OF WORDS I N TH STRING AR : S'
M556 DB 10 , 13 , ' NUMBER OF OCCURRENCES OF SUBSTRING IN
T HE STRING IIR : S'
l'ifLAG DB 0
ACOUNT DB 0
CCOUNT DB 0
WCOUNT 0~ 1
C ADDR Dl~ ? current address of pointer
E_ ADDR Dt< ? End address of string
. CODE
-
CON STR PROC FAR
CLO
MOV CH, 00 ; copy string l
NOV CL , BUfF l+l
LEA SI, BUFE'l +2
LEA DI, BUFF3+2
REPZ MOVSB
Copyrighted material
Microprocessors and Interfacing 458 Assembly Langu- Prognoms
LEA SI , BUFF2+2
REPZ HOVSB
Copyrighted material
Microprocessors and Interfacing 4. 59 Assembly Language Programs
RE: RET
COM_ STR ENDP
MOV BL, 00
LEA SI , BUFF!+~
Copyrighted material
Mic~oooro and Interfaci ng 4-60 Assembly Language Prog111ma
MOV CH, 00
HOV CL, BUFFl +1
LEA SI , BUFF1+2
BB : MOV AL, (SI) ; check of space
CMP AL, '
J NZ NNEXT
MOV AL , WFLAG if space occur s increment word count
CMP AL, 0
JZ LLAST
MOV WFLAG, 0
INC WCOUNT
JMP LLAST
NNEXT: MOV WFLAG, 1
; . IF AL > ' A. && At < I z I
Copyrighted material
4-61 Asaombly Lllnguage Prog..ms
CALL DIS_ HEX
MOV ACOUNT, 0
MOV CCOUNT, 0
MOV WCOVIIT. I
RT
fWCC_ STR ENDP
MODEL SMALL
. STACK 100
.DATA
ARRAY DB 10 , 53H, 20H, 30H, 25H , 50H, 09H, 10H, 13H, 90H, OOH
MES 1 DB 10 , 13 , 'I. SORT ARRAY IN THE ASCENDING ORDER $'
PROMPT MES 1
PROMPT MS2
PROMPT MES3
PROMPT MES4
Copyrighted material
Mlaoprocesoon nd -clng -4 - 63 ...._,y Lan{IU8118 p.._,
STl: HOV AH,OlH
!NT 21H
SKIP! : INC DI
DEC CH
JNZ BACK!
DEC CL
JNZ 8881
Copyrighted material
MlctOproeessors and Interfacing 4-64 Auembly Ulnguage Programs
PROMPT MESS
MOV CH, OO
MOV CL, ARRAY
LEA DI , ARRAY
INC DI
AGl ' INC DI
MOV AL, (OI (
CALL D HEX2 ; Display sorted a rray
PUSH AX
PUSH t,,;
t-10V AH,02H
MOV DL,
!NT 21H
POP ox
POP AX
LOOP AGl
RET
ENOP
SKIP ' I NC DI
DEC CH
JNZ BACK
DEC CL
JNZ BBB
Copyrighted material
Mlcropi'OCeDOI'S and lntarfacing 465 Assembly LAnguage Programs ..
PROMPT M$5
MDV CH, OO
MDV CL,ARRAY
LEA OI ,ARRAY
I NC OI
AG: INC OI
MOV AL, [Oil
CALL () HEX2 Display sorted array
PUSH AX
PUSH OX
MOV AH, 02H
~IOV OL,
INT 21 H
POP OX
POP AX
LOOP AG
RET
ENDP
Copyrighted material
Microprocessors and Interfacing 4 111 AsHmbly Langwoge Programs
DISP: MOV AH , 02H
MDV DL,AL ; (Displ ay the
!NT 21H ; number)
PDP AX ; restore contents of AX
DEC CH : decrement digi t count
JNZ BAC ; if not zero repea t
PDP ex
RET
ENOl-
END
Copyrighted material
Microprocessors al\d lnteffaclng 4 -67 AoMmbly lianguege Programs
JMP LAST
NEXT : MOV ADDR, OI ; save rel ative address of the
; byte from the starting
; l ocation of the stri ng
LAST : MOV AH, 4CH ; ( Terminate and
!NT 21H ; exit to DOS I
END START
Copyrighted material
Microprocessors and Interfacing 4. 68 Ass embly Language Progrems
20 + 15 = I Remainder 5 i.e. - 0
15 + 5 = 3 Remainder 0
HCF = 5
.model small
. stack 100
.data
CR EQU 0AH
LF EQU ODH
MES 1
MES 2- DB
DB
CR,LF, 'ENTER 4-0IGIT FIRST HEX NO ', CR, LF, '$ '
CR,LF, 'ENTER 4-0IGIT SECOND HEX NO ' ,CR,LF, ' $ '
MES 3 DB CR,LF, 'INPUT IS INVALID BCD S'
MES_4 DB CR,LF, ' THE HCF IS : $'
MULTI DW 1,10,100 ,1000
RESULT ow (00)
DIVISOR ow (00)
DIVIDEND ow (00)
INPl DB OS
DB 00
DB 05 DUP (O)
INP2 DB 05
DB 00
DB 05 DUP(O)
.code
MAIN: MOV AX,@data ; Initia lise
MOV OS,AX ; data segment
MOV AH,09H Di spl ay
MOV DX,OFFSET MES_l ME$ 1
!NT 21H on video screen
LEA OX, INPl ; Get the
MOV AH,OAH Firsc
Copyrighted material
Microprocessors and Interfacing 469 A...mbly Lllnguqe Piogt111
!NT 21H ; HEX number
MOV AH, 09H ; Display
MOV OX,OffSET MES 2 ; MES 2
!NT 21H ; on video screen l
LEA OX, INP2 ; (Get the
MOV AH,"OAH ; Second
!NT 21H ; HEX number
MOV CH, 02H ; Initialize buffer counter
LEA BX , INPl ; Get the address of buffer
AGAIN : INC BX ; ( Ad j ust buffer
INC BX ; pointer )
XOR OI , OI ; Clear pointer
~!OV CL, 04 ; Initialize counter for digits
BACK : MOV AL, [BX+OI) ; Get the digit from buffer
CMP AL,39H [ Convert
JG NEXT the ASCII
SUB AL,30H code of
JMP SKIP the actual number
NEXT : SUB AL,37H and store it in the same
SKI P : t<!QV ( SX+OI),AL position l
INC DI Increment pointer
DEC CL Decrement diqit counter
JNZ BACK If not zero qoto BACK
LEA BX, INP2 Point to second buffe r
DEC CH Decrement buffer coun ter
JNZ AGAIN ; 1f not zero go to AGAIN
MOV CL, 4 ; In itia li ze r otation counter
LEA BX, INPl ; Po1nt to first buffer
INC BX ; (Adjust buffer
INC BX ; pointer 1
MOV AH, [BX+O) ; [Forms the
SAL AH , CL ; packed BCD
AND AH , OfOH ; Hiqher
MOV AL, [BX+ l) ; Byte J
OR AH, AL
MOV AL, (8X+2 ) : (Forms the
SAL AL, CL ; packed BCD
AND AL, OFOH ; LOwer
MOV OH, (BX+3) ; byte )
OR AL. OH
r1ov RESULT, AX : Save packed wor d as a RESULT
MOV CL, 4 ; Initialize rotation counter
LEA BX, INP2 ; Point to second buffer
INC BX : ( Adjust buffer
I NC BX pointer l
MOV AH , (BX+O) ; (Forms t.he
SAL AH,CL : packed BCD
AND AH, OFOH ; Hi9her
MOV AL, (BX+l) ; byte)
OR AH, AL
MOV AL, (8X+2) ; I forms the
Copyrighted material
_,,Mj~~~~ '"~ lntorf~cing Assembly Language Programs
There is a one more method to find LCM of two number if HCF is known. We can
find L.CM a:o: (cdlows :
11l i~
progr.tm accepts two four digil numbers from keyboard, finds HCF ftrst and
us ing above equ.:.tion it then finds LCM ol the hvo numbers.
Copyrighted material
I
M lcroproceuora and Interfacing 4 . 71
.model small
.stac k 100
.dlU.a
CR &OU OAH
LF EOU ODII
~s
M5_2- I 08
08
CR,Lf,'ENTER 4-0IGIT FIRST HEX NO' , CR,LF, ' S'
CR, LF,' Et-iTER 4 - DIGIT SECOND HEX NO' , CR, LF, '$'
MES .3 DB CR, LF, ' INPu:' IS INVALID BCD $ '
HES 4 DB CR, LF, ''THE HCF IS : $ '
HVLT! OW 1, 10 , 100 , 1000
RESULT D'rl {00)
DIVISOR ow {00)
DIVIDEND OW {00 )
INPl DB 05
DB 00
DB 05 DUP(O)
INP2 DB 05
DB 00
DB 05 DUPIOI
. code
MJ.tN: HOV 1\X,@data ;
HOV OS, AX : dat aeqment. J
HOV AH, 09H ; ( Display
HOV OX, OFFSET O<ES_ l l!o'.!S_l
!NT 2 1H on v1deo screen J
LEA OX , I NPI I Get the
MOV AH, OAH First
!NT 21H HEX number
MOV AH , 09H Display
MOV OX, OFFSET MES 2 ~ es 2
!NT 21H on video screen J
LEA OX, 1NP2 [ Get the
HOV AH, OAH Second
!NT 21M ; HEX number
HOV CH,02H : Initialize butter counte r
LEA BX, INPl : Get the butter pointer
AGAIN: INC BX .
( Ad)USt buff er
INC BX : pointer )
XOR 01,01 ; Clear pointer
HOV CL,04 ; Initi Uze counter fo r digits
BACK: HOV AL, (BX+DI] : Get the di9it ft om bu ffe r
CHP AL,39H : ( Convert
JG N&XT ; the ASCII
Copynghted materio1l
MlcroproceMora and Interfacing 4-72 Asoembly Language Programs
Copyrighted material
Microprocessors and lnterfllclng 4-73
Copyrighted material
Microprocessors and Interfacing 4,. 74 Assembly Language Programs
ADD AH , JOH
J MP NEXTJ
SKIPJ: ADD AH , J7H
NEXT3 : MOV OL, AH
NOV AH, 02H
INT 2 1H
MOV AX,BX
AND AL, OFOH
SAR AL, CL
CMP AL, 09H
JNC SKIP4
ADD AL,30H
JMP NEXT4
SKI P4: ADD AL, 37H
NEXT4: MOV OL ,AL
MOV AH,02H
! NT 21 H
MOV AX,BX
AND AL, OFH
CHP A.L,09H
JNC SKIP5
ADD AL , 30H
JHP NEXT5
SKI P5 : ADD AL,37 H
NEXT5 : MOV OL,AL
MOV AH, 02H
!NT 21H
MOV AH, 4CH ( Terminate and
!NT 21H Exi t to DOS I
END MAIN
END
DOD
Copyrighted material
8086 System Configuration
5.1 Introduction
Unlike 8085. 8086 and 8088 can be operated in two modes : Minimum mode and
Maximum mode. ln this chapter we study the topics rcl~ted to Minimum mode and
Maximum mode operation of 8086. Topics include clock generation, bus buffering, bus
latching. timings. minimum mode operation <~nd maximum mode operation. let us begin
w ith signal description of 8086.
(5 1)
Copyrighted material
Microprocessors and Interfacing 5-2 8086 System Configuration
...,
,..... .....,
(Mift
00<0
..."". 2
O
",. ...
vee
......"""..
3
A.,fS,
,." ....... ...... 3
,.
31
A.,tJSl
......
14. 111S,
...
5
, .. ....... .....
,. "''A
....., ...,
As, S$o !HIGH)
" ' "
"" " t.tN..iii
. 33 . ..;;x
.....,
-
(M>n (Mn
...
loD,
'oo .... "
"
Ri)
RQIG'io ()tOlD)
...... 10 "
"
Ri)
.....
HOW <R016Tot
...
CPU
loD, II 30
,. RCW'io t><L""> II """ ,.
30 cHOtGT,,
.., ",,
..
<OCK
s,
l~ih
..,.., ,,.." ,.
;;;;; (LOCK)
loD,
""
..
(J4i:i)
tDTifi)
,, ""'
OT~
,." 00<
<$,1
(il )
...""'
AD,
"
"
"
" 00,
t6ENI
(ALE)
(iifTAJ
.......
17
,. ....
,. .;:;n
<S,i
t<>O,I
(0$,1
INTR
17
18 "
23
OS,
TEST INTR
23 TUT
CLK
ONO
19
20 ,," Rt;ADY
RESET
CUt
GHO ,." ,," REAOV
RESET
Fig. 5.1
0 0 es
0 1 ss
1 0 CS or none
1 1 OS
55 gives the current setting of the interrupt flag (IF) and 56 is always zero.
3. BHEIS7 : BHE (Bus High Enable) : Low on this pin during firs! part of the
machine cycle~ indicates that at least one byte of the current transfer is to be made
Copyrighted material
Microprocessors and Interfacing 5-3 8086 System Configuration
on higher order byte ADwAD~ othen..,ise the transfer is made on lower order byte
AD,.-AD..
BHE Ao Data acceaa.H
0 0 Word
0 1 Upper byte from Odd addrH*
1 1 None
Status S, is output during the later part of the machine cycle, but, presently, S, has
not been as..\igned a meaning.
4. NMI : It is a p05itive edge triggered nonmaskablc interrupt request.
5. INTR : ft is a level triggered maskable interrupt request. It js sampled during the
last dock cycle of each instruction to determine if the processor should enter into
an interrupt scrvke routine.
6. CLK : 8086 requires clock signal (with 33 % duty cycle) from some external, crystal
controlled generator to synchronize internal oper01tions. Clock frequency depends
on the version of 8086.
.
Procusor Required clock signal
80~ 5MHZ
8086-2 8MHZ
80861 10 MHZ
7. RESET : lt dears PSW, lP, OS, SS, ES, and the instruction queue. It then sets CS to
FFFFH. This signal must be high for at least 4 clock cycles. 1'\lh<."' RFSET is
removed, 8086 will fetch its next ir'lstruction fronl physical address FFFFOH.
8. READY : lf this signal is low the 8086 enters into wait stt~te . This signal is used
primarily to synchronize slower peripherals with the microprocessor.
9. TEST !Input) : This signal is only used by the WAIT instruction. The 8086 enters
into a wait state after exect1tio n of the WAIT instruction until a LOW signill on the
TEST pin. TEST signal is synchror,i7Ald inte n,nlly durh\g C('~ Ch dock cyde on the
leading edge of the dock cycle.
10. RD (Output) : RD ls low whenever the 8086 is reading data from memory or an
T/ 0 device.
11. MN / MX Clnput) : The 8086 can be configured in either rrummum mode or
maximum mode ushlg this pin. This pin is lied high for minimum mode.
Copyrighted material
Microprocessors and Interfacing 5-4 8086 System Configuration
DEN (Data Enable) Output : This s ignal in(onns the transceivers that the CPU is ready
to SC1'd or receive data.
OT/R (Data transmit/Receive) Output : 1'his signal is used to control data Oow
direction. High on this pin indica tes that the 8086 is tro1nsmitting the data and low
indic<ttt..-,. that the 8086 is receiving the data.
MilO Output : It is used to distinguish memory dotn transfer, (M / 10 G HIGH) and 1/0
dam transfer (M/10 = LOW).
WR : Write Output : WR is low whenever the 8086 is writing data into memory or an
l/0 device.
HOLD input, HLOA Output : A HIGH on HOLD pin indicates that another master
(DMA) is requesting to take ovN the system bus. On receiving HOLD s ignal p rocessor
outputs HLDA signal HlCH as an acknowledgment. At the same tim(', pnxC'SSOr tristates
the system bus. A low on HOLD givt.>s the system bus control back to the processor.
ProcesSt')r then outputs low signal on HLDA.
1 0 Queue is empty
I 1 1 Subsequent byte of an opc:ode
I
I 2. 5 2 , 5 1, 5 0 (output) : These three status s ignals indicate the type of transfer to be
take place d uring the current bus cycle.
II
I
Copyrighted material
Microprocessors and Interfacing 5 5 8086 System Configuration
s, s, s, Machine cycle
-s. -s, -s, Maehlne cycle
Co 1Q edIT' ale a
Microprocessors and Interlacing 5 -6 8086 System Configuration
FFFFFH
FFfFOH
"
~.
0
1
Fl'FFEH} -
FfFFCH
I
I
Ft:f:rnH 0
FFFF9H FFFFN<}
FfFF8H l $ byiH
FFFF7H 0
FfFF6H Declicfltecl
FFFFSK FfFF.tH
FFFF3H FfFF1H
FFFF1 H 0 FFFFOH
0
0
0
0
003FFH OO>FH
OC13F[)Oj 0 OOOFCH
0
0
0
0
ooomo
000100i 0
0
0
0001EH}
000700
........
128
1
b'Jies
0001510
000131"1
0
0
00014H
00011 H 00012t<
OOOUIH }
0
0000010
0
"""""""'
00000H
Odd Bat*
0
Evtn Bet*
"""""
OOOOOH
Copyrighted material
Mlcroprocenora end lnterfaci"ll 5 7 8086 Syotem Configuration
FFFFSH are dedicated to the initiali'!ation procedure of the 8086, while locations FFFF6H to
FFFFBH arc dedicated to the initialiMtion prcxedure of the 8089 input/output processor.
Locations OOOOOH to 00013H are dedicahld to store the v~tor addresses of the dedicated
interrupts. The dedicated locations are used for processing of specific system initialis.1tion,
inte_rrupt and reset hmction.
Intel has also reserved several locations for future hardware and software products.
Locations from OOOJ4H to 0007FH and locations from FFFFCH to FFFFFH are reserved
IOL"ations. nw locntions from OOOOOH to 003FFH are u.o;.ed for interrupt vector table (1V1).
The interrupt ve<:tor t:.ble provides the starting location/address of the interrupt service
routh\12' fo r the interrupt s upported by 8086. The detail description of interrupt vector table
i$ given i.n sections 8.2 and 8.3.
7 0
FFFFH
FFFEH
OOFFH 64K
OOFEH liO space
Reserved
OOF8H
PagoO
OOF7H "'
0001H
OOOOH
1 - l
t==:::j
Fig. 5.4 l/0 map for 8086
Copyrighted material
Microprocessors and Interfacing 58 8086 System Configuration
1/0 ports arc addr6Scd in the same manner as memory locations. Even addressed
bytes are transferrt:'d on the D;-00 bus lines and odd addressed bytes on Dw 0 8. Care
must be taken to assure that e~ch res:bt~r w ithin an 8-bit peripheral located on the lower
portion of tht- bus be addressed as tven. In the 1/0 space. Intel has reserved OOF8H to
OOFP locations.
ALE STB
Adctress
A00 Lotch bus
AOro,"- ~ (2)
Data
~ 1 ransoetver bus
(2)
DEN
-OE
OT/R T
Copyrighted material 1
Ml<:roproc:esso~ a.rid lnterflclog 8088 Syitem Configuration
Each WAIT s tate is of the :1<1 mc durarion"" n clock cycle. During a WAIT s tate, the signals
on the bus..'S remain the s.1mc as thl'Y were at the start of the WAIT state. (( the Ready
input is made high during wait s tate, then ofter WAIT state the 8086 wiU go on with the
regular T, of tlw! machioo cycle. Howll"cr, if the 8086 Ready input is still low at the end of
a WAIT state, then the 8066 will inseft another WAIT state. The 8086 will continue
insefting WAIT states until the Ready input is made high again.
TN! status bib S,. S1 and S, arc uJ<d, in ma.>dmum mode, by the bus controller to
identify the type of bus transaction according to tho table given below.
-s, -s, -s,
--
s, Mochlne cyclo s, s. lbd\lne cyclo
0 0 0 ........,. "'*""""<'g I 0 0
-
0 1 0 IIOWo'lt I I 0 Memory Wl'ke
0 1 1 I 1 I ~PassiYe
Status bib S, through S. are multipl<!xed with high-onder address bib and the BHE
signal. Tl1ese bib are also demultlplexed using latch and the ALE signal during T 1
Therefore, the status bits S, through S. arc valid during T2 through T4 Status bits S, and
S, indicate which segment register was used lor this bus cycle in forming the address,
aceo<ding to the following Table.
s, s, Char-otico
0 0 AJ-ooe OliO (t><lnl _ . )
0 I SIOck
I 0 Cod<> 01 None
I I Oata
Out of rcmai.nJ.ng stat\ts bit'l, S, ~ a rcOcclion o lhc Interrupt enable bit o the flag
register, $6 is always 0 and S, is a Spt'IN StatuS bit.
If a systom is large enough to "''''<!
dllta bus buffers, then the 8086 OT/R signal
connech.d tn ~~~ bufferS wUI 8Ct lhcm for in~during a read operation or set them for
output durong o -write op<rotion. The I1Ql6 DEN slgnol will enable the buffers at the
appropriat< time in the m.'lchlne cycle, "" hown In the Fig. 5.6.
Co 1Q edIT' ale a
Microprocessors an~ Interfacing 5 - 10 8086 System Configuratton
r - -Momo<y .... cycle- r - - - -Momo<ywrite cycle -j
I r, I r, I r, p,.,l r, I r, I r, I r, p,.,l r, I
CLK
Goes inactive in the &tate
just priQt to T4
=;'..___.~~~.tlhWJ'//JhWJ~
ALE
AOORI
;;j \
STATUS
Ready
orlfi
Copyrighted material
Microprocessors and Interfacing 5 -11
''".6 t"
11086 'System Configuration
ro~ Vee
I
.
+Vee \
'--
CO.K """'-"' .
.
R 8284A ALE STB
Clod< READY 8H
8Hf
-
82112
-Generator 1\ESET ...,
c
I-
RES
"r't6
> Address
Iateil
(3)
-
;>sus
ss
AD, ..."o OE
-----I
1 " -v
~
'
WAIT
I STATE
I 8086 CPU
I GENE.AATOR I
.r... . ta
L----I 8288
Transceiver ;>~
-DEN (lit (2)
DTIR T
8282
''
..
Data Bus
interfaces then to increase current
sourcing/sinking C(lpaciti4."S it is
t
AD,
2
.,,
A.D. necessary to use drivers and
""'
oo;
A,
OE
8
6
= rcceive:rs (t'r ansceiver) for data bus
also. The Intel 8286 device is used to
DTIR T implement the transceive r block
... .. -
81H16 shown in Fig. 5.7 The 8286 contah'S
.,, 16 tristate elements, eight recl'ivers,
.,,.
ADo
.,.. .,.. =
and eight drivers. Therefore two
8286s are n.~ui red to service 16 data
.,,
A011
.,,
.,,.
1
.....,"" .... ==-.
a
2
a
} Data Bus
lines of 8086 . Fig. 5.9 shows the
detailed col'moctions of 8286.
-
-
AD, 6
oe
T
"' DT/ R signal is connected to the
T input, which controls the direction
of the data flow. When this signal is
..J
' low, receivers are t.'flabled, so that
Fig . 5:11 Connection details of 11286 8086 can read data from memory or
input device. To write data into
memory or output device, the 8086's DT/R signal goes high. Due to this drivers are
enabled to transfer data from 8086 to the memo!l.. or the output device. At the thne of
data trnnsfer, to enable output of transceiver its OE should be low. This is acromplisht.od
by connecting DEN signal of 8086 to the OE pin.of 8286, since DEN signal goes low when
CPU is ready to send or receive d:.ta.
;If.
Clock genenotor
.
The third comeonent, other than the processor that appears in Fig. 5.7 is an 8284 clock
generator. The 8284 clock generator does the following functions :
Clock generation
RESET synChronb..ation
. Jl
READY synchronization
Peripheral clock generation.
The Fig~ 5. ro'sl\'ows the internal logic diagram of 8284.
The top half of 'the logic diagram represents the clock and reset synchronization section
of the 8284 clock generator. As shown in the logic diagram, the crystal oscillator has two
inputs : x ; and x,. If a cryStal is atladled to x, and x, the oscillator generates a
square-wove signal at the same frequency u the crys'tal The output of oocilioto )s fed to
an _!>NO gate and also to an inverter buffer that provides the oscillator output sognal The
F/C signal selects one of the osciUator inputs. When F/C input is 1, the EFI input
Copyrighted material
Microprocessors. and lnletfacing 5 13 8084! System CQnfiguratio~
[}:>
R'ES
x,
0
CLK
0
I - RSET
XTAL
x, Oscilt.a!Ot
. osc
FJC
,..._ , -
J 3 .
SYNC SYNC
2
I
- PCU<
EFI ~
CSYNC
ROY 1
I I
AEN 1 -{:::
v .' CLK
J
ROY0
AEN
2
1'-
v
I ~
._ 0
CLK
FFI
a ::n- o
CU<
FF2
a - READY
ASYNC
[=L >
Fig. 5.10 The internal logic diagram of 8284 .
determines the frequency; otherwise oscillator determines the frequency. When EFI input is
used, CSYNC signal is u.""<' for multiple processo~ system synchronitation. If the internal
crystal oscillator is used, CSYNC signal is grounded. In both the cases the output clock
frequency is one third of the input frequency. llje CLK signal is also buffered before it
leaves the clock generator. As shown in tM Fig. 5.10, the output of the divide~by3 counter
generates the timing for ready synchronization, a signal for another couriter (divide-by-2),
and the CLK signal to the 8086/8088 microprooessors. The two ~ caScaded counters
(div ide--by.J and dividc--by2) provide the di vide~by--6 output at PCLK, which c.-.n be used
to provide clock input for peripherals. The address enable pins, J).EN 1 and AEN2 are
provided tu qualify the bus ready signals, R()Y 1 and ROY,, respectively.
The reset circuit of 8284 consists of a schmitt trigger buffer and' a' sing.lc D nipCiop
circuit The D flip-flop ensures that the timing n.'quirements of the 8086/8088 RESET input
are met. This circuit applies the RESET signal to the microprocessor.o.n. the negative edge
(1 to 0 transition) of each clock. The 8086/8088 microprocessors ~~ljlpl e RESET at the
positive edge (0 to 1 transition) of the docks; therefore, this drcuit meets the timing
requiremonts of the 8086/8088. ' .,
j.
Copyrighted material
Mle~nora and)nllltfaclng 5 14 8086 Syatem Configuration
The Fig. 5.11 shows the drcuit connection for 8284 clock generator. The RC circuit
provides a logic 0 to the RES input pin when power is first applied to the system. After a
short time, the RES lnput becomes a logic 1 because the capacitor charges toward + 5.0 V
through the regL<ter. A push button switch a llows the microprocessor to be reset by the
operator.
nmf-
x, X,
- EFI
F/ C RESET
a.K CU<
RESET
10t<i
-
>
8284
Clock Qeneqtor
8086
or
8086
w
' ~
RES
I :o,,F
. PCU< f--
ROY 1 ROY:
1 1
Fig. 5.-11 Interfacing of 8284 clock genenotor with 8086 or 8086
Other signals e
The statt1s on the M/10, RD, and WR lines decides the type of data transfer, as listed
in the Table 5.!.
MilO RD -WR Ope..Uon
0 0 1 110 read
0 1 0 110-
1 0 1 MonlOiy read
1 1 0 Mtmoty write
Table 5.1
HOLD and HLDA signals a re used to interface other bus masters like DMA controller.
Interrupt request (INTR) and interrupt acknowledge (INTA) are used to extend the
interrupt handling capacity of the 8086 with the help of interrupt controller.
Copyrighted material
1 tos 21e..
Mleroproceaaors and Interfacing 5 15 8088 System Configuration
5.6.2 Minimum Mode 8086 System
"
The Fig. 5.12 shows the typical minimum mode 8086 system. , He!'\', interfacing of
memory and 1/0 d evices arc shown with the ba.liic minimum mode 8086 configuration.
~hll ~~ fi d'J
of- ~
.h
I
>
~
~
I f
.rJ !
I
,.
Lr-
~ ~ ~
I (
.u
~
;>-'"
~
I ~
.
-!I w
~
,:
b
~ I
~
~I ~
,... - ,.
~-
~
.
----
EIS li : I
. '
'
: ~1!1"'
&
'
4 -
>ij1 ! II II
I II
ii l i
'j
.
'In lilt ~ ~ }11 ~~ I 'if-
dfJ
I ~ v .~.J
..
'
lf.....'if .
~ ~
{
1
!l :f n(
H
.
.
I ':~'
IJ r
,, .
Copyrighted material
Microprocessors and lnte~lng 5 - 16 8086. SY)Sl..., c;:onflguratlon
For interfacing memory module to 8086~ it is necessary to have odd ' and ,e;ven memory
banks. Tilis is implemented by uslng two EPROMs and two RAMs. Data lines 0 150 8 arc
connected to odd bank of EPROM and RAM, and data lines D,.-00 are connected to even
bank of EPROM and RAM. Address lines are connected to EPROM and RAM as per their
capacities. RD signal is connected to the output enable (OE) s ignals of EPROMs and
RAMs. WR signal is connected to WR signal of RAMs. Two separate decoders are used to
generate chip select signals for memory and 1/0 devices. These chip select signals are
logically ORed with either BHE .or A, to generate final chip select signals. For generating
final chip select s ignals for odd bank decoder outpuiS are logically ORed with BHE signal.
On the otl'ler hand to generate fin.1l chip select signals for even bank decoder outputs are
logically ORed with A0 signal.
The 16-bit 1/ 0 interface is s hown in the Fig. 5.12. RD and WR signals are connected to
the RD and WR signal~ of 1/0 device. Oatn lines 0 15-00 arc connected to the data lines of
1/0 device. The chip select signal for 1/0 device is generated using separate decoder
whose output is enabled on1y when M/10 signal is low.
'
5.6.3 Bus Timings lor Minimum Mode
RD
Copyrighted material
~!c;(pp~~rs.ancllnterfaclng 5-17 808fl System C<!nflguratlon
10
AD -AD
0
------<<.-.s.ou~.._~;;;o;ata:-:o:ur=:r--""'>
:--- TDVWl-1
A L E - - -- . /
_,X..__ __;;.LOW
MilO _ _ .;__
_IIO.;_WR
_IT.;;;
E;..H
_IGH
.;__
_M"'EMORY
....;.._,R
w;-_ITE
....;...._.,x..___
WR --------!--- ~~------
TWLWH
OT/R
.. - - -.....
...............
..... ...
Fig. 5.13 (b) OU1pU1 (write operation)
These are explained in steps.
1. When processor is ready to initiate the bus cycle, it applies a pulse to ALE during
T1 Before the falling edge of ALE. the address, BHE, M/10, DEN and DT/R must
be stable i.e. DEN = high and DT/R 0 for input or DT / R a 1 lor outpul
2. At the trailing edge of ALE, ICs 74LS373 or 8282 latches the address.
3. During T2 the address signals are disabled and S,S, arc available on
AD 16/S,AD,. /S6 and BHE/S,. Also DEN is lowered to enable transceiver.
4. In case of input operation, RD is activated during T2 and A00 to A0 15 go in high
impedance preparing for input.
5. If memory or 1/ 0 interface can perform the transfer immediately; there a~ no wait
states and data is output on the bus during T3.
6. After the data is accepted by the processor, RO is raised high at the beginning of
T,.
7. Upon detecting this transition during T,, the memory or 1/0 device will disable its
data signals.
8. for an output operation, processor applies WR = 0 and then the data on the data
bus during T,.
9. InT., WR is raised high and data signals are disabled. \.
Copyrighted material
Hidden page
Micropr.oc:.n 10n1 and Interfacing 5- 19 8081 System Conflgur811on
- - ..
v.,., [ ~ [ I
...... _...,
LOCM.8USES
CLOCK
. . . . . .tOR
CU<
,._
I, .. CL'
r-
Mlll5l!
r-
iiWiC
- """" r-
i, i,
::;m
..,
liD
r- ..,.
-
i, J,
OTM
iQWC
:o;owc
f- oo
r-
r- .... r-
ii1A
iOi5< - H.c.
""'
tlA1'1
.,"""""'
GHO
'- ...
ill
"
Ao.,IIO,$
~ ....., 'r
.... -
AOIt.o.J.TA
. "''
'-"""
C:tOU)
"'
Fig. 5.15 Typ ical maximum mode conftguration
I
~
I If there is no
STB
"""'"'
.,.,. (3)
a25&A. !his il
~~ I 8fl i'IYet*
I ';:1 .r oe Tran~
828612)
r T
CLK ALE
CEN DEN
5V Control
IOMI
AEN
oOB
Con'""
l ogic f= Signal
Generator
OTIR
MCEIP""'DEH
8011 '
BUS i,i;oC
"_;:.
ro;:::er IIWTC
$!)
... Command
s-gnal
;c;;;c
ii5WC
s,
Status
Decode<
Generator ;;:;;;;.:
s,
iNiA
Po1011ty lniO<nlj)t
conb'oller8259A
.
~
13
}it
~
;
'.
Ill
~~~
I I
Ill
I (
}H
I
il
~.~I
1!1
~
~I
}If
1!1
IU~ IP
,- :; ui
.., ...... n~ 13
::a"'
as~
. 18
~~a
I
,
i "" . . .. i"
~
i 71
j}ll
,..-,: ,..~ .
di
I I
u
LJ:t t
r
a..d. i t-- i~
.r
L.... wli 8
,s
Copyrighted material
Mlcroproc:eaors and Interfacing 5 - 22 8086 System Conflguratl~
- - --.,.'----_-_-_-..;:...!:..&1.........-_-_-_-_-_-_-_,-;-r--s:,. -.live
~s.~,- -~-..:: :::
r
- ..~.,. : ---!c'k_:,.-""1::.....,x;.=='-s,...,...,.s-,--- --..> F~oe~
BHe, A1 gA16
ANOBHEIS1 - - - - - - - -
!
! ~--.. cDataiND11~-0o
.......,.......- - - - -l<:< A,.... ) >------;.::<_ I >-----
(AD,AOoJ TAVOV - ---i
1
" ALE - - - -. /
!--TRLOV -i
"MRDC ----------~ :
ortORC
" DT~ ----- ,;------
Copyrighted material
Hidden page
Hidden page
Microproc:easort and Interfaci ng 5 -25
8 bit
Example 2 : If memory has 8192 memory locations, then it has 13 addn.>ss lines.
The Table 5.2 summarizes the memory capacily and addrus lines Nquired for memory
interlacing.
Table 5.2
As shown in the Fig. 5.20 (a) memory chip has 11 addl'l'S5 lines Ao-A 1., """chip sclect
(CS), and two control lines, read (~ to enable output buffer and write (WR) to '""'blc the
input bufk>r. TI>e intcrnol decoder is used to doox!e the add"'"" li~... Fig. 5.20 (b) shows
the logic diagram of a typical EPROM (Erasable Programmable Read-Only Memory) with
4096 (4 K) registe,... It has 12 address lines A0-A 11, one chip select (~, ono Read control
signal. Since EPRO M i.s a rc{ld only memory. it does not require the (\VR) sign.1l.
Lopynghted materio~l
Hidden page
Microprocessors and Interfacing 5. 27 8086:'9Ystem Configuration
memory interface with absolute decoding. Two 8 K EPROMs (2764) a~ used to provide
even and odd memory banks. Control signals BHE and Ao are used to enable outputs of
odd and even memory banks respectively. As each memory chip has . 8 K memory
locations. thirteen address lines are required to address each locations~ independently. All
rc.-maining address lines are used to generate an unique chip select 1signal. This addressing
tedutique is normally used in large memory systems.
2) Linear Decoding :
In small systems, hardware for the decoding logic can be elif!linated by using only
required number of addressing lines (not all). Other lines are simply ignored. This
technique is referred as line.ar decoding or partial decoding. Pig 5.22 shows the addressing
of 16 K RAM (6264) with linear decoding. Control signals BHE and Ao are used to enable
odd and even memory banks, respectively. The address line A19 is used to select the RAM
chips. When A1t is low, chip is selected, otherwise it is d isabled. The status of A 14 to A18
does not affect the chip selection logic. This gives you multiple addresses (shadow
addresses). This technique reduces the cost of decoding circuit, but it has drawback of
multiple addresses.
DATA
BUS
o,. .L).o. o,.L).o.
07 DO Do o,
A, LA A, A,~ A,
A;-" ... A;-" Ao 1 ~
RAM
RD :-)
./
LRO
RO RAM
6264
SHE
~ HWR
- (8K)
IA&i. i.WR
'
' (8 K)
WR WR WR - ViR
./ ./
Cs Cs
A" .
Copyrighted material
Microprocessors and lniiHfaclng 5 28 8086.Syatem Con~
... ~
o,, ll Ot .. .. o,5 {}o, ..u ..
... ....
D
:::; .....
0,0, 0,0,
""" I ~ ...... ....... I~ . =:: ...
3 "" ...,
r.-/ ii;li
~
,..
~
,,..
......
..., ;o;o
5E ...... (Rlj .........
--q y... '""
151
~"
Of
""'
~ iiR ~ w;;
a a a a
....,- A
r
Yeo
v,
~
EPROt.ICS
.... - e 1
~
A" - ,...___
'
-
G, >
.f 0~
lS
~
~
~AAMCS
3_ }- 0 . 9 NO
_._
Fig. 5.23 Block decoding
,..., Example 1 : Ot":'i~...,, au 8086 based system tuitll tilt> jollutuing sptcificntious.
i) 8086 iu miuimwn modt.
iil 6-1 KByte EPROM
iiiJ WI KHyk RAI\rl
Drtrw lite complete :;clttmntic of tilt' desigu iudicating addrtSS map.
Solution : The 8066 L a 16 bit microprocessor. It can access 16 bit data simultaneously.
hr inh'rfacin14 nu. non mudule to 8086 CPU, it ls ''ecessary to have odd and even
mem ory ban~. This Cr.'m be achieved by using two 32 Kbyt~ EPROMs and two 32 byte
RAMs, one for odd bank and anothe r for even bank.
As 32 Kbytc RAM and EPROM need 15 address lines, A 1 to A15 lines are used. A, and
BHE a rc used to select even and odd memory banks respectively. Fig. 5.24 shows the
intt-rf,:~~. !'IWt.'' '" ~lRl .1nd lwo nll'mory chips.
Copyrighted material
Vee
J
""""' I
..it~
74LS373(2)
.,.
""" r-
leu< ~
7A
T
.....
-
AlE
--
7"LS138
Vee
f
o,
o,, I
.&
. Ro A
D G,
E
c
MEMR
MEM\ii
w.
..00
c 0
D
R ""
OW I uo
CU< Reset Ready
o, o, . ::!
I I I .... OE o8-o,& A, -A,$ Of 0,0, A,-A,s 0E o,.o,5 ~A,, WR OE 0.,~ A1~$ WR
O.OCK 17256 (EMOt.4) 27256 (EPAOM) 62256 {J\AM) 6:2256 (RAM}
?vee
"'""
I ~
......
Cs Cs Cs Cs
~ ....- L ~ A
Vee o G,
E
c
A1. - A ~ .
T
D
D ,..._ ,..._ .- i
A., - C ~
H ~
c
q,
v,
R
I -1>- AO -L>- -L>- ., -L>- "' '
-r-
iiiiE o; GNOv, .
74lS313
.. f
0 L....;r74LS138 . I '
0
"0
'<
~
<0'
j
::r
~
3
Fig. 5.24 Interfacing 64 K RAM and 64 K EPROM with 8086 In minimum mode
i
*"'
"'
Mlcropr~essors and Interfacing 5 . 30 8086 System Configuration
Memory Map :
0
.. Acklress
0 FO<lOOti
Memory
EYO<l
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 FFFFFH EPROM1
0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 F0001H Odd
0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 FFFFHH EPROM2
1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30000H Even
1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 3FFFEH RAM1
, , 0 1 30001H
0
0
0
0
0
0
0
0 , 1 , 0, 0
1
0
1
0
1
0 0 0 0 0 0
1 1 1 1 1 1
0
1
0
1
0
1 1 3FFFFH
Odd
RAM2
,,.. Example 2 : Design an 8086 based system witll tile fa/tawing specifirotians.
, 0
.. A, At At ... A, AJ At .. AddrHS
FOOOOH
Address
Even
1
1
1
1
1
1
I
1 1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0 0
1 1
0
1
0
1
0 0 0 0
1 1 0 , FFFFEH EPROM1
1 , , FOOOIH Odd
0
0 1
1
1 1
1
1
0
1
0
1
0
1
0
1 ,
0 0 0
1 1 , 0,
0 0 0
1 1
0
1
0
1
0 0
1 1 1 FFFFFH EPROM2
-o 0 0 0 0 0 e...
1
1
0
0
0
0
1
1 ,
I 0
1
0
1 1
0
1
0
1 ,
0 0
1
0
1 1 1
0
1 , 0
1
0
1 1 0
30<lOOti
3FFFEH RAM1
0 0 0 0 0
0
0
0
0
0
0
1
1
1
1
0
I
0
1
0
1
0
1
0
1
0
1
0
1
0
1 1 1 , 1
0 0
1 1 1 ,
1 30001H
3FFFFH
Odd
RAM2
Copyrighted material
!I:
n~
0
"
MN/Mx
11- '"'"~"'"'''~ l
.. ..~
0
"""
Do r- T )
... Ii
"o
r- -
c
L.!!..
TRANSCEIVER
.... .. Q.
- r- CU<
ot.ii
oao
MRDC
T (i o,
i.iiDC
li~
!l
loll
"'
I,
i, t.... ~
;u;;;;c
iOiii!
iOwi!
iiNTc
:;;;;;we
iOiiC
;owe
-...
CU( Reset R..oy AiOWC AiOWC
...
-- --
I ':"
I I
......
ClOCK
I
"""""""'
f Vco;
OE o..o,,
212'!111 Cf~j
~
A,..A" 0 Do.O, A1--A1~
mso(fl'IIC)WJ
cs
Oi GrOts
cs
A'"''' Wit oe 1
a
At""ts Wft
-
I ,,..... I ..... Vee o G,
...,_ . i--
..... - l ~A ~
J---r
0
0
--t?.f-
Ate
.. ~ I-< H
f- C
-
E Y7
v,
.<o-L>- ...J.>- "o ~ >-- i..
ru3n G2 Gte>
0
~~~- . 1 n
~c:
0
-o
'<
~
Fig. 5.25 Interfacing 64 K RAM and 64 K EPROM with 8086 In maximum mode
-
<3
~
3
t
~
"""
Ol
Hidden page
Micr oprocessors ,a nd Interfacing 5 - 33 8086 System Configuration
clear input, CLR, of the shift register. The outputs of the shift register will then all be low.
One of th~ lows will be coupled through a jumper (jumper 4 in the Fig. 5.26), wiU cause
the RDYI input of the 8284 to be pulled low. However, WAIT states will not be inserted
unless ROY! remruns low long enough. Now, when RD. WR. or INTA goes low in the
machine cycle, the CLR input of the 74t.S164 shift register will go hjgh_ and th(> shift
register will function normally. The highs on the INA and INB inputs will be loaded on to
the Q A outp\lt on the next positive edge of the clock. lf the \.YAJT s tate jumper is ln the fo
position., then this high on the Q A output will cause the RDYl input of the 8284 to go
high again. For this Ctl.SC, the ROYJ input gOL"S high soon enough that no W AJT states are
inserted.
The high lood-.."'<1 into the 74L5164 shift rcgist('r is shifted one stage to the right by ('ach
successive dock pulse. When the high reaches tht> jumper connected to the RDY1 input, it
will cau::.e the RDY1 input of the 8284 to go high, as shown in the Fig. 5.27. n ,e 808b will
then exit (rom a WAJT st:~te on the next dock pulse. The number o( WAIT stales il\scrtcd
in a r11.achine cycle is determined by how many s tates the high has to be shifted before it
reaches the insta11ed jumper.
ern ~,
'
o. ~~----~vr--~:----~--+---~----------
o. ~~--------":; :
~ ~~--------~vr-+--~------
oo ~'---------------lJvr'-t-------
o.
(RDY 1) ___2:~---------------------"
READY
Fig. 5.27 Timing diagram for wait state generator
Review Questions
l. Explain ll~: fm~etioll offo/IMl.Jin,r{ pins in S086.
-- ---
il NMI ii) MN/MX iii) TEST
--
iu) BHE vi OT/R vi! DEN vii! QS(}"QS,.
2. EJ.plai11 11~ mnxlmum mode s-ig11nl$ f1/ 8086.
J. EJ:pl11itt lilt mhtlmum modt slgn11ls 8()86.
4. Wilh tl1t' lklp of b/()(k diagram explain memory iutrrfocing WitiJ 8086 mrd e.rplnin rl.llly two bus
cycle'S art> ri'qr.tirM to ltC4'SS odd mldrffS iLI()rd ?
5. DmtU mtd r:rplni11 tiN' nh"1t10ty mnp for 8086.
Copyrighted matenai
Microprocessors and Interfacing 8086 System Configuration
6. E.xplairl lllt 1/0 rtddrming copabilitit-5 of 8086.
7. Drnw and n:plnin 1111" 1/0 mnp of 8086.
S. Explain tllt grruml bus op~rnlion of 8086 ruWr the lld.p of timing diagram.
- -
9. E.xp/1;,, th ,mrpose of RMdy, OE..N nnd DT/R sigtutls.
lO. Witlr llw lttP of block sclkmatic diagmms ~xplnin tlr~ optndion of 8284 dock g~11trator ttnd 8286
transaivcr.
11. Sketclr block diagram sJunvilrg bask 8086 minimum mode sysltm. E.xplain ftmctions of 8282 /ntcll!t'S
(md 8286 lrtmsrrivtr.
12. O.:fint be~s ryde, nnd ~xpltrbr tire minimum nrodt- rmd n11d writt- bus cycle wilh proper Uming
diagram.
13. Explnin Ill( HOLD rt'5ponse ~UI'11U in tlr~ minimum mode of 8086 witlr lht lretp of timing
dingrnm.
14. Dmw and exploiu a block diagram showirfg 8086 in mn.ximum nwdt cotifiguraliQn.
15. Drnrv and (:tp/nin llrl" timing dingmm.s of brp1d and 011tput trtmsfrrs of 8086 in nruinrum mcxk
16. IndicaJe tilt signals wllich art dif/c!n!fll wlum 8086 iu minimum mode 1md in mtJ:rimum mcde.
17. Explain the operation of bus rrqurslaud b11s gmnt Sif1ull wWr the l~tlp of liming dingmm.
18. Explain tlw ftmction of wait stntt gm~rntor.
19. D ..osign the u\'.lit state gt~ltTiltor to in$Ul ~1it stntes from uro to set'Cn.
QQQ
Copyrighted material
6
Direct Memory Access
(DMA) - 8237/8257
&ni!ializ:e counter
Initialize &OtKCe pointer
-
microprocessor system.
r--1
ADo -AD,s
.... -
--""'~ -
-
"""" " ' lO
~
HRO
HI.OA
Copyrighted material
6 -3 Direct Memc.ry Acceu (DMA)-1237111257
Copyrighted material
-
Microprocessors and Interfacing 8-4 Direct Memory Access (DMA) - 8237/8257
5. It has priority logic that re:soJvt"S the peripherals requests. The priority logic c:an be
programmed. to work in two modes, either in fixed mode or rotating priority
mode.
6. It provides inhibit logic which can be used to inhibit individual channels.
1. It allows data transfer in two modes : burst mode and cycle steal (single byte
transfer) mode.
8. It can execute three DMA cycles : DMA read, DMA write and DMA verify.
9. Auto load featur. of 8257 p<lnnits repeat block o r block chaining operations.
10. It operates in two modes : slave and master.
11. When DMA is in master mode, AEN signal provided by 8257 allows to isolate
CPU buffe rs~ latches and other devices from the system bus.
12. Extended write mode of 8257 prevents the unneccssa;ry occurrence of wait states in
the 8257, increasing the system throughput.
13. It op.<rates on single TIL clock and it is completely TIL compatible.
14. lt can be interfaced with all Intel microprocessor.
15. H transfers one byte of data in four doc.k cydes. Thus giving high transfer rate
s uch as 500 Kbytes/second at 2
MHz dock input.
16. Like 8085, 8257 alw has READY
.,
input which allows 8257 to interface
slower memory or l/ 0 devices that
can .,ot mt.>el bus setup f:'>les
required by the 8257.
REAOY ....
TC
Copyrighted material
Microprocessors and Inte rfacing 6-5 Direct Memory Access (DMA) 823718257
Address Bus (Ao-A3 and A4-A 7) : The four leasl significanl tines Ao-A3 are
bi - directional tri - state signals. In the idle cycle they are inputs and used by the CPU to
address the register to be loaded or read. In the active cycle they output the lower 4 bits
of the address for DMA operation. A4 A 7 are unidirectional lines, provide 4bits of address
during OMA service.
Address Strobe (ADSTB) : This signal is used to demultiplex higher byte address and
data using external latch.
Address Enable (AEN) : This active high signal enables the 8-bit latch containing the
upper 8-address bits onto the system address bus. AEN can also be used to disable other
system bus d rivers during DMA transfers.
Memory Read and Memory Wrtt, ( MEMR, MEMW ) :
These are active low tri-state signals. The MEMR signal used to access data from the
add res._~ memory location during a OMA read or memory-to-memory transfer and
MEMW signal is lLc;cd to write data to the addressed memory location d uring DMA write
or memory to mentory transfer.
VO Re ad and 110 Wrlte ( lOR AND iOW ) : These are active low bi-directional s ignals.
In idle cycle, these are an input control signals used by CPU to read/ write the control
regis tcrs. In the active cyc-le lOR s ignal is used to access data from a periphera l and lOW
signal is used to send data to the peripheral.
Chip Select (CS) : This is an active low input, used to select the 8257 as an 1/0 device
during the idle cyde. This allows CPU to communicate with 8257.
Reset : This active high s ignal dears the command, s tatus, request and temporary
registers. [t also dears the first/last flip-flop tt.nd sets the Mastc.r Register. After reset the
device is in the idle cyde.
Ready : This input is used to extend the mem ory read and write s ignals from the 8257
to interface s low memories or 1/ 0 deviet.~.
Hold Roqueot (HRQ) : Any valid DREQ causes 8257 to issue the HRQ. II is used for
requesting CPU to get the control of system bus.
Hold Acknowledge (HLDA) : The octive high Hold Acknowledge from the CPU
indkatcs that it hM rolinguishcd control of the system bus.
DREQ,-DREQ3 : These a re DMA request lines, which are activated to obtain DMA
service, until the corresponding DACK signal goes active.
DACK,-DACK3 : These are used to indicate peripheral devices that the DMA request is
granted.
Terminal Count (TC) : This is active high Sib'l\al concem with the compiNion of OMA
service. The TC output signal is activated at the end of DMA service, i.e. when present
cycle is a last cycle for the current data block.
Copyrighted material
Mlcroprocusors and Interfacing 6 -6 Direct t.'e .. oory Access (DMA) 823718:257
MARK : Tilis output notifies the selected peripheral that Lhe current DMA cycle is the
128 " cycle since the previous MARK output. MARK always occurs ot 126 (all multiplies of
126) cycles from the end of the dat., block.
.. r-
Data I '"' 16 ORQ0
o,.oo ( bl1
' bus
buffer
- addr
CNTR
; :
... 16
DRQ 1
RlR bit
RlW
CLK
RESET
Readl
write
j
..
- addr
C>ITR DAllR,
.,.,_
Ao
logic
.... 16
_,
bit
'
H LDA-
ggm1--< set
.~
register Priotity
lm!WY--< resolver
AEN-
.~
ST8- I
Internal bus
MARK
TC ....
Copyrighted material
Mlci'Oflrocesf!Prs and Interfacing 6-7 Dire<:! Memory Access (DMA) 8237/8257
internal "'b>isters of 8257. In master mode, it is used to send higher byte address 1As-A1s)
on the data bus.
Road/Write logic
When the CPU is p rogramming or reading one of the internal registers of 8257 (i.e.
when the 8257 is in the slave mode), .t he Read/Write logic accepts the 1/0 Read (lOR) or
1/ 0 Write (lOW) signal, decodes the the least significant four addre$S bits (Ao - As) and
~ithcr wrltcs the contents of the data. bus lnto th~ addres..t;Cd regio;ter (if iOW is low) or
places the ('(_mtents of the addressed register onto the data bus (if lOR is low).
During OMA cycles (i.e. when the 8257 is in the master mode) the Read/Write logic
g(..onerates the 1/0 read and memory write (DMA write cycle ) or 1/0 write and memory
read (DMA read <::yde) sign.1ls which control the data transfer bel\v(!Cn pcriphcr:ll and
memory device.
DMA Channels
The 8257 provides four identical channels, labeled CH, to CH3. Each channcl has tw"
sixteen bit registers : i) A DMA address register. and ii) A tcrmin31 count r(-gis ter.
DMA Addnoss Register :
Fig. 0.5 shows the format of OMA addn-:,s n..ogi.stcr. It ~pt...odfit...os tht! .1ddn......_... u ( lh( fi,..,.t
memory location to be accessed. 1t is necessary to load valid memory address in the DMA
address register before channel is enabled.
T, To Type of openUon
Copyrighted material
Mlcroproeessor&iand Interfacing 6-8 Direct Memory Access (DMA) 8237/8257
The value loaded into the low order 14 bits (C 13 -Co) of the terminal count register
specifies the number of DMA cycles minus one before the terminal count (TC) output is
activ,1ted. Therefore, for N number of desired DMA cycles it is necessary to load the value
N-1 into the low order 14bits of the terminal count register. The most significant 2 bits of
the termina l count regi~lcr specifies the type of DMA operation to be performed. It is
ncces..;;ary to load count fo r DMA cycles and operational code for valid DMA cycle in the
terminal count register before channel is enabled.
Control logic
It controls the sequence of operatiOJ\S during 0'1.11 DMA cycles (DMA read, DMA write,
DMA verify) by generating the appropriate control signals and the H>bit address that
specifies the memory location to be accessed. It consists of mode set register and status
register. Mode set register is programmed by the CPU to configure 8257 whereas the status
register is read by CPU to check which channels have reached a terminal count cond ition
and status of update nag.
e7 B6 B5 e, 83 e., e, B0
lt is nonnally programmed by the CPU after initializing the DMA address registers
and terminal count registers. It is cleared by the RESET input, thus disabling all options,
inhibiting all chaMcls, and preventing bus conflicts on power-up.
Status Register
Fig. 6$ shows the status register format. As said earlier, it indicates which channels
have reached a terminal count condition and includes the update f'lag described
prev ious ly.
The TC status bit, if one~ indkates terminal count has been reached for that channel.
TC bit remains S<'l until the status register is read or the 8257 is reset. The up!ate flag,
h.._1wevcr, i:o:; not a ffech.:.d by a status read Optration.
Copyrighted material
Microprocessors and Interfacing 6-9 Direct Memory Acce(DMA) 823711257
0 0 0
L _ TC status 101' Channel 0
Update flag
TC status for Channel 1
TC statu-s fOf c::tlannel 2
TC status for channel 3
The update Aag bi~ if one, indicates CPU that 8257 is executing update t)'de. In
update cycle 8257 loads parameters in channel 3 to channel 2.
Priority Resolver
It resolves the peripherals requests. It can be programmed to work in two modes,
either in fixed mode or rotating priority mode.
Priority Chlnnel
Highesl 1 0
2 1
3 2
4 3
Table 6.1 Priority ratings
Copyrighted material
Hidden page
Hidden page
MlcroproeessOrc-'~nd Interfacing 6 - 12 Direct Memory Access (DMA)- 823718257
~ ..
Q ..
Q '
Q
Q 0
tf o 8 o
0 -8 0' N
"
8 0'
J I~ I~ A A j
~~~ ~ ~~ I~ I~
I I I I I
I
~ ~ <!-2
"~
-.
11~
OQ
a' <
~~
. g"
c o
f
~
~
,(
i%
~ d~
-.. I~ I~
!l
I~ ~~ 0
Q
g ~
~
~
w
lfl ~ 18
tf ~ .
I
~~
-' < ~uz:S
ld
owuOowu-
10
u
-' <~U :Z: ~ E
1
fO I~ I~ I~ { I~ H f-
<
~
~
o-lj o
IC
N
hi
I I
Fig. 6.10
Copyrighted material
Hidden page
Hidden page
Microprocessors and Interfacing 6 - 15 Direct Memory Access (DMA) 823718257
EOP
RESET
cs
READY
......
-
ct.OCK
AEN
AOS'lll
MEMR
MEMW
lOR
lOW
Table 6.2
Copyrighted material
Hidden page
Hidden page
MlcroprocenOJS and Interfacing 6 - 18 Direct Memory Access (DMA) 823718257
Cascade Mode
DMA ch;mnels can be expanded using this mode. Fig. 6.14 shows thnt two addition:.l
devices are cascaded to the mas ter device us ing two channels of the master device. This is
two level DMA system. In this the HRQ and HLDA signals from the additional 8237A are
conn<.'Cted to the DREQ and DACK signals of a channel of the master 8237A. This allows
the DMA requests of the additional devices to communicate through the priority network
circuitry of the preceding device.
2ND LEVEL
o:I:ITA
1ST LEVEL
M1CROPROCSSOR
HRO DREO HRO
>I.OA DACI( HlOA
W7A
OREO HRO
DACI(
>I.CA
&237A
ADOinONAL
DEVICES
Copyrighted material
Start Sllrt Start
No /
__..... ,..... .... ' ...
~
5.
i,. j
..;
w
v..
OMA acquires ~
"'"
OMA .cqulres DMA acQUires the control of
the control of the oontrd of buses from DI'008'SSOf
i buNt from PfOCtltol' buses from processor
0
DW.rtllngulohts
;
!l
I
oonttol of buses 1o
processor 1:
YH 3
!i. ~
i No
f-
DMA relinguishes
control of buses to
IV" processo< 0
~
0
0
"0
I ptO<:eiiOt
~
'< 0
~
cO~ lop Slop Slop tl
-
::r
~
(1) atnglt tronofe< (b) Block trandw (c) Demand transt.r
.........ill
3.
"'"'
10
"'
Microprocessors and Interfacing 6 - 20 Direct Memory Access (OMA) 8237/8257
HOLD
HL()A
I
Master
DMA
Controller
Slave
DMA
Control'-r
Copyrighted material
MICI'Oprocessors and Interfacing 6. 21 Dlrec1 Memory Access (DMA) 823718257
6.10.2 Autoinitialize
In this mode, during the initialization the base address and word count registers are
loaded ~;mu1taneously with the current address and word count registers by the
microprocessor. ~ address and the count in the base registers remain unchanged
throughout the DMA service.
After the first block transfer i.e. after the activation o( the EOP signal, the original
values of the current address and current word count registers are automatically restored
from the base address and base word count register of that channel. After autoinitialization
the channel is rea.dy to perform ;:mother DMA servk~. without CPU intervention.
6.11 Priority
In the 8237A there are two priority scl(>('tion options.
1. Fixed Priority
2. Rotating Priority.
Copyrighted material
Mlcrop<ocessors and Interfacing 6 22 Direct Memory Access (DMA) 1,&23718257
6.12 Register Description
1. Current Address Registe r : Each dlt.1.lllle1 has 16-bit current address register. This
rt.--gister stores the value of the address used during DMA transfers. The address in the
current address regis ter is automatic::al1y incremented or decremented after each transfer.
This register is loaded or read by th~ mkropl"'CeSS()r and it a.Lso be re-initiaHzcd back to
its original value after EOP in the autoinitialization mode.
2. Current Word Register : Each channel has a 16-bit current word count regisrer.
This register determines the number of transfers to be perfonncd. Tile actual number of
transfers will be one more than the number stored in the current word count register.
After e<'lch transfer the contents of word count register is decremented by 1. Wht"'l the
value in the register goes from zero to FFFFH, a TC wHJ be geru.'"Tated. ThLo; register is
loaded or read by the microprocessor and it also be relnitialized back to its original value
after EOP in the autoinitialize mode.
3. Base Address and Base Word Count !Wglot."' : Each channel has base
address and base word count registers. TI\CSC 16--bit registers s tore lhe original V<lluc of
their associated current registers. During autoinitialization these values are used to restore
the current regist~ to their originctl values. 1he base n.-gisters are storE..od simultaneous ly
with their corresponding curl't-"'flt registers.
4. Request Register : 'The 8237A can respond to requests for DMA service which
are initiated by software as well as by a DREQ. Each channel has a req....st bit associated
with it in the 4-bit request register. Each bit in the reqlK'St register is set or reset separately
undc..)J' software control and is nu tQmatkaJJy dcan.>d upon generation of a TC or t.xtemal
EOP.
Request Register
7 6 5 4 3 2 1 0 .-sitNumber
Don't Care
I { 00 St:locl """""' 0
0 1 Select channel 1
10 Select chaooel 2
11 Select channel 3
5. Command Register : Fig. 6.18 shows the bit patlem of the oommand rq;i:,ter. It
is a.bit n:.og:ister wh ich ('Olltrols the opc..--r.1tiun o( 8237A.
Copyrighted material
~lcropn>cuson and Interfacing 6 23 Direct Memory Accuo {DMA) 823718257
Commend Register
7 6 5 4 3 2 1 O ~ SitNumber
I I I I I JIJ I
1 ro Memory-to-memory diseble
l 1 Memo<y-to-memo<y enoble
0 Channel o address hOkl disable
1 Chan.wtl o a<khss hOld enable
X lfbftO=O
0 Controler enable
1 Controller diS8ble
0 Normal timing
1 Compreosed timing
tfbit 01
0 Fixed ptfority
1 ROialing prlor11y
6. Mask Register : E.1ch channel request can be individually maoked by setting the
proper bit pattem in the mask register. Fig. 6.19 sh<>ws the bit patterns of the mask
register.
7 6 5 4 3 2 1 0 +--BitN~Mnber
I I I I I I I I
00 Select channel 0 mask bit
Don't Care 01 Select channel 1 mask bil
10 Select channel 2 mask bil
11 Select channel 3 mosl< bft
Copyrighted material
Mlci'.OI)I'oces~ and Interfacing 6- 24 Qlrect Memory Acces, (DMA,) - 8237/8257
'~ ...
:)
Note : All fou r-bits of the mas k register can be written with a single command.
Fig. 6 .20.
7 6 5 4 3 2 1 O.....,_BiiNumber
l l J l J illJ
~ IL ----lr o Clear Cllannel o mask bll
Don't care l 1 Set chaMel 0 mask bit
I '
7. Mode Re.gister, : Each channel has n 6-bit mode reg-i.i tcr associatL)(J with it. The bit
I' 11 h ru ,,f tl'k 1m~o~.ic ':t-,.;i~h.. r is '-'~ shown in the Fig. 6.21 .
Mode Register
7 65432
'- I I I I II I
~,,
00 Channel 0 select
01 Channel 1 seleC:t
o
1 Channel 2 se1ec1
11 Charnel 3 se.4ect
00 Verify transfer
01 Write transfer
,
I 0 Read ltansfer
1 Illegal
\ ' tfbits 6 and 7 = 11
10t
I
\
!
I 0 Adcl'eSII: inct'el'nenf setec:t
1 Addte!IS cSeaernenl 9eled
,.
Copyrighted material
Microprocessors and Interfacing 6 25 Direct Memory Access (DMA) 823718257
8. Status Register : The status register contains the infonnation about the status of
the OMA channels. It includes which channels have reached a terminnl count and which
ch<~ nnels have pending DMA requests. The bit pattern for s tatus r:c~istt..--r i!J shown in
Fig. 6.22.
ll JllL il l
1 Chamel 0 has reached TC
1 Channel 1 has reached TC
1 Channel 2 has read~<><l TC
1 Channel 3 has reaChed TC
1 Channel 0 request
1 Channel 1 request
1 Channel 2 request
1 Channel 3 request
--
'
0 0 1 ~ ,")
Copyrighted material
Hidden page
Mlcroprocnoora nd lnletfacl119 8 27 Dlfect Memory Acc:.aa (OMA) 823718257
Softwore Comm.tndo : The 8237A respond 10 the splal software commands in the
progmm mode. Each software command hruo the spociflc code. The Table 6.5 lists the code
fO< spocial software comtru~nda provided by 8237A.
a..- Open~Uon
6.13 Interfacing
Fig. 6.23 shows that a typical method for configuring a DMA sy>tem with the 8237A
controller and an 8088 microproces!!Or sy>tem. The multlmode DMA controller issues a
HRQ signal to the microproces.10r whenever there is a t leilSt one valid DMA request from
a peripheral device. When p""""'""r responds with a HLDA signal, the 8237A tokes
control of the addr('ti..S bus, data but' and control bU!.. Tile 8237A sends lower byte of the
address on the AoA 7 bus and higher byte on the data bus. The contents of the data bus
are then latched Into the extemol latch to complete the full 16-bits of the address bus.
Microprocessors and Interfacing 6- 28 Direct Memory Access (DMA) - 8237/8257
~ ' ~ ' ~
~ ~"
...
oe
.
. _, ...o. A,Ao A7 ~ AEN
AOST8
_r LATCH
~ t-"'9
- - ClK
'
~
~
0:
8:Z37A5
,~ .
~~ ~ ~~~~ li li
oao
ce,
A
...
.. . ! 4 4
CI.K - ,,.,, .
RESET
MROC
MWRC
lOA
lOW
Review Questions
J. WIMt i~ lite' lli'f'<f ofi)M!l iu mi,rartrot:"!l~r nJrliclrtious?
~. 1:\JJ/,riu tilt' (lf(,/rilt'(lllft', organiSIItiou and vmio11s modr$ of Optration of a programmable DMA
~-ontrollr.'f' 8257.
J. Expl.rin hr bri<f tltr difft'mll (VP.~ of DMA data trrmsfrr.
.J. W1111t do you rmtltrSlnmJ by tiN.' following lt'TmS ?
Rotann,f! l'riority mode.
TC STOI, r~wd
S. Giw tltt' int<'rfacitrg sdrt>mc of 8257/81J7 ;md 8086.
6. List lilt' featuns of 8237 A DMA controll~r.
7. Draw a11d t'Xplaitr tl1t> ardtitt'Cillrt of 8237 A .
8. Explnirr till" optroting modes of 8237 ..4.
9. xp!ni11 tlw datil tnwsjt'r f.VIH'$ SllpfiOI'IM b.v 8237 A.
JO. Cxpl(1in "'" wiorily option: ntuilnlllc in 81J7 A
'I J . Draw ttud t'.l' plniJl 1.11.. iuterfilciu.~ of 8137 A nnd 8088.
CICICI
Copyrighted material
. u' ,.
Tile 8255 is a general purpose programmable 1/0 device u...;cd (or poralld J.1to
transfer. It has 24 l/ 0 pins whkh can be grouped in three 8-bit parallel ports : Port A,
Port B and J'ort C. The eight bits of port C c-an be used as individual bits or be grouped in
two 4-bit ports : C,,., (C") a nd C ..... (Cc>
The 8255, primarily, can be progra mmed in two basic modes : Bit Set/Reset (BSR)
mode and 1/0 mode. The BSR mode is used to set .or reset the bits in port C. The 1/0
mode is Further divided into three modes :
Mode 0 : Simple Input/ Output
Mode I : Input/Output with handshake
Mode 2 : Bi-directional 1/ 0 data transfer
The function of 1/ 0 pins (input or output) and modes of operntidn of 1/0 ports can be
programmed by writing proper control word in the control word register: Each bit in the
control word has a specific meaning and the s tatus of tht.-ose bits dt"CideS th~~ Function cmd
operating mode of the 1/0 ports.
Copyrighted material
Mlcroproceooonl and Interfacing 7 - 2 8255 PPI (Programmable Peripheral interface)
7. The 8255 can operate in 3 I/ 0 modes : (i) Mode 0, (ii) Mode I, and (iii) Mode 2.
a) In Mode 0, Port A and Port B can be configured as simple 8-bit input or output
ports without handshaking. The two halves of Port C can be progtammed
separately as 4bit input or output ports.
b) In. Mode I, two groups each of 12 pins are formed. Group A consists of Port A
and the upper half of Port C while Group B consists of Port B and the lower half
of Port C. Ports A and B can be programmed as 8-bit Input or Output ports with
thtee lines of Port C in each group used for handshaking.
c) In Mode 2, only Port A can be used as a bidirectional port. The handshaking
si!lMis are provided on Ave lines of Port C (PC, PC, ). Port B can be used in
Mode 0 or in Mode I.
8. All l /0 pins of 8255 has 2.5 mA DC driving capacity (i.e. sourcing current of
2.5 mA).
P.Ao 40 PA,
PA, 39 PA,
PA1 38 PAo
PAo 37 PA,
R5 36 \VR
Cs 35 RESET
GNO 34 Do
A, 33 o,
Ao 32 02
PC7 31 o,
USSA
PC6 30 o,
PC5 29 Ds
PC4 28 o.
PC0 27 0,
PC 1 26 Vcc(+5 V)
PC2 25 PB7
PC3 24 PB8
Pao 23 PB5
PB 1 22 Pa,
PB2 21 PB3
D0.0, (Dala B<Js) These bi-directional, tri-state data bus tines are connected to tho system
data bus. They ere used to transfer data and control word frcm
mlcroPf'QCe$sor (8065) to 8255 or 10 receive data or status word from 8255
to the 8085.
PAo-PA7 (Port A) These 8-bit bi-directional liO pins are used to send data lo output device
end to receive daca from ilput <fErolioe. It ~~ et an 8--bit data output
latch/buffer, when used In outpll'l mode and an 8-blt data Input buffer, when
used in input mode. .
PB0-PB7 (Port B) These S.bit bi-directional liO pins are used to send data to output device
and to recefve data from k'lput dcwloe. It fi.rlctlons as an 8bft date, ovtpU'I
latchlbutfer when used in output mode and an 6-bit data I~ buffer. when
used in input mode.
J>Co.PC, These &.-bi1 bl-dlrecdonal lfO pins are divided Into two groups PCt.
(~.PC.0) and I:.Cu (PCrPC4). These groups indMdualy can transfer data
., or out when programmed for simpae l/0, and used as handshake signals
when programmOd for hancbtlab or bi-directiOnal modes.
RD (Read) When this pin Is tow. the CPU can read the data In lhe ports or the saatus
word, through the data buffer.
-WR {Write) VYhen this input pin i s tow, the CPU can write data on the pot'IS 0t in the
control regGter through the data bus buffer.
-
CS (ChiP 5elect) This is an active kJw input Which can be enabled for data transfec' opetatlon
between lhe CPU and the 8255.
RESET This Is an activo high i"Put used to reset 8255. When RESET k'lput Is high,
the control register i s cleared and al lhe ports are set to the input mode.
U$U811y RESET OUT signal ffom 8085 Is used to reset 8255.
Ao and A 1 These Input signals along wftll RD and WR Inputs oonVol the selection ol
the controlfstalus w01d regislers Of 2!2! q!_lhe th~. Tabie. 7.1.
summarizes the status of Ao ,
A 1, CS, RD and WR to acceu the con1Jol
wordfporls. Ao and A 1 are generally connected~A 1 pins of the
addreu bvs: the 8255 therefore occupies four locations in the
110 "'"""
Ao
" RD WR cs Operation
Copyrighted material
Microprocessors and Interfacing 7 4 8255 PPI (Programmable PerlpMral...-rface)
DI!Nble Function
X X X X 1 Data Bus TI'IStated
1 1 0 1 0 Illegal Cond-
I I
,_J P.
POWER{-
suPP\.IES -
5V
GNO
- GROUP
A
CONTROL
GROUP A
PORTA
(8)
r
I
GROUP A
PORTC
Upper
BIOtRECTIONAL (4)
DATA BUS
o,..o, r
DATA
BUS
BUfFER 8BIT
INTERNAL GROUPB PCL
DATA BUS PORT O
Lower
.
(4)
I-
_I
Rll
WR READ/ GROUP GROUP S PB
WRITE PORTS
S
RESET
""A, CONTROl.
LOGIC -
CONTROl. (8)
I-
p
L...r.__
I I
t:1; l
Copyrighted material
Hidden page
Mluoproc. .sors and Interfacing 7 6 8255 PPI (Programmllble Pertphenlln...,_)
Copyrighted material
MlcloprocH oora ond lnt.rfacing 7 7 8255 PPI (Prograrnm- P..-lpherll lnt.rt.ce)
l o l ~l~l~ l ~l~lo, l ~ l
L L L I SIT SET/RESET
1 SET
~ ORESET
Don't c:are
SIT SELECT
0 I 2 3 4 5
1
0 I 0 I 0 I 0 I Bo
0 0 I I 0 0 1 I a,
0 0 0 0 1 1 1 1 a,
The cight pos.<tibte combination.~ of the s tates of bits 0 3 -B1 B1 8 0 ) in the Bit
01 (
Set-Reset formllt (BSR) determine particular bit in I'C. . PC1 being set or reset as per the
5tatus of bit 0 0. A SSR word is to be written for each bit that is to be set or r~t. For
example, if bit PC, is to be set a..nd bit PC,. is to be reset, the appropriate BSR words that
will h.tve to be lo.,ded into the control register will be, OXXXOIII and OXXXIOOO,
respectively, where X is don't care.
.
The BSR word can also be used for enabling or disabling interrupt signals generated
by Port C when the 8255 is programmed for Mode 1 or 2 OJX><ation. This is done by
setting or resetting the associatt."<i bits of the interrupts. This is described in detail in nex-t
section.
For I / O -
The mode definition format for 1/0 mode is s hown in Fig. 7.5. The control words for
both. r.oode dcli.nition and Bit SctR~t arc loodcd into the s.une control register, with bit
0 1 used for spt.'Cifying whether the word loaded into the control register is a .._mode
Copyrighted material
Microprocessors' and Interfacing 7 8 8255 PPI (PrOgrammable Perlpherallntofface)
1 o. o, o, o, 02 01 Do
I I GROUPS
PORT C (LOWER)
1 INPUT
O=OUTPUT
PORTS
1 INPUT
OOUTPUT
MODE SElECTION
O MOOEO
1 MOOE1
GROUP A
PORT C (UPPER)
1 INPUT
O=OUTPUT
PORTA
I= INPUT
O=OUTPUT
definition word or Bit Set-Reset word. lf 0 1 is high. the word is taken as a mode
definition word~ and if it is low, it is taken as a Bit Set-Reset word. The appropriate bits
arc set or reset dt:"pCnding on the type of operation desired, and loaded into the control
regisler.
Copyrighted material
-
Micropi"OC4!Uors and lnt-clng 7-9
Solution :
8255 PPI (Programmabl P ..lpMral lnltlrf-)
1 0 0 1 1 0 0 0
l l L Port cl - Output
Pott 8- Output
ModeOPart 8 - Simpk! l/0
Port Cu input
Port A - Simple input
MOdeOPonA-Sim 110
1 0 1 0 1 1 1 0 =AEH
I I
PonA
Pon<;,
- -
L Pon c, Output
8
1 Pon B - HandShake
Program S-ment :
Write a pn.lgmm to blink Port C bil 0 of the 8255. A~umc addn..---ss o( control word
r.'gisk>t ol 8255 L 83H. U:<e Bit Sell R..-..t mod<.
Copyrighted material
Hidden page
Mk:roproceooors and Interfacing 7 - 11 8255 PPI (Programmable Peripheral Interface)
81H
As mentioned earlier, this mode provide sinlple input and output operations for each
ol the tl\r.,., ports. No handshaking 1$ ""!lllrood, daln is samply writlen 10 or read from a
specified pori.
Input Mode : rig. 7.6 shows lhe liming diogram for mode 0 inpul mode.
Rll - - - - - - - 1
I
Input
---~
CS, A,.I\o _ __ _.
Afler initializnlion ol 8255 in the inpul mode 0, CPU can read dala through lhe in~
port by initiating read command with propct port address. Read command tti:tivates RD
signal. Upon activalion of RD sign.,l CPU reods lhe dnm from lhe sell'<:ted input port into
the CPU register.
0
Microprocessors and Interfacing 7 12 8255 PPI (Programmable Peripherallnterfece)
Output Mode : Fig. 7.7 shows th~ tinting di.-gram for mode 0 output mode.
A B GROUP A GROUP B
o, o, o, Do PORT A PORT C
(Upper) PORT B PORT C
(Low.r)
0 0 0 0 OUTPUT OUTPUT 0 OUTPUT OUll'UT
0 0 0 1 OUTPUT OUTPUT 1 OUTPUT INPUT
0 0 1 0 OUTPUT OUll'UT 2 INPUT OUTPUT
0 0 1 1 OUTPUT OUll'UT 3 INPUT INPUT
0 1 0 0 OUTPUT INPUT 4 OUTPUT OUll'UT
0 1 0 1 OUTPUT INPUT 5 OUTPUT INPUT
0 1 1 0 OUTPUT INPUT 8 INPUT OUll'UT
0 1 1 1 OUTPUT INPUT 7 INPUT INPUT
1 0 0 0 INPUT OUll'UT 8 OUTPUT OUll'UT
1 0 0 1 INPUT OUll'UT 9 OUll'UT INPUT
1 0 1 0 INPUT OUll'UT 10 INPUT OUTPUT
1 0 1 1 INPUT OUll'UT 11 INP\IT INPUT
1 1 0 0 INPUT INPUT 12 OUll'UT OUTPUT
1 1 0 1 INPUT INPUT 13 OUTPUT INPUT
1 1 1 0 INPUT INPUT 14 INPUT OUTPUT
1 1 1 1 INPUT INPUT 15 INPUT INPUT
Copyrighted material
Mlcroproceuors and Interfacing 7 13 8255 PPI (Programmable Peripheral Interface)
Copyrighted material
Microprocessors and Interfacing 7 - 14 8255 PPI (Programmable Peripheral Interface)
port. Port A can ilccept parallel d(lta from a peripheral (like a keyboard) and this datd can
be read by the CPU. The peripheral first loads data into Port by maldng the STB, input
low. This latches the data placed by the peripheral on the common data bus into Port A.
Port A acknowledges reception of data by making IBF, (Input Buffer Full) high. IBFA is
set when the STB"' input is made low, as shown in f ig. 7.8 (b).
MOOE ! (PORT A)
Conttol word
r----
' INTE r"'----
' PC
A o
'- - -- PCs
1 = INPUT
0 c OliTPUT
m,,--,
'---____,J/
I
I~R --------J/'
Rn -------+--,." ) /'r/ _ _
o:-;:~ -<________,>---------------------
Fig. 7.8 ( b) Timing diagram for port A In mode 1
INTR, is an octive high output signal which can be used to interrupt the CPU so that
the CPU can suspend its current operation and read the data written into Port A by the
peripheraL INTRA can be enabled or disabled by the INTE, flip-flop which is controlled
by Bit Set-Reset operation of PC,. INTR, is set (if enabled by setting the INTEA flip-flop)
after the STBA has gone high again. and if !BFA is high.
On receipt of the interrupt, the CPU can be forced to read Port A. The falling edge of
the RD input resets !BFA and it goes low. This can be used to indicate to the peripheral
that the input buffer is empty and that data can again be loaded into it.
Copyrighted material
Microprocessors and Interfacing 7 - 15 8255 PPI (Programmable Perlpherallntorface)
Control wo<
r----.,
PB,.PB0
~
I' INTE 'r---- PC2 1--1
0
~ s
t_,.,,_,___,!
I PC 1 f--t
~
PCo r- INTR6
If the CPU is busy with other system operations, it can rend data from the input port
when it is interrupted. Titis is often called interrupt driven l/0. However, if t1w CPU is
otherwise not busy with other jobs, il c-an continuously poiJ (read) the status word to
check fo r an IBF . This l< often caUed Program ControUed 1/0. The status word is
aca:ssed by reading Port C (A 1 A0 must be 10, RO and CS must be low). The s tatus word
fonnat when Ports A and B arc input ports in Mode 1, is shown in Fig. 7.10.
INPUT CONFIGURATION
o, o8 o5 04 o3 o2 o, o0
1/0 1/0 j1sFA I INTE.jiNTRAjiNTE6 j lsF6 j tNTRel
-L~----~----~' I I
GROUP A GROUP 8
Fig. 7.10 Mode 1 status word (Input)
Copyrighted material
Microprocessors and Interfacing 7 -16 8255 PPI (Programmable Peripheral Interface)
MODE 1jPORT A)
Control word
, - - - - - I PC7
1 0 1 0 t/0 -----..
INTE j PCs
Il.....A
_ _j
r'--;
PC 5, PC4
' - - - 1 = INPUT
0 OUTPUT
Copyrighted material
Microprocessors and Interfacing 7 - 17 8255 PPI (Programmable Peripheral Interlace)
vm -----._
l.rrR:r-----""""
~.~------------~~
DATA:- - - - - - - - - - - -
OUTP~~ PAEv1ous DATA X..____N_e._v_o_r__ _ __
PAoPA7
Control WOtc:t
o,. De o, D4 o1 ot 01
I c><lXI><JXJ I lXl I 0
INTR8
Th" s t.11us word is acccsstd by issuing a Read to Pon C. The forma t of the s tatus
word when Port$ A <~n d B are Output ports in Mode 1 is shown in Fig. 7.1 3.
o, o, o,
I I L-~~~1
I I
GRD\JP A GRD\JP B
pn..') grammed i l''l Mode 0 o r it\ Mode 1. \--vhen Port B is programmed in mode 1, PC0 - PC 2
lines of Port C are used as handsh..'lking signals.
Fig. 7. 14 s hows the control word that should be loaded into the control port to
config u re 8255 i l''l Mode 2.
1 1
X IX X 110 110 110
PC,.-f'Co
1 = INPUT
0 OUTPUT
PORTS
1 = INPUT
0 0\JTPUT
GRD\JP B MODE
O MODEO
1MODE 1
Copyrighted material
Mlcroprocenors and Interfacing 7 -19 8255 PPI (Programi1UIIJM Periphefallnterfeee)
ACKA (Acknowledge)
This is an active low input signal (generated by the peripheral) which enables the
tri-state output buffer of Port A and makes Port A data available to the peripheral. In
Mc:x:J(! "" : Jrt A outputs are in tri-state until enabled.
INTE 1
This L< the Rip-flop associated with Output Buffl?r Full. INTE I ean be used to enable
or disable the interrupt by setting or resetting PC in the BSR Mode.
Input Control Signals :
)-
J >-E f--tHTF(A Interrupts are generated for both output and
input operations on the same INTRA (PC,)
PA,-PAo
,., r--
PC,
line.
Copyrighted material
Microprocess ors and Interfacing 7 - 20 8255 PPI (Programmable Peripheral Interlace}
B is in MOOc 1, 0 2 - 0 0 carry information about the control signals for Port 8 (as in
Fig. 7.10, or Fig. 7.13), deptmding upon whether Port B is an Input port or Output port
respectively.
Dz D,
Imil' I
A ltH E 1 I
I
GROUP A GROUP B
(DEfiNED BY MODE 0
OR MODE 1 SELECTION)
-..
ONLY
PA, IN OUT IN OUT
PA, IN OUT IN OUT ++
PAz IN OUT IN OUT ++
PA3 IN OUT IN OUT
PA,
PAs
IN
IN
OUT
OUT
IN
IN
OUT
OUT ...
++
~~
IN OVT IN OUT ++
IN OVT IN OUT ++
MODE 0 MODE 1 MODE 2
--
IN OUT
~~
IN OUT
IN OUT IN OUT
p~
P63
IN
IN
OUT
OUT
IN
IN
OUT
OUT
-- ModeO
Ot
---
PB, IN OUT IN OUT Mode1
PB5 IN OUT IN OUT Only
PB6 IN OUT IN OUT
PB, IN OUT IN OUT -
~
IN OUT INTR, INTR8 110
IN OUT IBF8 08F8 1/0
~ IN OUT STS, ACKS 1/0
~
IN OUT INTRA INTRA INTRA
IN OUT STB 110 STBA
PC5 IN OVT 18fA 1/0 IB~
PC8 IN OUT 110 AC~ AC
PC7 IN OVT 1/0 08 . oB?.
Copyrighted material
Mlcrop<ocesaors and l nterfaclrig 7 21 8255 PPI (Programmable Peripheral Interface)
Do
~~<
o, o,
A PA, "-
A, Ao " PAr v
>
... A,
A PBo
Milt!
Ri5
Ao
' RO
8255
, PBr
Copyrighted material
Microprocessors and Interfacing 7 22 8255 PPI (Programmable Peripheral Interface)
Do Do
.,., ....,
0, D,
Ap...
....., WR
..
A15
--1
RO
I'IR
8255
~
APC0
"~' PC
7
>
.... .. Reset CUI
R...,
cs
.., 5
....,,
A,
A, ' )
.......'
..
...."'
..
...
Fig. 7.18 Memory mapped 1/0
Rtglat ..... .... .... .... .... Au .... .... .... AM .. ddres
P<>ttA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OOOOOH
P<>tt B 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 00002H
Po"C 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 00004H
Control rcg;s.ter 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 00006H
Copyrighted material
Hidden page
Mlcroproeosson and Interfacing 7 24 8255 PPI (Programmable Peripheral interface)
The IC 1408 cons i<IS of reference curreot amplifier, an R/2R ladder and eight high
speed current sw itches. It has eight input dato lines A1 (MSB) through As (lSB) which
control the positions of current switches.
It requires 2 mA reference current for full scale input and two power supplies
Vee = + 5 V and Vee a=- 15 V (Vu can range from - 5 V to- 15 V).
The voltage Vro:f and resistor R14 determines the total reference current source and Ru
is generally equal to R1.- to match the input impcda\CC ol the reference current amplifier.
Fig. 7.20 shows ' typical circuit for IC 1408.
I = V~r (~ + A2 + A l + A +A, + A, + A , + A 11 ) ( 1)
R 14 2 4 8 16 32 64 128 2.16 ...
Note : lnput At through As can be either 0 or 1. lherefore.. fo r typical circuit full scale
ciJ.ITf!Jlt can be given as,
= 2mAx255 = A
256 1992
. m
Copyrighted material
Microproc.Uol'8 and Interfacing 7 25 8255 PPI (Programmable Perlpherlllnterface)
It shows that the full scale output current is always I lSB less than the reference
current sour o( 2 rnA. This output current is converted into voltage by I to V converter.
The output voltage for full scale input can be given as
V0 = 1.992x 2.5 K
4.98 v
Note : The arrow on the pin 4 shows the output current direction. It is inward. This
means that lC 1408 sinks current. At (0000 0000), binary input it sinks zero current and at
(11111111)2 binary input it sinks 1.992 mA.
The circuit shown in the Fig. 7.20 gives output in the unipolar range. When digital
input is OOH, the output voltage is 0 V and when digital input is FFH (11111111)2, the
output voltage L~ + 5 V. This drcuit can be modified to give bipolar output.
Fig. 7.21 sho\~o's the circuit for giving output in the bipolar range. Here, resistor R8
(5 K) is connected between V"' and the output terminal of IC 1408. This gives a constant
current source of 1 mA.
Vee
+5V
5 13 R,.
A, +5V
6
14 v,.,
A2 2.5 K
8-bit
d igital
1
8
9
A3
~
A$ JC 1<108
1 mA
'l 5K
RB - R,
SK
- .
input
4
10 A
Ao
11
~
Ar
12
Ao . ..1.
15 -:;:"
163 1 2 Ros
15 pF 2.5K
v "
Fig. 7.21 Interfacing DAC in tho bipolar range
The circuit operation can be observed for three conditions ;
Condition 1 : For binary input (OOH)
Whet. binary input is OOH. the output current fo ttt pin 4 is zero. Due to this current
flowing through R6 (I mAl flows through R1 giving V0 = - 5 V.
Copyrighted material
Microprocessors and Interfacing 7 26 6255 PPI (Programmable Peripheral Interface)
11 0
1, = -lmA
Therefore, the output voltage is + 5 V. In this way, circuit shown in the Fig. 7.21 gives
output in the bipolar range.
Important Electrical Characteristics for IC 1408
Re ference current : 2 mA
Supply voltage : + 5 V Vee and - 15 V VEE
Setting time : 300 ns
FuJI scale output current : 1.992 mA
Accuracy : 0.19%
7.9.2 DA C0830
The DAC0830 is an advanced CMOS 8-bit DAC designed to interface directly with the
8080, 8048, 8085, 280, and other popular microprocessors. A deposited silicon-<:hromium
R-2R resistor ladder network divides the reference current and provides the circuit with
excellent temperature tracking characteristics (0.05% of Full Scale RaJl.b~ maximum linearity
error over temperature). The circuit uses CMOS current switches and control logic to
achieve low power consumption and low output leakage current errors. Special circuitry
provides TTL logic input voltage level compatibility.
Copyrighted material
Mlctoprocessors end lnterfaclng 7 - 27 8255 PPI (Progrsrnmll>le PeripherallnterfKe)
Double buffering feature allows this OAC to output a voltage corresponding to one
digitnl word while holding the nex t digital word. This permits the simultaneous updating
of any number of DACs.
The DAC0830 series (0AC0830/DACOB3 1/ DAC0832) ore the 8-bit members of o fomily
of microprocessor-mmpatible DACs. For applications demanding higher resolution, the
OACl OOO series (!O-bits) and the 0AC1208 and OAC1230 (12-bits) are available
alternatives.
Features
Doubl.,.buffcrecl, singl.,.buffured Or flow-through digital data inputs.
Easy interchange and pin-compatible w ith 12-bit DAC1230 series.
Direct interface to all popular microprocessors.
Built-in fadJity fo r zero adjustment.
Works with l: 10 V reference voltage.
Can be used in the voltage switching mode.
Logic inputs whkh meet Til voltage 1eve1 specifications..
Operates ..STAND ALONE.. (without up) if desired.
Available in 20-pin smaJl-outline or molded chip carrier package.
Pin Diagrams
Fig. 7.22 shows ll~ pin diagram of DAC0830. The function of each pin Lo; explained in
Tobie 7.2.
- 1. 20 Vee
WR, - 2 19 ILE(BYTE11BVTE2)
GND 3 18 WR2
DC, - 4 17 XFER
0'2 - 5 16 01,
0 11 - 6 15 ot,
D'<I(LSB) 7 14 ot6
v., - 8 13 Dt 7 (MSB)
RF8 - 9 12 1oun
GND 10 11 loun
DAC0830
Fig. 7.22
Copyrighted material
Microprocessors and Interfacing 7 - 28 8255 PPI (Programmable Peripheral Interface)
- .
Controt Signals (All contrm slgn l level .c:tuated)
cs ; Chip Select (adi\'e low).. The Bin combination with ILE Y"ill enable WR1.
ILE : lnpu1 Latch Enable (acttve high), The ILE In combination with CS enables WR1. -
WR 1 : Write 1. The octM! low WRJ is used to load the digjtal .!!i!Ut data bita (01) into the
loput latch. The data In the oput latCh Is latChed when WRo Is high. To update the
input latch- ~ and WR. must be lOw while ILE is high.
WR~ : Write 2 (active low}. This $lgnal, in combination with XFER, causes the a.bit data
which ts aw!labfe In the i~ut latch to transfer to the OAC reg.lster.
XFER: Transfet control signal (active low). The XFER will enable WR, .
D \)017 : Digital Inputs. 0 10 Is the least significant bit (LSB) and 0 17 Is the mos1 slgnlllcant bit
(M SB).
101/TI : DAC Current Output 1. lour 1 is a maximum for a digital code of all 1's In the OAC
register, and is zeto 101 all Its in OAC register.
lOUT> : OAC Cw rent Output 2. Ioun lour2 constant (I full scale for a fixed reference
'""tage).
R., : Feedback ReslstOt. The feedback resistor is provtded on the IC chip few use as the
Shunt feedbaCk resJstor tcw the extemal op-amp which is used to provide an output
voltage for the DAC. This on-chip resistcw should ahvays be used (not an external
resistor) since it matches the resistors Which are used in the orw;hl p R2R ladcter
and tracks these reslstcn over tet'J1)etlture.
VREF : Reference Voltage Input This input connects an external preds.Jon voltage SQt.II"'e
to the internal R2R ladder. VR~t can be selected over the range ot +10 v to
-1 0 v . This is also the analog voltage Input for a ~uadrant multiplying OAC
application.
Vee: Digital Supply Voftage. Thi s is the power supply pin for the part v cc can be from
+5 Voc to +15 Voc. Operation is optfmum fof + 15 Voc.
GNO: The pin 10 'o'oltage must be at the same ground poten tial as loun and Iou12 for
c...-rent swftchlng appllcaUon$. Any dltference of potential (V08 pin 10) will result in
a linearity chaoge ot
Vo;: ,
1
For example. if VRF a 10 v and pin 10 ls 9 mv offset from lovT1 and
1~. the linearity change wil be 0.03%. Pin 3 can be offset t 100 mv with no
linea ty Change. but tne logic loput ll'<eshotd wiM slllft.
Copyrighted material
Hidden page
Microprocessors a.n d Interfacing 7. 30 8255 PPI (Programmable Peripheral Interface)
DATA
!:S 1
\ I
WIIT & Wll2 1
~
ll.E LOGIC ~1
\
--
~n.PIA'-Ich .............
Copyrighted material
Hidden page
Hidden page
1:
,
.c
...
tl Vee
f
~
a
'
'
:10K
"S'
;. Do Do
PA, 4
PA, 3 ILE ~
!!.
.,"
D,
g;D,
D,
D, ~~ 1
"""
oe,
oo,
oe, ~
o; PA, oe, ~
WID
RD ~
~ Ao
D,
D,
D,
D,
D,
D,
PAo
~~ ...
oe,
oe, + 12V
...
~
VRF +V1e4 (10 V)
WR
0, P8o
P81 XFER "'"'
0
g
R6
ViR ~ ""
loo; ~
AI PB, "'"'
:::
3
;;- ..... A2
RESET
cs
PS.
PS.
PB,
--,.
cs
w., Dri>glon
pair "
:l!
-:;;
c;
" .. 8 A
I!
2 OGNO A.GNO
A, -i>-f
~
2
DAC 0830 "Analog
5
..., Ground
~
- o;gital
c: .. Gr""""
:;
... "
0
0
"0
'<
N
g: I
l
~
cO.
::r
~
3
*"'
"'
Hidden page
Hidden page
Microprocessors and Interfacing 7 - 36 8255 PPI (Programmable Peripheral Interface)
CLKOUT _ CLK IN
RO
RO
ViiR -WR
IN+
Microprocesaor AOC ANALOG
Address INP\IT
Address OOOOdor Cs 01031
System 01041 ~
0805
INT ii'fl'R
~
080
DATA BUS
087
Copyrighted material
Microprocessors and Interfacing 7 37 8255 PPI (Programmable Peripheral Interface)
A IN Analog input
Do Dllo
Dr To DSr
IN-
Dr -!-
. Rii
-
iOR ClKR
R(10 K)
iO ClK
C{150 pF)
:f.
.,.
~ MR
REF/2 VREF
Ao- A Yo 1>-
A, - B D v. Cs AGNO
A,- c E
c
0 />DC0804
.!-
A,- G, D
E
=I / G2 R
Ar - G
'
741 38
\\.....;__.J/
INTR ---...;J~ Busy \'----+- - - -
~ ----~------~\~~!
Start of conversiOn - .
'
Read data
Copyrighted material
Microprocessors and Interfacing 7 - 38 8255 PPI (Programmable Peripheral Interface)
PAo 4
go o, PA, 3 00.
IN+
Analog onput
o' o, PA2 00,
RESET
A,
Wii
AI
A2
REseT
cs
PB2
PB3
PB,
PBs
PB6
cs
Ri5 REF/2
qtso pFJI
VAEF
.,.
PB7
PC, iN'fR
8 PC 1
1
AGNO
2 PC2
.,.
2 ~ ADC 081)4
5 PC,
PC5
PC.
PC,
Application
This section illustrates the application of ADC/ DAC to store and reproduce audio
signal or speech. Refer Fig. 7.36. Here, speech data is converted to digital dta using
AOC0804. This data is stored in the array at the sampling rate of 1/2048 of second. Then
this sampled data ls sent to DAC0830 with same rate to reduce the speech signal This is
illustrated in the following program.
Copyrighted material
II
~~
Hidden page
Microprocessors and Interfacing 7 40 8255 PPI (Programmable Peripheral Interface)
MODEL S~IALL
. DATA
SAMPLES DB 2048 DUP (?) ; Space for speech samples
. CODE
START ' MOV AX, @DATA ; (Initialize
MOV OS, AX ; data seqment J
CALL READ ; Read speech
CALl.. >lRlTE ; Reproduce speech
PROC NEAR
MOV ex, 2048 ; Init ialize counter
MOV Dl,Of'FSET SA~1PLES Ini tialize pointer to array
OUT 94H,AL : Send start of conversion
IN 1\L, 80H ; Read INTR
AND AL, 80H Check INTR
JNZ BACK Repeat until INTR ~ 0
IN AL, 84H Read samplo
MDV { DI J,AL : Store sample in array
INC DI Increment array pointer
CALL DELAY Wait for 1/2048 seconds
LOOP AGAIN Repeat 2048 times
RET
READ ENDP
WIHT PROC NEAR
MOV CX, 2048 Initialize counter
MOV DI, OFFSET S AMPLES ; Initialize array pointer
BACKl ' MOV 1\L, ( Dl) Read sample from array
OUT 82H,AL Send it to OAC
INC DI ; Increment array pointer
CALL DELAY Wait for 1/2048 second
LOOP BliCKl Repeat 20 48 times
RET
WRITE ENDP
DELAY PROC NEAR
; This procedure generates a pproximately 1/2048 second delay
; assuming 8MHz Clock frequency of 8086.
PUSH ex ; save ex register
AGAINl ' MDV CX,0255 ; Initialize counter
LOOP AGAINl ; Repeat until count 0
POP ex ; Restore CX register
RET
DELAY ENDP
END START
Copyrighted material
Microprocessors and Interfacing 7 - 41 8255 PPI (Programmable Perlplleralln1er1ace)
.......
Analo\l
5
:
2}
Arnllog
~~
~}-~
6
7
soc
OUTPUT CONTROL
EOC
083 ....
AOC
01011
A LE
097
096
CLK DBS
Vee o..
REF 080
GNO REF
09 1 082
Copyrighted material
I
Microprocessors and Interfacing 7 - 42 8255 PPI (Programmable Perlpllerallnlerface)
A
e ~ Address X
c - 50nsl-
ALE
~25JJs-C "----1 j
soc ~ (
)
EOC
060 INO
091 IN1
082 IN2
INPUT 093 IN3
PORT/ 064 A IN4 1K
PORTS 065 D INS
09& c IN6
067 0 IN7
eoc 0
-
CLK
OUTPUT
A
6
Output
+5V
0.01 1-1F
PORT c 74t4
soc Vee
ALE +REf 12 v
-"EF GND
2K
-
"""
,......... 10 K
=
Fig. 7.39 Typical Interface for 080810809 -
Copyrighted material
Microprocessors and Interfacing 7 - 43 8255 PPI (Programmable Peripheral Interface)
.....
Stepper
.. x, motor
~ Ov
~
X, 0~
v, v,
~ 0
A, +1
;::::
~
A,
~ rj v--
r bt
~ v)
">
~CQ '' ~ 2~ ' ~ 2~
. '-
Fig. 7.40 Stepper motor Interface
The Tnblc 7.3 s hows typical excitation sequence. The given excitation sequence rotaK-s
thl~ motor in dockwi~ d irection. To rotate motor in antidockwi.~ direction we hnv(' co
("xcilt motor in a reverse sequence. The excitation sequence for stepper motor may changt
due to dtaJ'SC in winding ronn:tions. However, it is not desirable to excite both the ~omds
Copyrighted material
Microprocessors and Interfacing 7 - 44 8255 PPI (Programmable Peripheral Interface)
of the same \'o'inding simultaneously. This cancels the flux and motor windjng may
damage. To avoid this, digital locking system must be designed. Fig. 7.41 shows a sjmple
d igital locking system. Only one output is activated (made low) when properly excited;
otherwise output is disabled (made high).
x, _-.-1 ~o--1--.,
X'1
X2 - r--1.....:..- -L...-
x;
Step x1 x, v, v,
1 0 1 0 1
2 1 0 0 1
3 1 0 1 0
4 0 1 1 0
I 0 I 0 I
Stop x1 x, y1 v,
I 0 I 0 I
2 0 0 0 I
3 I 0 0 I
I 0 0 0
5 I 0 I 0
6 0 0 I 0
7 0 I I 0
6 0 1 0 0
1 0 1 0 1
.
Table 7.4 Half stp excitation sequence
Copyrighted material
Microprocessors and Interfacing 1 45 8255 PPI (Programmable Peripheral Interface)
We know that stepper motor is stepped (rorn one position to the ne1Ct by changing the
currents through the llelds in the motor. n,. winding inducta""" opposes the change in
current and this puts Umil on th(t tot\.-pping rAte. For higher stepping rate s and more
torque, it is necessary to use " higher voltage source and ('WT(>Ilt limiting resistors as
shown in Fig. 7.4.2. By adding seri"" resistance, we decrease L/R time constant, which
allows the """""' to change more rapidly in the wlndinS$- ll>ere is a power loss across
series resistor, but designer has to compromise between power and speed.
)... Example 3 : hlltrfnce sttft/)('r motor to tl1e 8086 microproc.C"Ssor s.vstem and wri te mr
8086 assembly lmrgmrg,. pf08ram to control IIIC' II'PP.'' motor.
Solution : Hardware : Fig. 7.43 shOW8 the typical 2 phnsc 1'1\0h ll' t<~h.:d 12 V/ .67A/ph
interfaced with the 8086 micropl'()((>tlsor system using 8255. Motor shown in the circuit has
two phases, with centertap winding. Tile center taps ol these windings are connected to
the 12 V supply. Due to this, motor om be cxdted by 6rounding four terminals of the two
windings. Motor can be rotatoo In steps by Siving proper excitution sequence to these
windings. 1ne lower nibble o( pori A of tt-K. 8255 i ~ w:....-d to gentratc 4!.Acit.liun ,j~,,, in
the proper sequence. llte--.A." excitation s igm.l11 aN bulk-red usi.ng driver transistors.. 11-.
transistors are selected such that they can souroc rotoo current for the windings. Motor is
rotaloo by 1.8" per excitation.
Hidden page
Hidden page
Microprocessors and Interfacing 1 - 48 8255 PPI (Programmable Peripheral Interface)
+SV
From
porto--'Ww--H
pin
Let us aj;~u mc tha t the Joad cunent is 200 rnA and maximum sourcing current of port
pin is 1 mA. Then transis tor should have
> 200 mA
> l
I Bm.liX
200mA
>
1 mA
hf-c min > 200
pdfl\ol:c > vCE:Io1t lcm.a:c
X
= 3.7 kQ
Copyrighted material
Hidden page
Hidden page
Microprocessors and Interfacing 7 51 8255 P.PI (Programmoble Peripherollnterfac:e)
The mechanical relays or oontactors, however, have several serious problems. When
the contacts are opened and closed, arcing takes place between the contact, which causes
the cot1tacts to oxidize and pit A~ the contacts a re oxidiz.t:d, they become higher resistance
.contact and mfly get hot enough to melt. Another disadvantage of mechanical relays Ls that
when they switch ON or OFF at high-voltage point, they produce la_rge amount of
electrical noise, called tlec.trom.agnetic interference (EMI).
~;;-]
I Load I perfonnance a t relatively low switching
speed. Because it has switching speed
limitations. On the other hand, at high
""' switching speeds pulse transfonner
\Pulse transformer
provides better performance. At low
switching spet.1(j pulse trnnsformer may get
Fig . 7.49 Isolation using pulse tr~msformer saturated to deteriorate its performance.
Solution : Hardware : Fig. 7.50 shows a matrix keyboard with 16 ke)~ connected to the
8086 microproct..'Ssor u~ing 8255. A matrix keyboard reduces the number of connections,
thus H'lc J)uJnbcr of h\tctlae:iJlg lines.. Jn this: example th~ keyboard with 16 keys, is
Copyrighted mat~rial
Mluoprocessors and Interfacing 7 52 8255 PPI (Programmable Perlpherallntert.ce)
arranged in 4 x 4 (4 rows and 4 columns) matrix. This requires eight lines from the
microprocessor to make aU the connections instead of 16 lines if the keys are connected
individually. The interfacing of matrix keyboard requires two ports : one input port and
one output p<i ri. Rows are connected to the Input Port (return lines) and columns are
connected to the Output Port (scan lines). When aU keys are open row and column do not
have nny connection. Wh~n any key is pressed, it sho ts corresponding row and column. II
the output line of thico column is low, it makes corresponding row line low; otherwise the
status of row line is high. The key is identified by data sent on the output port and input
code rettived from the input port. The following section explains the steps required to
identify pressed key.
0,
o, z-; ~
~ Jt-
Rl! ~
::
MIKJ
-l ""'
; lOW 8
:-
2
""
t:S
5
5 rv
:::jit::
A,
. , I I
>- ...
Copyrighted material
Microprocessors and Interfacing 7 - 53 8255 PPI (Progra'!'mable Peripherallnterfoc.)
Check 2 :
1. Activate keys from any one colwnn by mal<Y'tg any one column line zero.
2. Read the status of return lines. The zero on any return line indicates key is pressed
from the corresponding row and selected column. U the status of alJ lines is logic
high, key is not pressed from that column.
3. Activate the keys from the next column and repeat 2 and 3 for aU columns.
In Fig. 7.50 the scan lines are connected to the port CL of 8255 and return.~ Jines are
connected to the port C u of 8255.
Flowchart
(See flowchart on next page).
Source program
PORTA EQU 0000
PORTC EQU 0004
CR EQU 0006
PROC KEY NEAR
START: t10V AL, 81H Initialize Port C 1 as input and Port Cu
as output
MOV OX, CR I nitialise
OUT DX, AL 8255 J
MOV t\L, OOH
t10V OX , PORTC
OUT DX, AL !<1aka all scan lines zero
BACK : IN AL, DX
AND AL , OfH
Ct1P AL, OFH Check for key release
JNZ BACK If not, wai t for key release
BACK! : IN AL , DX
AND AL, DfH
CMP AL,OFH ; Check for key press
JZ BACK! ; If not, wait fo r key press
CALL DELAY ; wait for key debounce
MOV BL , ODH ; I nitialize key coun t er
NOV CL,04H
NOV Bli , FE!i ; t-1a ke one column l ow
NEXTCOL : t-10V AL , BH
OUT OX, A.L
MOV CH , 04H ; Initialize row counter
NOV OX, PORT A
IN .AL , DX ; Road return line status
Copyrighted material
Microprocessors and Interfacing 7 ~ S4 8255 PPI (Programmable Peripheral Interface)
Call display
-1
Yeo
Copyrighted material
Mlcroprocesson and lnterhocing 7 55 8255 PPI (Progrwnm- Periphenol lnt.rt.ca)
NEXTROW : RCR AL, 1 ; Check fo r one Row
JNC DISPLAY ; I f zero, go to d i splay
; other"<fise continue
INC BL ; I nc rement key counter
DEC CH ; Decremen t row counter
JNZ NEXTROK ; Chec k for next r ow
NOV AL, BH
RCL AL 1 1 Select the next column
MOV BH , AL
DEC c Decrement column count
JNZ NEXTCOL Chec k for last colurnn if not repeat
J MP START Go to start
RET
KEY ENDP
END START
Ex.ample 5 : lnterfrtct' au 8-digit 7 5egmt:nt LED display u.si''S 8255 to tile 8086 microprocessor
sys.li!m and rvrite tm 8086 aS..'it'1nbly larrguase routhr~ to display messag~ on llr~
displny.
Solution : Hardware : Fig. 7.52 shows dw multiplcx<'<l eight digit 7-scgment display
connected in the 8086 system using 8255. In this drcuit port A and port B are used as
simple Jatchf..'CI output ports. Port A provides the segment data inputs to the display and
port B provides a means or selecting a display position at a time for multiplexing ttw
disp~1ys. The 8255 is addressed using di"-"'t nddn!Ssing mode, so only AaA7 lines are used
to dec:ode the addr<.'SSL'S for 8255.
For this circuit different addresses are :
PA OOH PC s 04H
PB 02H CR 06H
TI'le register values are chosen in Fig. 7.52 so the segment current is 80 mA. This
current is required to produce an average of 10 mA per segment ns the d isplays arc
multiplexed. In this type of display system, only one of d1c eight display position is ON at
any given Instant. Only one digit is sel:ted at a time by giving low sigMI on the
corresponding control line. Maximum anode current is 560 mA (7-~<rJnents"' 80 mA =
560 rnA), but d1c average anode current is 7D mA.
Software : Before going to write the software we must know the control word to Pr'Ob"?fam
8255 according to hardware connections. For 8255 Port A and 8 are used as output ports.
Comrol word format f 8255
~R--+-__M_~,__A__~----:-A----+-~-
0 0 X~+---M-~___B__~_PB___~_PC_X~L-41 ~
0 0
Copyrighted material
Hidden page
Mlcroproceoaors and lnwrtaci ng 7 - 57 8255 PPI (Programmable Perlpherallnwrtace)
Program :
MODEL SMALL
. DATA
PA EQU SOH
PB EQU 82H
CR EQU 86H
MES DB 41H,4 2H,4 3H,4 4H, 45H , 46H,4?H,48H
. CODE
; Procedure t o display message o n multiplexed LED displ ay
DISP PROC NEAR
MOV AX,@OATA ( I nitialise
M()VOS, AX data s egment
MOV AL, 80H Load control word in Al,
OUT CR, AL Load cont rol word in CR
PUSH F Save registers
PUSH AX
PUSH BX
PUSH ox
PUSH SI
; set up registers f or display
MOV BX, OSH ; load count
NOV AH , 7FH ; load select pattern
LEA SI , MES ; starting address ot messaq~
display mC:$Saqe
DISPl : MOV AL,AH : selec t diqit
OUT PB, AL
MOV AL , (BXSIJ ; get data
OUT PA, AL display data
Ct..LL DELA'f wait for some time
RDR AH, OlH ; adjust selection pattern
DEC BX ; adj ust count
JN Z DISPl ; r f!p.ea t 8 times
POP SI restore registers
POP OX
POP BX
POP AX
POPF
R1'
OISP ENDP
Note : This procedure must be called C'tmtinuously to display the 7-segment coded
mlossage in the memory.
Copyrighted material
Microprocessors and Interfacing 7 58 8255 PPI (Programmable Perlpherallntertaca)
13 - SLCT OUT This signal Indicates that the printer is in lhe selected state.
14 - -AUTO IN When 1his signal beflg 01 "low" level. the paper is
FEED XT automa~lly fed one IW'Ie after printing, (The signal le~ e&n
bo fix.ed to "lOW" with orP sw pin 2-3 provkfe<f on the oonb'OI
circui1 board).
15 - NC Not used.
Copyrighted material ,
Mleroprocessors and lnterfaelng 7 -59 8255 PPI (Programmable Peripherallnterfaee)
Notes :
1. "Oif\.'(tiM'' ~(e~ to the d irection (l(f signal I'!Qw 115 vitwt'd from the p rinter.
). All intcrfllOc conditJons art ba..~d o n m. leYel. Both the rise and fait times ol each signal must be les&
th.ln 0.2 IJS.
4. Data trilnsk:r must nol 00 c;~ rried o ut by i&noring the ACKNLC or BUSY sfgrol. ~Ia tra.n..;er to this
printer can b.: rarried ou t only afh!r oonfl.rmlng the ACKNLG signal o r when the level of tht BUSY
signal is '1ow"'.
Fig. 7.53 Pin definitions for contronlcil Interface
The other sign.al.s fall into two categories, signals sent to the printer to ten it which
operation to do a nd signals from the printer that ind icate its status. These signal~ ar~ as
follows :
Input slgnal.s for printer :
1. INIT : This signal whe n activated tells the printer to perform its internal
initialization sequence.
2. STROBE (STB) : This signal when activated tells lhe printer that valid data is
available on the d a hl b us.
Copyrighted material
Microprocessors and Interfacing 7 ' 44! .82" PPI (Programmable Periphe ral Inte rface)
3. PE : This activo high signal goe5 high when printer is out of paper.
4. SLCT : This signal goes high If the printer is selected for rC<"Oiving data.
5. ERROR : This active low signal goes low for variety of problem condi tion.~ in the
printer.
Fig. 7.54 shows the timing waveforms for transfer of data characters to an JBM printer
using the basic handshake signals.
BUSY
1- APPROXJMATELY 5 ...
ACKNLG
-1 1- 0.5 (MINIMUM)
Fig. 7.54 Timing waveforms for transfer of data characters to an IBM printer
Copyrighted material
. Microprocessors and Interfacing 7 61 6255 PPI (Programmable Perlpherallnterfacel
Do
Hardware
Do
.... Do
0,
A,
0,
... 2 PC6 w- 0,
iii
R
I
A, 5 N
PC, AcK
""
iOR
i5W
Ro
\iVR
5
PCo
PB,
I NIT
ERROR
T
E
Ro,.. RoSOl P8 1 PE
from8284 PBo
r-' cs BUSY
D >-
Fig. 7.55 Interfacing cen1ronlcs printer to 8255A
ln the next section we will see flowchart and program required to print a message.
Flowchart : Fig. 7.56 Flowchart for printer interface.
No
No
Yes
Port A
. .
Output 1
.
Port 8 Input ! 0
0 1 A2H
110 map :
A,, A,. A,, A1 2 A t1 ... ,. ... ... A, ... ... .... .... A, A, ... Address Port
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OOOOH Port A
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0002H Port B
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0004H Port C
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0006H CR
Program:
. ~fODE L SHALL
Por~A ~QO 0000
PortB EQU 0002
Porte EQU 0004
CR EQU 0006
. DATA
Mesl DB ' Printer Paper Out' , 10 , 13 , ' S'
.. Mes2
Mes3
08 ' Printer Offline' , 10, 1 3 , ' $ '
08 ' Printing Over, ' S'
Mes4 DB ' This is to be print '
COUNT DB 15
.CODE
START : MOV AX , @DATA Initialize da t a se<;ment
MOV OS , AX
LEA BX, ~lE S 4 In itia lize po i nter to string
MOV OX, CR CR i s control register address
MOV AL, OA2H Load control ""'Or d
OUT OX, AL
MOV AL, 07 Ma k e INTE, h igh to e nable INTRA
Copyrighted material
Microprocessors and Interfacing 7 - 63 8255 PPI (Programmabl.e Peripheral Interface)
OUT DX ,AL
~10V AL, OO
OUT DX,AL Make PC0 ~ (BSR mode)
to give ! NIT low
l10V CX, OFFf'H
BACK : or.:c ex Wa it for mo r e than 50 ~
LOOP BACK
MOV AL,Ol
OUT DX,AL Make INIT HIGH
NEXT : t<QV ox, Porta
IN AL,OX
MDV AH,AL ; Save status information
AND AL, Ol H
J NZ CHECK Check for BUSY if high goto
; check
MOV AL, (BXJ
MOV ox, PortA
OUT DX,AL ; Send the character
MDV DX, PortC
AG-'IN : IN AL, OX ; Check for ACK by
AND AL, 08 ; checking I NTR,.. line high
JZ AGAIN
INC BX ; Increment st ring pointe r
t-1CV AL,COUNT
DEC AL
f-iOV COUNT, AL ; Decrement counter
JNZ NEXT Check for counter 0
JMP LAST
CHECK: MOV AL, AH
AND AL , 02
MOV AL,AH Save printer status
JZ CHECK!
LEA DX,>lESl
MDV AH, 09H Call for DOS interrupt
!NT ?!H to display MSl
CHECK! : AND AL, 04
JNZ NEXT
LEA OX, MES2
~10V AH , 09H ; Call for DOS interrupt to
INT 21H ; display MES2
JMP NEXT
LAST LEA DX , MES 3 ; Call for DOS interrupt to
><OV AH , 09H ; display MES3
! NT 2!H
MDV AH , 4CH ; Terminate program
!NT 21H
END START
END
Copyrighted material
Hidden page
8086 Interrupts
8.1 Introduction
Sometimes it is necessary to ha\'e the computer automaticaUy execute one of a
collection of s pecia l routin~ whcnevt>r cert.tin conditions exists within d program or in the
microcomputer system. For example, H is necessary that microcomp uter sytitem should
give response to devices s uch ns keyboard, ~!ilor and other components whc1\ they
reque:;t fo r service.
The most commOt\ method of servking such device is the polled approach. ll'ai~ is
where the proccs..;tu m us t test each device in sequence :.nd in effect "ask.. each one if it
needs communication w ith the pruces.~r. It is easy to sec that a large portion of the main
program is Looping through this continuous polling cycle. Such a me thod would h.wc n
serious and dt..'CTCmental effect on system th roughput, thus limiting the tasks that rovld be
assumed by the microcomputer and n.--ducing the cost e(fect:iveJ''ICSS of us ing su ch deviccs.
A more de.~irablc method would be the one thn t allows the microprOCl.-.ssor to exL>cutc
its main program and only stop to service peripheral devices when it is told to do so by
the device itself. l.n effect. the method, would provide an external asynchronous input that
would inform the pn.>c~-..or tha t it s hould complete whatever instruction that is cUrrently
being executed and fetch a new routine that will service the requesting device. Once this
servicing is completed, the processor would resume exactly w~ it left off. This met:hOtl
is c.-11led interrupt m ethod. It is easy to see that system throughput would d rastically
increase, and thus enhance its cost {>(fcctivern.'SS. Most microprocessors a llow execution of
special routines by in terrupting normal program execution. When a microprocessor is
intcrrupttod. it stops executing its current program cmd ca.Jls a special routine w hidl
NscniccsN the il\tcrrupt. The event that cnu.~-.s the interruption is called interrupt l)nd the
special routine ext.'Cuted to service the interrupt is called interrupt service
routine/procedure. Normal program can be interrupted by three ways :
1. By external s ignal
2. By a special instruction in the pro~'Tam or
3. By the occurrence of some cond ition.
(8 1)
Copyrighted material
Mlcroproussors and Interfacing 8-2 8086 Interrupts
Copyrighted material
Microprocessors and Interfacing 83 8086 Interrupts
INTERRUPT
SERVICE
PROCEDURE
PUSH REGISTERS
MAINLINE PUSH Ft.AGS
PROGRAM CLEAR IF
CLEARTF
PUSHCS
PUSHIP
FETCH ISR ADORES$
POPIP
POPCS
POPFI.AGS
PDP REGISTERS
IRET
Now the qut..~tion is " How to get the values of CS and LP register ?" The 8086 gets the
new values o( CS and lP register from four memory 3ddrcsscs. When it responds to an
inte-rrupt, the 8086 goes to memory locations to get the CS and u> values for the start of
the internlpt service routine. In an 8086 system the first 1 Kbyte of memory from CXXlOOH
to 003FFH is reserved for storing the s tarting addresst.~ of interrupt service routines. This
block of memory is oftC'n called the interrupt vector table or the interrupt pointer table.
Since 4 bytes are required to store the CS and LP values for each intern1pt service
procedure, the table can hold the starting addresses for 256 interrupt !o'Oervi mutine!-'0.
Fig. 8.2 shows how the 256 intcrn1pt poiniCI'S ore arranged in the memory table'.
Each intl'rrupt ty~ is given a number bdwt..'Cn 0 to 255 and the addrC"SS of each
interrupt is found by multiplying the type by 4 e.g. for type 11, interrupt addn..-oss is
11 x 4 = ~~ ~o~ 0002CH
Only fin; t five types Juwe explicit defini tions s uch as divide by zero anct non mas kabJe
interrupt. The next 27 inter-rupt types, from 5 to 31, are reserved by lntcl for u!ie in fu ture
microproctssors. The upper 224 interrupt typl~. from 32 to 255, ar'! available for user fvr
hardware or s.oftware interrupts.
When the 8086 responds to an interrupt, it ilutomntic.llly SOt..'S to the SJX->ci(ied location
in the interrupt vector table to get the starting address o( interrupt serviC\" roul\n(', So \bel'
has to l0c1d these starting addresses for different routines at the s tart of the p rogram
Copyrighted material
Microprocessors and Interfacing 8-4 sols Interrupts
ADDRESS
f-
TYPE 33 POINTER:
(AVAltA&.E) -
r- TYPE 32 POI""ER :
( AVAllABl) -
r- TYPE 31 POINTER:
(RESERVED) -
TYPE 5 PQ(NTER :
f- (RESERVED) -
f- TYPE 4 POlNTEA :
OVERFLOW
-
f-,1BYTE
TYJ>E 3 POlNTR :'leN
INT INSTRUCTI
r- TYPE 2 POINTER :
NON-~SKABl.E -
TYPE 1 POINTER :
r- SINOLESTEP -
CS BASE ADDRESS
r- TYPE 0 POINTER :
OMOE ERROR
- IPOFFSET
'' 16 BITS
I
Fig. 8.2 8086 interrupt vector table
Copyrighted material
Hidden page
Mi~roprocessors and Interfacing 8-6 8086 Interrupts
executes the INTO ins truction, the instruction will simply function as ar. NOP (no
opt>rqtion). However, if the ov~rfl0\'1: flag is set, indjcating an overflow ('rTOr, th~ 8086 wiiJ
cx~J<Cute a type 4 interrupt after executing the INTO .i nstruction.
Another way to detect and respond to an overflow error in a program is to put the
jump if ovcrfJow instruction, (JO) immed_iateJy after the arithmetic inStr\lction. J.f the
overnow flag is set as n resuJt of nrithmetic operation~ execution will jump to tht: addr('SS
s pecified in the jO instruction. At th.is address you can put an error routiN~ which
responds in the way you want to the overflow.
Copyrighted material
Microprocessors and Interfacing 8-7 80861nterrupts
r, 1 T2 1 r 3 1 T4 1 r, 1 r, 1 r, 1 r 2 ) r, 1 T4 1
ADO-A015 --=====~~_!F~L~O~A~J------~---------------2~~~~)
tntetnJpl
type
2. Once the 8086 receives the interrupt type. it pushes the flag register on the s tack,
dear!-1 TF and IF, and pushes the CS l'!nd lP values of the next instruction on the
stack.
3. The 8086 then gets the new value of lP from the memory address equal to 4 times
the interntpl type (number), and CS value fmm memory address equal to 4 times
u,e intt'rrupt number plus 2.
Copyrighted material
Microproces.sors and Interfacing 88 80881nterrupts
lnterTUpt Prlonty
OMde Enor. 1n1 n, lnt 0 HIGHEST
N~.1 ~
INTR J.
SINGlE STEP WWEST
l MAIN PROGRAM
The interrupt Rag is al!tomatically
cleared as pnrt of the response of an 8086 to
NMI J
I DIV I an interrupt. This prevents a signal on the
JNTR input from interrupting a higher
I DIVIDE ERROR
priority interrupt service routine. The 8086
PUSH FLAGS, CS. IP allows NMJ input to interrupt hig:.t,er
CLEAR TF & IF priority interrupt, (or example supp~ that
TRANSFER CONTROl
a rising edge signal arrives at the NMJ input
J IF=O TF = 0 while the 8086 is executing a OIV
instruction. and that the division operation
PUSH FLAGS. CS. IP produces a d ivide error. Since the 8086
CLEAR TF & IF
TRANSFER CONTROL check. for intc.rnol interrupts before It checks
for an NMI interrupt, the 8086 will push the
I flags on the st.lck, clear TF and IF, push the
I EXECUTE NMI I rehtm address on the stack, and go to the
start of the divide error service routine. The
! RETURN IF = 0 IF=O 8086 will then do a n NMI interrupt response
EXECUTE ONIOE and execute non-maskable interrupt service
ERROR ROI.ITINE ~utine. After completion of NMl service
Copyrighled material
Microprocessors and Interfacing 89 80861nlerrupts
ADo Do
'Ro
AD 7 0., ,.., f--
IR 1
IR3
84U 8259
IR;
lm'A lm'A
'"
IR6
INTR INT IR7
Copyrighted material
Hidden page
Mlcropi'OC4Issora and Interfacing 8 11 80861n1errupts
Priority Resolver
The priorily resolver detennlnes the priorities of the bits set in the IRR. The bit
rorresponding to the highest priorily interrupt input is set in the ISR during the (]','TA
input.
Copyrighted material
Microprocessors and Interfacing 8- 12 8086 Interrupts
2. The priority resolver checks three registers : The IRR (or interrupt requests, the
IMR for masking bits, and the ISR for the intermpt request being served. It
resolves the priority and sets the lN1' ~gtl when appropriate.
3. The CPU acknowledges the !NT and responds with an iNi'A pulse.
4. Upon rea>iving an INTA from the CP U, the highest priority ISR bit is set and the
corresponding IRR bit is reset. The 8259A does not drive data bus during this
cycle.
5. A selection of priority modes is available to the progranuner so that the manner in
w h ich the requests are p rocessed by the 82.S9A can be configured to match his
system requirements. The priority modes can be changed or reconfigured
dynamici'llly a t any time during the main program. This means that the complete
interrupt service structure can be defined as required, based on the total system
environment.
6. The 8086 will initiate a second INTA pulse. During this pulse. the 8259A releases a
8-bit pointer (interrupt type) onto the Data Bus where it is read by the CPU.
7. This completes the interrupt cycle. In the A01 mode the ISR bit is reset at the end
of the second !NTA pulse. Otherwise, the ISR bit remains set until an appropriate
EOI command is issued at the end of the interrupt subroutine.
II
Copyrighted material
,,
Hidden page
,Miti'OI!(OC. .IPrs and lnt&rfaelng 8 14 80861nterrupts
l r lx lx l x l xlw. l w, jw, j
I = 1 4 One or more interrupt requests activated.
I =0 -+ No interrupt request activated.
Binary code of h.lghcsl priority active interrupt roqucst.
Copyrighted material
Microprocessors and Interfacing 8-15 8086 ln1errupls
ICW1
NO {SNGL 1)
READY TO ACCEPT
IN'TERRIJPT REQUESTS
Copyrighted material
..I I , I .. I .. I
Microprocessors and Interfacing
0
o, o, o, o,
1
o, 0,
8 -16
o, 0,
I I
- 1 rcw NEEDED
0 NO ICW4 NEEOEO
1SINGLE
0 ,. CASCADE MOOE
._,...,o,..,.._.,.,
VECTOR ADDRESS
{MCS 80f85 MODE ONLY}
~ ~ ~ ~ ~ ~ ~ D, ~
I IA~,,A"f. l"'~sl"~.l"%, 1
I I I I
"o I At "o
A1s-Ao OF INTERRUPT
VECTOR ADDRESS
(MCS80185 MODE)
T rTs OF INTERRUPT
VECTOR ADDRESS
(808618()88 MODE)
Copyrighted material
Mlc:roprocosson and Interfaci ng 8-17 8086 Interrupts
ICW3(MASTER DEVICE)
Ao D, De Ds D, D, D, D, Do
I 1 s, So s.
I
s,
I
s, s, s,
I
So
I
1 = IR INPUT HAS A SLAVE
0 :~; IR INPUT DOES NOT
HAVE A SLAVE
ICW3(SLAVE DEVICE)
Ao D, D. D. D, D, o, D, Do
I I I I I I I I I I
1 0 0 0 0 0 10 2 10 1 IDo
I
0 1
SLAVE ID
2 3 4 5 6 7
I 0
0
1 0 1 0
0 1 1 0
1 0 1
0 1 1
0 0 0 0 1 1 1 1
1 808618088 MODE
0 MCS 801'85 MODE
1 AUTO EOI
0 NOR....-L EOI
1 SPECW.. f'VlLY
NESTEOMOOE
0 NOT SPECIAL FUllY
NESTEOMODE
It specifics.
1) Whelher lo use special fully nested mode or non spedal fully nested mode.
2) Whether to use buffered mode or non buffered mode.
3) Whclhcr to usc Automatic EO! or Normal EO!
4) cru used. 8086/8088 or 80810.
Copyrighted material
Microprocessors and Interfacing 8 1 8 80861nterrupts
After initialisation, the 8259 is read~ to process interrupt requests. However, during
operation. it might be necessary to change the mode of processing the intemapts.
Ot>erabon Command Words (OCWs) are used for this purpose. They may be loaded
:.nytime n(tcr the 8259's initialisation to dynamically alter the priority mocles.
Operation Command Word 1 (OCW1)
A Write command to the 8259 with A0 = 1 (after ICW2) is intorpreted as OCWI.
OCWl is used for enabling or d isabling the recognition of specific interrupt requests by
programming the IMR.
M = 1 indicates tha t the interrupt is to be masked, and M a 0 indicates that it is to be
unmasked as shown in Fig. 8.12.
1 , Mo .... ....
... ..., M3
"' Mo
I I I I I INlERRUPT MASK
1 =MASK SET
0 : MASK RESET
I I I I ~" I I I ... I ... I ... I
0 Sl 0 0
I I
0 I 2 '
' ' '
.
IR lEVEL TO 81! ACT:0 UPON
5 ' 7
..., r
0 0 0 0
0 0 0 0 '
0
' NON-SPE:CIFIC EOI COtoaAANO
SPECIFJC EOI OClUMA.ND
} END Of INTEARUPT
Copyrighted material
Hidden page
Microprocessors and Interfacing 8 . 20 8086 lntaiTUpls
ICW1
1 AOI
0 1 0 13H
Note : When used with an 8086. bit 0 11 0 51 0 4 and 0, a re don't care, so we make
them O's for simplicity.
ICW2
In an 8086 system ICW2 is used to tell the 8259A the type number to send in response
to an interrupt s ignal on the IRI) input.
I ~ I : I ~ I : I :: I : I : I ~ I.
2
20H 32 Decimal
!CW2 for sending interrupt type 32 to the 8086 in response to an IRQ interrupt is 20H
Note : For an IRI input the 8259A will send 00!0000! binary (33 decimal ) and so on
(or the other lR inputs.
ICW3
Since we are not using a stnve in our example, we don't need to send an JCW3.
Copyrighted material
Mlcr_.,cessors and Interfacing 8. 21 80861nterrupls
ICW4
For our example, the only reason we need to send an ICW4 is to let the 8259A know
that it is operating in an 8086 system. We do this by making bit 0 0 of the 1CW4 one.
OCW1
An OCWl must be sent to an 8259A to unmask any IR inputs. For our example we
wnnt to mask IR1 and IR3, so we put l''s in these two bits and O's in the rest of the bits.
I : ! : I : I : I ~ I : I ~ I : I
7
= OAH
Program:
t>IOV AL, l3H ; edge triggered , s ingle , ICW4 n eeded
OUT 40H,AL Send ICWl
l-lOV AL, 20 H .
;
t ype 32 i s first 8359A t.ype
OUT 41H, AL ; s end ICW2
MOV AL, Ol H ; ICW4, 8086 mode .
OUT HH, AL ; s end ICW4
MOV AL, OAH ; OCWl to mask IRl and I R3
OUT 41H, AL ; send OCWl
J... Example 2 :
"ri~l
Write th~ it~itialization instructions for master nud SIIJvt' coufigurntiou to
tlre Jolluwiug spedficntions :
11 Tilt INTR of slnve is rout<d through IR2 of the mnslff 8259A to the 8086.
2J Master and slllvt nrt! both /n~el triggt>rffl.
3) First interrupt types for master and slnt't! are 32 and 64 respectively.
4) Modes : automatic rotation aud aJito tnd of inltrrrtpl.
5) Addrm<S of th mnsltr are #JH nnd 41H and lite slavt are SOH and 8lH.
6) Buffers are not used.
lnitializntion command words for Masft'T JCW1 (Mastn)
ICW1 (master)
SNGL
0 IOH
ICW2 (master)
1 ~1: 1 ~ 1 0 I; I; I ~ I~ I = 20H
ICW3 (master)
1~1~ 1 : 1
s.
0 = 04H
Copyrighted material
Microprocessors and Interfacing 8 - 22 8086 lnterTUpts
Program :
MOV AL, 19H ; level triggered, cascaded, ICW4 needed
OUT 41 OH , AL ; send ICWl {ma ster)
M()V AL, 20H ; type 32 is first 8259A type
OUT 41H , AL ; send I CW2 Imaster}
MOV AL, 04 slave at IR2
OUT 42H, AL send !CW3 (master)
10v AL, 0311 ; 1CW4 , SOS6 mode , and set AEOI
OUT 4 1H , AL send 1CW4 {mastt!' r}
MOV AL, 19H l eve l triggered, cascaded, ICW4 needed
OUT SOH , AL send ICWl (slave)
MOV AL, 40H ; type 64 is fi rst 8259A type
OUT SlH , AL ; send ICW3 {slave}
MOV AL, 02H I D fo r slave connected to IR2
OUT 81H , AL ; send ICW2 tslave)
MOV AL, OlH ICW4, 8086 modo
OUT 81 H, AL ; send 1CW4
MOV AL, SOH OCW2 <rotate in auto EO! mode set command)
OUT SOH , AL send OCY12 {s l ave}
1 1 1 1 1 1 1 1 1 1 1 1 0 0 X 0 FFFOH
F F F 0/2 FFF2H
The 74LS138 address decoder w ill assert the C5 input of the 8259A when an 1/0 base
address is FFFOH or FFF2H on the address bus. The Ao input of the 8259A is used to
Sl:'lect one of the two internal addresses in the device. Ao of the 8259A is connected to
system line Al. So the system addresses for the two internal addresses are FFR)H and
FFF2H. The data lines of an 8259A a re connected to . the lower half of the system data bus,
because the 8086 eXJX'CIS to receive interrupt types OJ\ these lowe.r eight data lines. RD and
WR signals are connected h,., the system RD and WR Jines. ~ interrupt req u~t s ignal
Copyrighted material
Microprocessors and Interfacing 8-23 8088 Interrupts
+5V
A,o - v<X G
Address
bus ~ - "
/ 0:, Yo
A, c
...
A,
B
741.5138
Ao A T +5V
~~1 0 <i, GNO
I I
... SPiEN v<X
Control
L-.. cs IRe, --
bus
RO
AO
R5
IR 1
IR, --
WR
INTR
WFi
-INT
IR3
IR4
--
INTA
Do
o,
INTA
Oo 8259A
IRs
IRe,
IR7
--
02
o,
02 CASo
--
o...
bus
o,
o,
o,
o.
o,
o,
o,
o.
CAS 1
CAS2
-
o, o, GNO
...
Fig. 8.15 8259A interface to 8086 s yste m bus
It-IT from O>c 8259A is connected to the INTR input of the 8086 and INTA from 01e 8086 is
connected to INTA on the 8259A. As we are using single l'259A in the system SP/EN pin
is tied high and CAS.,.CAS, lines a re left open. The eight IR inputs are available for
interrupt signals.
Note :
1. Unused IJ< inputs should be tied to ground so that a noise pulse cannot
accidentally cau.<soe an interrupt
2. ln rna.x:imum mode RD and INTA signals of 8259A ar~ connected to the IORC,
IOWC and !NTA lines of 8288 bus controller.
Copyrighted material
Microprocessors and Interfaci ng 8. 24 8086 Interrupts
Cascading :
The 8259A cnn be- ~asily interconncctOO to get' multiple interrupts. Fig. 8.16 shows how
8259A can be conn<.-*<:'ted in the cast(lde mode. In cascade mode one 8259A is configured in
Moster mod~ <\nd other should be configured in the Slave mode. In thio; figure 8259Al is
in the master mode and others are in slave mode. Each slave 8259A is identified by the
number which is assigned as a part of its initiaUzation. Since- th(' 8086 has only one lNTR
input, only one of the 8259A fNT pins is connected to the 8086 INTR pin. The 8259A
connected directly into the 8086 INTR pin is referred as the master. The lNT pins from
other 8259A are connected to the lR inputs of the masrer 8259A. These cascaded 8259As
are referred as sla\ :. The INTA signal is connected to both master and slave 8259A.
(S<e Fig. 8.16 on next page.)
The C..'lscadc pins CASo to CAS2 are connected from the master to the corresponding
pins of thl! slave. For the master these pins function as outputs. and for the slave these
pin,'it function as inputs. The SP/EN signal is tied high for the mas ter. However it is
grounded for the s lowe.
Each 8259A ha.o; iL'j own addres.o;c~ so that command words can be written to il and
status bytes read from it.
Addresses for 8259As :
8259A-2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 X 0 FFF4H
F F F 4/6 FFFSH
82S9A3 1 1 1 1 1 1 1 1 1 1 1 1 1 0 X 0 FFF8H
F F F 8/A FFFAH
Copyrighted material
Hidden page
Mlc:roprocessors and lnterfac:ing 8. 26 8086 Interrupts
Solution : Hardware : The Fig. 8.17 shows simple circuit that generates intem1pt request
after every 0.5 sec.
39pF 330K
.r~-'WIIr~-lo
15M 4060
Copyrighted material.
Hidden page
' ; 1;
Microprocessors and Interfacing 8-28 80861nterrupts
JNZ DONE
MOV HR, OOH ; Reset HR - 00
DONE : POP SI ; restore register s
MOV AH , 00
I {lET
TIMES ENDP
END START
l.ENf
Review Questions
1. Wlrat do you mevJn by fntt>rmpt ?
2. Wltnt is intemrpl ~rola routiu~ '!
3. Wl111l arr 11~ sourm of h1trrrupt5 ;, 8086 ?
4. Wllat il_iult'rmpt Vt1"tor fllblt> ?
5. Orotuaud explnltl fht IVT for 8086.
6. Brt.'fty. t4-'SCJ'i~ ihe conditions wllicll CIJII~ tile sas6 to pt'rform mch of the following 'YIN'S of
iuttrmpts : Typt 0, Type L Type 2. Typt 3 and Typt 4.
7. Explain itiUhitpl' structure of 8086.
8. Wlrat are sojt'roJ~,. inf("rmpt ? How 8086 ll'Sponds to 5Qftwn intuntpts ?
9. Draw and c).rltliu tf11! internrpt ncknowlc>.dgt cycle of 8086.
10. Dt'S(Tibc. tlrt' rtSporr~ of 8b86 to 111~ int~rrupl coming em pi~.
l 1. WJtal do you memr by i11terrupt priorities ?
12. Stolt" tltC' intNTupt priorities for 8086 inturupts.
13. Wllat On! advmttogN of 1Lii11g 8259 ?
14. LiM tl1e footures of 8159.
15. Expl!liJI l.fle operating modes of 8259.
16. Draw amJ I*Xplm'n til~ itrlt'rfndng of 8259 tvilh 8086.
17. Drnw nnd rxplniu llu hrt~rftm'~tg of cttscndtod 8259s with 8086.
18. E.xplsdn lht pro.:wlurt of lutt'rrupt programming.
ODD
...
'
Copyrighted material
Introduction to DOS and
BIOS Interrupts
In IBM PC. part of the operating system is located in the permanent memory (ROM)
and part is loaded during power up. The part located in ROM is referred to as
ROM-BIOS (B-sic Input/Output System). The other part which is loaded in RAM during
power-up from harddisk or Ooppy disk is known as DOS (Dis k Operating Systom).
BIOS is located in an 8Kbyte ROM at the top of memory, the address range being
from FEOOOH tO FFFFFH. The progra.m s within ROM-BIOS provide the 1110St direct. lowest
level intcrttction with the various devices in the system. Tile ROMBIOS contains routiru.~
for
1. Power~on self test
2. System configuration analysis
3. Time-of-day
4. Print screen
S. Bootstrap loader
6. l/0 support prog'"m for
a. Asynchronous communication ...
b. Keyboard
c. Diskette
d. Printer
e. Display
Most of t~ progr<lms are accessible to the assemblylang,uage programmer through
the software interrupt instruction (!NT). The d<'Sign goal for the ROM-BIOS programs is tO
provide a device-independent interface to the various physkal devices in the system.
(9 1)
Copyrighted material
Mieroprocessors.~,nd Interfacing 92 Introduction to DDS and BIOS Interrupts
It is seen that ROM-BIOS provides basic low-level services. Using ROM-BIOS one can
output characters tp_ various physical deviet.'S lik(> the printer or the d isplay monitor, one
can read characters from keyboard, one can read or write sectors o( data to the diskette.
But still (ew things we can't do with ROM-BIOS.
1. It is not possible to provide ability to load and execute programs directly.
2. It is not pos$ible to store data on the diskeHe organized as logical files.
3. ROM-BiOS h.(I.S no command-interpreter to allow us to copy fllcs, print files, delete
files.
It is DOS tha t provides these services. When we tum our computer ON, we exp~t to
SL->e a mcssoige or a prompt. We except to be able to look a t ~ diskette directory to see
what data files or programs the diskette contains. We expect to run a program by typing
its name. We want to copy programs from one diskette to another, print programs, and
delete progra~1s. All tl1esc scrviees are provided by group of programs "''lied DOS. The
service:; provided by DOS can be grouped into following categories.
1. Character Davie" .UO : This group indudes routineti that input or output characters
to character oriented devices such as th(' printer, the display monitor, and the keyboard.
2. File Management : This group includes routines thai manage logical Iiles, allowing
you to create, read~ write a nd delete rues.
3. Memory Management : Thi,. group includes routines that alJow us to change..
a llocate, and deallocate memory.
4. Directory Management ; This group includes routines tha t permit us to create,
change search.. and delete d irectories.
5. Executive Functions : This group includes routines that aUow us to load and execute
programs, to ov('rlay programs, to retrieve error codes from completed programs, and to
execute commands.
6. Command Interpreter : This routine is in action whenever a prompt is present on lh e
screen. It intcrpre!f. commands and executes DOS functions, utility programs, application
programs.. depending upon the command.
7. Utility Programs : These programs facility to copy, delete provides lhe DISKCOPY,
DIR and m(lny other DOS commands.
Copyrighted material
Hidden page
MlCtOprocusors'ih!fjnterfaclng 9-4 Introduction to DOS and BIOS Interrupts
Used by program that need to read and wrire all p<l5Sible characters and control codes
without any interference from the operating system.
Reads a character from the standard input device or writes a character to the standard
output device. 1/ 0 may be redirected.
Calling parameters
AH 06H
DL = fu nction requested
OOH-FEH if output request
OFFH if input request
Returns : Nothing, i f called with DL c OOH OfEH
If called with OL Ff'H and a character is ready returns
Zero fla g = clear
AL '"' 8-bit input data
If cal led with OL = FFH and no character is ready
Zero _ {lag set
! jj.
Reads a charac~r"'from the standard input device without echoing it to the standard
output device. If no character is ready, waits until one is available.
Calling Parameter
J\H 07H
Returns
AL 8-bit input data
Example : Read a character from the standard input without echoing it to the display,
and store it in the variable char.
char db 0 ; input character
Copyrighted material
Hidden page
Microprocessors and Interfacing 9-6 Introduction to DOS and BIOS Interrupti
If the buffer fills to one fewer than the maximum number of characters it can hold,
subsequent input is ignored and the bell is sounded until a carriage return is detected.
Example : Read a string that is maximum of 80 characters long from the standard
input device, placing it in the buffer named buffer
buffer db 81 ; maximum length of input
db 0 ; actual length of input
db 81 dup (0) ; actual input placed here
Copyrighted material
Microprocessors and Interfacing 9-7 Introduction to DOS and BIOS Interrupts
lnt 21H Flush Input buffer and then Input Function OCH (12)
Clears the standard input buffer and then invokes one of the character input functions.
Input can be redirected.
Calling parameters
AH = OCH
AL = number of input fu nction to be invoked
after resetting buffer (must be OlH , 06H ,
07H, OSH, o OAH)
(i f AL OAH)
DS : DX = segment :offset of input buffe
Sends a string of characters to the standard output device. End of string is indicated
by character $ (24H).
Copyrighted material
Microprocessors and lntarfacjng 9 -8 Introduction to DOS and BIOS Interrupts
Calling Parameters
1\H 09H '
OS = segment : offset o f string
Returns : Nothing
Example : Send the s tring, followed by n carriage return and line feed, to the st."lndard
output device.
cr equ Odh
l E equ Oah
msq db ' MICROPROCESSOR', cr , l!,' $'
Copyrighted material
Hidden page
Microprocessors and Interfacing 9-10 Introduction to DOS and BIOS Interrupts
mov ds, dx
mov d x,. offset myfcb
i nt 21h trans fer to MS-OOS
o r al. al ; check status
jnz error ; jump if close failed
Dclcles all matching mes from the current directory on the default or specified disk
drive.
Calling parameters
AH = l3H
DS : DX s egment : offset o f fi le control b lock
Returns:
If function successful (file or files deleted)
AL ' = OO H
If function unsuccessful (no matching files were found, or at least one matching file
was read-onJy)
AL ~ FFH
Example :
Delete the file TEST.DAT from the current dL<k drive and directory.
myfcb db 0 drive default
db ' TEST' f ilena me , 8 characters
db ' OA'l" e x tension , 3 characters
db 25 dup ( OJ remainder of FCB
Copyrighted material
Microprocessors and, Interfacing 9 -11 Introduction to DOS and BIOS Interrupts
Re\lds the next sequential block of data from a file, then increments the file pointer
appr<>priately.
Calling parameters
AH 14H
DS : DX = segment : offset of previously opened file
control block
Returns
AL = OOH if read successfu l
OIH if end of file
02H if segment. -,.rap
03H i f partial record read at end of fi l e
Example .: Read 512 byt.,. of data from the file spe<:ified by the previous ly opened file
control block myfcb.
myfcb db 0 drive = defau lt
db ' TEST' filename , 8
characte rs
d.b ' OAT' extension , 3
characters
db 25 dup (0 ) remainder of FCB
or al , al ; check status
)n error ; j ump if read fa iled
Writet the next sequential block of data from a file, then increments the file pointer
appropriately.
Copyrighted material
Hidden page
Microprocessors and Interfacing 9 13 Introduction to DOS and BIOS lntetTUpls
Exampt. : Create a file in the current directory using the name in the file control block
myfcb.
ay!cb db 0 ; drive default
db ~TE ST' ' ; H lcnA.t:li&, 8 characters
db ' OAT' ; e x tens ion, 3 charact.rs
db 25 dup 101 I remainder of res
Allers the name o( all matching files in the current d.irectory on the disk in the
specified drive.
Calling parameters
AH = l7H
os : ox = seqment:offset of '"'specia l .. file control
block
Retums : If function successful (one or moc files arc renamed)
IlL = OOH
II function wtsuccessful (no matching files, or new filename matdu.od rm cxbting fiJe)
AL = FFH
Microprocessors and Interfacing 9-14 Introduction to DOS and BIOS Interrupts
Searches for a matching fLJe in the current directory; if one is found~ updates the FCB
with the file's size in terms of number of records.
Calling Parameters :
!\H 23H
DS:OX segment : offset of unopened fi l e control
block
Returns : If function suocessh~ (matching file found)
!\L = OOH
a"d FCB relative-record field (offset 21 H) set to the number of records in the file.
If function unsuccessful (no matching file found)
AL = FFH
Copyrighted material
Hidden page
Microprocessors and Interfacing 9 - 16 Introduction to DOS and BIOS lnterru~
Ir function.
fa iled
Carry flag = set
AX = error code
Example : Crea te and open,or truncate to zero length a1\d open, the file
C : \ 1-JBS\PROl.ASM and $3ve the handle for ~ubsequent
access to the file.
fname db 'C: \M.BS\PROl.ASH', 0
handle dw ?
Calling ParametO<S
1\H 3DH
Copyrighted material
:: 2',(,
Mi.CI;OP<Q~:easors a!)d lnlllrfaclng 9-17 lnlroductlon to DOS-andBIOS Interrupts
Example : Open the file C:\ \ PROI.ASM for both reading and writing, and save the
handle for subsequent ac:ccss to the file.
fname db ' C o \~IBS \ PROl.ASM',O
fhandl e dw ?
Given a handle that was obtninl' \1 by ~' previous succLossful open or create operatiun,
flushc."S all internal buffers associated with the file to disk.. doses the file, and releases the
handle for rcu~. If the file was modiik-d. the time and date stamp and flit> :o>izt .ur
upd.ltt.od in the filt.'s d irectory entry.
Copyrighted material
9 18
.
Introduction to.DOS and BIOS Interrupts
Calling Parameters
AH = 3EH
BX handle
C ivcn a valid file handle from a previous open or create operation. a buffer address,
and a length in bytes, transfers data at the current file-'pointer position from the file into
the buffer and then updates the file pointer position.
Calling Parameten
AH 3FH
BX = h andle
ex number of bytes to read
OS:DX = segment : offset of buffer
Rotu<ns : If function successful
Carry fla g = c lear
AX bytes transferred
lf function unsuccessful
Carry fla g set
AX = error code
Examp&e : Using the fill' handle from ~ previous open or create operation, read 512
bytes at the current file pointer into thll! buffer named buff.
Copyrighted material
Introduction to DOS- B IO&Inlerrupls
-
mov ah , Jfh ; f unction number
mov dx, seq buff ; buffer address
mov ds , dx
mov dx, offset buff
mov bx, fhandle ; file hand le
i ~
mov ex , 51 2 ; length to read
int 21h ; t ransfer to MS-OOS
jc error ; jump, read fai l ed
cmp ax , e x ; check length of read
jl done ; jump, end of file
Given a valid file handle from a previous open or cre01tc opc:rtttui"n, i'l buffer address,
and a length in bytes, transfers data from the buffer into the file an!! then updates the file
pcJinter posi lion.
Calling parameters
AH = 40H .,.
BX handle ..
ex .. number of bytes to write
DS:DX = segment:offset of buffer
' .
Copyrighted material
Mlcroprocess~m .':>.d Interfacing 9-20 Introduction to DOS and BIOS Interrupts
.... .
mov ah, 40h ; function number
mov dx, seg buff ; butter address
mov ds , dx
mov dx, offset buff
mov bx, f handle file handle
mov ex, 512 ; l ength to write
int 2lh ; transfer to MS- OOS
jc erro r jump, failed
write
cmp ax, 512 entire record writ t en?
jne error no , jump
Copyrighted material
.,, .
M_lcroproc:eosors"anel.lnterfaclng 9 21 Introduction to ooaanc'I.Bios lntenupts
INT21H Move file pointer Function 42H (66)
DOS maintains a file pointer. The open file operation initialize file pointer to 0 and
subsequent sequential reads and writes incr~ment file pointer by record.
Calling pararMtors
1\.H 42H
AL = method code
OOH absolute offset from start of file
Ol H siqned offset from current file poi nter
02H signed o ffset from end of fi l e
BX handle
e x = most sign ificant half of offset
OX l east signficant hal f of offset
.... ,~
Copyrighted material
I Z2 ;.. -.ction to DOS end BIOS lnlerrupta
Example : Change the name of the 61e.~~.DAT in the directory \MYDIR on drive
C to MYTFXT.OAT. At the same time. n\oYi! .11\e 6Je to the directory \SYSTEM on the
same drive.
oldname db 'C: \ MYDIR\ MYFILE.OAT' ,0 ; drive defau l t
newname db ' C: \SYSTEM\ MYTEXT.DAT' ,0
mov ah ,
56h function number
mov . '
dx , seq oldname old filename address
mov ds , dx
mov dx, oft set oldname
mov di, seq newname ; new fi lename address
mov es , di
mov di, offset newname
int 2 lh ; transfer to MSOOS
jc error ; jump i f rename
; fai l ed
Allocates a block of memory and retums a poinrer to the beginning of the allocated
an.--a.
Calling paramete rs :
AH 4811
BX ~ number of paragraphs of memory needed
Copyrighted material
t 23 tntroduc:tion to DOS UKI BIOSint.nupa
ReleOS<!S a memory block and makes it availilble for use by other programs.
Calli"ll parameters :
AH = 49H
es segment of b loc k t o be released
Returns : If function succes..~ful
Example_: Releose the memory block tl>at was previously allocated in the example for
21H Function ~SH.
bufseg dw ? ; segment base of block
Copyrighted material
Hidden page
Microprocessors and 'Interfacing 9 - 25 Introduction to DOS and BIOS Interrupts
Returns :
AX = amount of e x tended memory {in KB)
Selects thl' current video dis play mode. Also sele<:ts the active vidoo controller, if more
than one vidro controller is present.
Calling Parameters
AH = OOH
AL '"' video modes
Returns Nothing
ook>rburstoff
Ot H 40-by-25 16 text
Copyrighted material
Introduction to DOS and BIOS Interrupts
Mic:,roprocessors and lnterfac;,,lg
-9-26
09H 320-by-2(;0 I 16 gralll1k:O
OAH 640-by-200 4 ~ralll1ico
OBH reserved
OCH esorved
ODH 320-by-200 16 graphics
Selec-ts the starting and ending lines for the bUnking hardware cursor in text display
modes.
Calling Parameters :
AH OlH
CH bits 0 - 4 = starting l ine for cursor
CL bits 0 .. 4 endi ng l ine for cursor
Note : Cursor om be disabled by se1ting CH = 20H
Retumo : Nothing
Returns : Nothing
Mlcroprocesaors end tnt.rfaclng 9-27 Introduction to DOS and BIOS lnttrrupts
Obtains the C\Jrrertt position of the cursor on the display, in text coordinates.
Catling Parameters :
AH = ' 03H
BH page
Returns :
CH starting l ine for cursor
CL = e ndin9 line for curso r
OH row (y coordina te }
DL = co l umn (x coordinate)
Writes an ASCR character and its a ttribut~ to the display at the current cursor
position.
C.lllng P.ameters :
AH = 08h
AL = character
BH page
BL attribute (text modes) or color
{graphics modes)
e x = count of characters to write
(replication f a ctor)
Return& : Nothing
Writes an ASCU character to the display at the current cursor position. The character
receives the attribute of the previous character displayed at the same po5ition.
Cdlng Parameters :
AH = OAH
A.L character
BH = page
BL = color
ex = count of characters to write
(repl i cati on factor}
Retumo : Nolhillg
Copyrighted material
Hidden page
Mlcropr.ocessors and Interfacing 9. 29 Introduction to DOS and BIOS Interrupts
Sends a character to the specified parallel printer interface port and retum~ the current
status of the port.
Calling parameters :
AH = OOH
AL character
OX = pri nter number (0 LPTl, 1 ... LPT2,
2 = LPT3)
Returns :
AH status
Bit Significance (if s et)
0 printer timed- out
1 unused
2 unused
3 I/0 error
4 printer selected
5 out of paper
6 printer acknowledge
7 pr inter not busy
initializes the specified parallel printer i_nterface port and returns its status.
Calling parameters :
AH = O! H
OX printer number (0 ~ LPTl, 1 LPT2 ,
2 = L PT3 )
Retums :
AH status (see lot 11H Fu nction OOH)
Copyrighted material
Microprocessors and Interfacing 9-30 Introduction to DOS- BIOS Interrupts
Retun't~ the current status of the specified p;1rclllel pri_n tcr interface port.
Calling parameters :
l\H 02H
DX ""' printer number (0 LPT l , 1 = LPT2 ,
2 ~ LPT3)
Ratums :
AH = sta t us (see Int 17 H Function OOH)
(J(J(J
Copyrighted material
10~----------------~
Serial Communication
10.1 Classification
Serial dntn transmission can be classified on the basis of how transmission occurs.
l. Simplex
2. Half duplex
3. Full d~plex
10.1.1 Simplex
ln simplex, the hardware exists such that data transfer tak.L--s plact' only in om.
direction. There is no possibility of data transfer in the other direction. A typical cxampl(
is transmission from a computer to the printer.
(1 0 1)
Copyrighted material
Microprocessors and Interfacing 10.2 Serial Communicatior
10.2.1 Asynchronous
Fig. 10.1 shows the trnnsmission format for asynchronous transmiss ion. Asynchronou:
formats oH\' ch.u.lctc-r oric.-ntcd. In this, the bits of a character or data word are sent at
constant rate, but characters can come at any rotc (asynchronously) as !ong as they do no
overlap. Wh~n no"characters are being sent. a line stays high at Jogic 1 called mark, logic (
is ~1II L'tl space. Tilt.> beb..Jnning of a character is indicated by a start bit which is alway:
lu\\'. This i~ used tu synchro1\ize the tran.~mith!r and receiver. After the s tart bit, the dat.:
bit:~ nn. stJH with INst significant bit first, followed by one or more s top bits (active high)
Tht:. !\top l>it:-o indicate the end o( character. Different systems use 1, 1 1/2 or 2 stop blts
Th~o. ~,... mN n.ltion v( s tart bit. character and s top bits is known as frame. The start and s tar
bib co.1rry n o inforn1Z1tkm, but are required because of the asynchronous nature of data.
Fig. 10.2 illustrates how the data byte CAH would look when transmitted in t~
asynch runnu~ SCrii-11 format.
Tronsmittt~t Reoeiller
CLK CU<
rome
Fig. 10.1 Transmission format for asynchronous transmission
1 $101) bll
Transmittet Receivec
Tome - --
10.2.2 Synchronous
The start and s top bits in each
I - I
"""' frame of asynchronous format
represents wasted ove rhead bttes
s,...l-1 I I I I I tha t reduce the overall character
T~l!lllr
"""'H
-
o... rate. Th~ .~tart and s top bits can
Tlnut -
be climinated by synchronizing
receiver and trAnsmitte r. They can
Fig. 10.3 Synchronous transmission format be synchronized by having "
common dock signal. Such a
commul'tication is called synchronous serial communication. :rhe Fig. 10.3 shows the
tran~m ission format of synchronous sc-rial commw'lication. . ln th is transmission
synchr01'10US bits are inserted ins tead of start and s top bits.
4. Data ttanSfer is Character orien ted. Oats tmnsler takes pface tn block.$.
Table 10.1 Comparison between asynchronous and synchronous serial data transfer
Copyrighted material
Mlc:toproc....,... andilnterfacl ng 10-4 Serial Communication
'The devices are designed for his purpose are called universal asynchronous
receiver-transmitter (UART). The devices which provides synchronous as weU as
asynchronous transmission and reception are called as universal synchronous
asynchronous receiver-transmitter. A good example of UART is 8250 and USART is 8251.
'These devices are software programmable for number of data bits$ parity and number of
stop bits. In the next sections, we discuss the 8251 (USART).
10.4.1 Features
1. The lntcl 8251A is an universal synchronous and asynchronous communication
controUer.
2. It supports standard asynchronous protocol with :
a) 5 to 8 Bit character format
b) odd, even or no parity generation and detection
c) Baud rate from DC to 19.2 Kbaud
d) False start bit detection
e) Automatic break detect and handling
f) Break character generation.
3. It ha..i built in baud rate 8'--nerator.
4. It supports standard synchronous protocol with :
a) 5 to 8 Bit character format
b) Internal or external character synchronization
c) Autom..'llic sync insertion
d) Baud rate from DC to 64 Kbaud
Copyrighted material
Microprocessors and Interfacing 10.5 serial Communication
o, o,
o, Do
""' Vee
;;;c
o, OrR
o, RTS
o, DsR
RESET
CLK
TICE:mpty
CTs
SYN OET 180
T11ROY
Data Bus : Bi-directional, tri-state, 8-bit Data Bus. Thlc; pin aJiow transfer of bytes
between the CPU nnd the 825LA.
RO (Read) : A low on this input allows the O'U to read data or status bytes from
8251A
WR (Write) : A low on this input allows the CPU to write data or command word to the
8251A.
Copyrighted material
Hidden page
Microprocessors and Interfacing 10.7 Serial Communication
TxC (Transmitter Clock) : This dock input controls the rate at which thE: character is to
be transmitted.
Receiver Signals
RxD (Receiver Data) : This input receives a composite serial st:reilm of data on the
rising edge ol RxC.
RxRDY (Receiver Ready) : This output ir'ldicatcs that the 8251A contains a charact..,r
that is redy to be input to the CPU.
RxC (Receiver Clock) : This clock input controls the r.th: at which the character is to be
received.
SYNDET (Sync Detect)/ BRKDET (Break Detect)
This pin is used in synchronous mode for detection of synchronous characters and
may be u!'Cd as either input or ou tput.
In asynchronous mode this pin gtX'S high if receiver line stay~ low for more than 2
character times. It then indicates a break in the data s tream.
When used as an input (external sync detect mode) a positive ~ignal will cause the
8251A to s tart receiving data characters on the rising edge of the next RXC.
....
Dal
bufter
L -"
~
Transmit
buffer
(P- S) - r.o
l
RESET -
c
Cl~
;;-
~::::
R-
"""""'
logic
Transml' -- TxROY
TE
w
ccntrol
- fie
cs
'
_., -
SR -
- -
Rooeive
TR --< Modem buffer
(S-P)
S --<
In~ - -
data bus
"-
- ReoeNe
Copyrighted material
Hidden page
Mlcroproceaors and Interfacing 10 10 Serial Communleallon
Character r.ngth
00- Sbits
01-6bits
10-7 bits
11-8 bits
Copyrighted material
Mlcroproce..on and Interfacing 10 - 11 Serlal CommunicatiOn
--
IEHIIRJRTSl<R lbiO l<>lli1T<Hj
&let* """' ft!IOIOit.
1
--
"'*' ....,.,.. lOr
~~
I I
-
- 12$1 IOmodle
A~t10Mnd
1~RTS
---
t EtM1t1it DTR
Ft.ot~.... 4INible
I ENIH
0 """"'
Error~tel Sind br"ll ~let
1 RtMI tff'1)f A.-gt 1 fi':oroes T')O 'LOW"
PE.OE,F 0 Norm,. Cperllion
'(Hat no elf.a inAsync: li"'Ide)
Ho4e :Error re&et must be perlorme<l-'!enev.r
RX et~ebfe a~ en1e.r N.lnt are l)fDgfammecl
P111rity Eri'Of'
The PE ftag It a.ec ~on a1)anty error Is
dlOI;Iod, II ._ roto~ by lhe ER bit of the
command ll\l.lruclion, PE duel not inhibit
operaUOI'I of lht 8215 1A
Overrun IIN'or
TM oe ftllg le ... .,........ the CPU doos
1'101 read chereetef befor. the Mlll or-.
beComH av...ble II t. , .... bV the ER
bllottn.~ ~ oe: ~
nollnhlbic ~Of h 82151 A. fto.eYef,
--~~~-bit.
_I Dt.IJ , ,.My:
ln<JiCatn IMt ,,. DSR l t e :.t~ levet.
Error Definitions
Partty Error : At the tjme of trc1.nsmission of data an even or odd parity bit is inserted in
the data s tream. At the receiver end, if parity of the character does not match with the
pre-defined parity oarity error occurs.
Overrun Error : ln the receiver section received character is s tored in the receiver buffer.
The CPU is supposed to read this character before r~ption of the next character. But if
CPU fails in re:1ding the character loodcd in the receiver buffer, the next the received
chamcter repl:lccs the previous one and the OVERRRUN Error occurs.
Framing ErTor : lf valid stop bit is not detected at the end eac-h character framming
error occurs.
All these errors, when occur, set the corrosponding bits in the s tatus register. These
error bits are reset by setting ER bit in the command instruction.
Transmission can be C"nabled by setting transmission enable bit (bit 0) ln the command
instruction. When transmitter is enabled and ffi = 0 the transmitter is ready to transfer
data on TxD Hne.
Operation : When transmitter is ready to transfer data on TxD line, CPU sends data
character and it L~ Jo:1ded in the transmit buffer register. The 8251A then automatically
adds a start bit (low level) foUowed by the data bits (least significant bit first), and the
programmed number of STOP bil(s) to each character. It also adds parity information prior
to STOP bil(s), as defined by the mode instruction. The character is then transmitted os a
serial data stream on the TxO ou~ at the falling edge of TxC. The rate of transmission is
equal to I, }{6 or y64 that of the Tl<C, as defined by the mode instruction. Fig. \0.9 shows
the transmitter output in the asynchronous mode.
Copyrighted material
Mlcroprocenors and lnterfadng 10 - 13 Serial Communication
"
TxO Matklng Slart
Oata bits Parily s
bil bl< bll(
((
RxO
Sync:hronous Transmission
Ttansmlc;sion can be enabled by setting tran.o;mission enable bit (bit 0) in the command
instruction. When transmitter is en.."lbled and crs = 0, the transmitter is ready to transft-r
data on TxD line.
Open~tion : When transmitter is ready to transfer data on TxD line, 8251A transfers
characters serially out on the TxD line a t the falling edge of the TxC. The first character
usually is the SYNC d1aracter.
Once transmis.'tion has startect the data stream at the TxD output mlL">l continue ~t the
TXC rate. II Cl'U does not provide 8251A with a da"' character before transmitter buffers
become empty, the SYNC characters will be automatically inserted in the TxD da"' stream,
as shown in the Fig. 10.11. In this case, the TxEMP'IY p in is raiS<.od high to indicate CPU
that transmilter buffers are empty. The TxE.MPTY pin is internally reset w he:n CPU writ<.>S
data character in the transmitter buffer.
TxEMPTY ------'~ \ \ \ \ \ \\
Copyrighted ma!;:rial
Microprocessors and Interfacing 10 -14 Serial Communication
Synchronous Reception : Rcccption can be enabled by setting receive enable bit (bit 2) in
the command instruction.
Operation : In this mode chMiKier synchronization can be achieved internally or
externa lly.
Internal SYNC To detect the SYNC character 8251A should be programmed in the 'Enter
H UNT mode by setting bit 7 in the commrmd insturction. Once 8251A enters in the ' Enter
HUNT' mode it s tarts snmp ling data on the RxD pin on the rising edge of the RxC. The
con ~ent of the receiver btlffer is compared at every bit boundary with the first SYNC
char:<cter until a ma tch occurS. If the 8251A has bet..:.n programmed for two SYNC
characters, the :mbsequent SYNC characters are compared until the match occurs. Once
8251 A det.;.'CIS SYNC character(s) it enters from 'HUNT' mode to character synchroniz,-, tion
mode, and s tarts receiving the data characters on the rising edge of the next RxC. To
indicate that the synchr<mi~a tion is achieved 8251 A sets the SYNDET pin high. It is reset
<lUtomatically when CPU reads the s tatus register.
External SYNC
In the extem<1l S.YNC mode, synchronization is achieved by applying a high level on
the SYNDET pin, thlL< forcing the 8251A out of the HUNT mode.
0
DoO,
o, TO
Reset oot Reset FbO
Clock out CtK
MilO
Ro ::> RO
Ao 8251A
ViR
WR
-
FbC From...,.
A, cii5 generator 01
- TxC
cs
CTs GNO
T I
Copyrighted material
Microprocessors and Interfacing 10- 15 Serial Communication
110 Map :
A, A, A A, A2 A, Ao
Data Register 0 ""
0 0 0 0 0 0 0 OOH
.
Do-07
rxo
RxO
Reset out Reset
Ck>ck out CLK
Ml iO ...
VRO Ro
Ao ......, 8251A
WR
WR
RiC From pulse
'; A, Clii generator or
TxC timet
cs
..
~
CiS GNO
l I
- c.
Fig. 10.13 Interfacing of 8251A with 8086 In memory mapped 1/0
Copyrighted material
Microprocessors and Interfacing 10 16 Serial Communication
110 Map :
Regis.1et ..... A,. A,, A,. A,, ..... Au A,. Au ... .. ... ... ... ...
A, .... A, .... A, Ao Addrus
Oala 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OOOOOH
Register
COntrol 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 00002H
Rogisler
Fig. 10.14
Command word for given specification is as follows.
I I I I J
..,....
No~ . . .
_ II
I
I I
I
llH
'-
iffii- 0
.,.._
,.,._
RTSo
....... ...._
Fig. 10.15
Copyrighted material
Mlcroproceoooro and lnterfoclng 10 17 Serial Communication
Program :
t<!OV IlL, OOH
OUT 81H , IlL
OUT 81H , AL
OUT 81H, AL Dummy mode "'ord
MOV AL, 40H Reset command word
OUT 81H, AL ; Reset 82$1A
MVI AL, 71H ; Mode word incilization
OUT 8 1A, AL
MOV AL, JJH : Command vord initialization
OUT 81H, AL
Note : Before initialization of the 82SIA. the dummy mode word and the reset
command are sent to the control register. lnihally control n.~tcr m.y have any random
word; therefore. it is a good pl'liCtlc< to~ the 82SIA. However, it eocp1s lhe instruction
as a mode word followed by lhe command word. Therefore, lhe """'t command is sont
afler sending three dummy mode word. which are recommended lo avoid problems
when it is turned on.
PtotoetiY ground
'
SecondWy Trentmllt< <lfll.f
" 2 Tren1mlfttcl <IRa (T X 0) - 00E
Tti11111T115Sion 1lgnN t41mtnllltning (OCE ~~
Secondlry ,~ Clal.f ,,
1$ ) Rt041Md dltt (R X D)
Rtqunt to Mnd (Itt$)
OlE
OCE
R~ aiOnal element timing (DCE aource)
u~-
"
$ QNr to lend (CTS)
Oat , ,..dy (D~)
OlE
OlE
- -
s.cono.ry fi!QUtlt to Mncl 18 7 Slgf\11 GrOUnd
OCE -o.ta lerminll I'Ndy {OTR) 20 6 R.cllved IN~ deteaof
59'wl Qu*y <*ICIOf 21
... ...
T----(OTE-)
(-
Rlne-
Deta .gnM ma 1e11ctor (DTE.OCE ICIUI"Oe)
22
n
10
...._,..
(~lot dMIIel testing)
24 "
12 Sec. ~'ed IN t9- dHec:Jof
"""'- H I) S.C. . .to Mnd
11 .. unsigned
Table 10.2
Copyrighted material
Microprocessors and Interfacing 10-19 serial Communication
11\C Table 10.2 s hows pins and s ignals de&ription for RS-232C fo~ datn l ine~, The
voltage level + 3V to + 15V ls defined as logic 0; from -3 V to - 15 V is de:fiN!d as logic 1.
The control and timing s ignals are compatible with the TfL level. BecmtSe of the
incompatibility of the data lines with the TTL logic, voltage ITans la ton;, called line d rivers
and line receivers, art' n:."quired to interface lTL logic with the 1~232 s ignals. Fig. 10. 17
shows the inter facing behveen TTL and RS-232 s ignals. 1ne line driver, MC1488, converts
logic 1 into approxilnatel)r 9 V. TI\CSe levels a t the receiving end :\Te aAain oorwertcd by
the line receiver, MC1489, into TIL-.compatible logic.
RS 232C
cable
! '"2"' Receive
(""1
MC 1483 MC t~9
"\_TIL
Ot~la
t~at
TIL '- 2 Oa1a
Comm~lcatlon
/ /
equipment + 3.4 v -- 9v -9V-+3.4V e quipment
0.2V -+9V +9V - 0.2V -
J 3 3 J . -
\. Transmil\.
MC t ~9 MC 1488
OTE oG:e
GNO GNO
7 7
'-' '-'
Fig. 10.17 Line drivers and receivers
Copyrighted material
Hidden page
Microprocessors and Interfacing 10.21 Serial Communication
--
MOV AL, 02
fr.10V BX, FILE HANDLE
the end ana
INT 2 1 H
.,: -,
DEC WORD P'I'R S I Z ; Decrement size poir.ter
CMP SlZ , 0 ; Check if end of f ile
JNZ BACK
MOV AH, 4CH ; Terminate pro9ram and
INT 21 H ; ret\lrn to DOS
CODE ENDS
END START
Copyrighted material
Microprocessors and Interfacing 10 - 22 Serial Communication
COD ENOS
!NT 21 H .
END START
Copyrighted materia!
Microprocessors and Interfaci ng 10.25 Serial Communication
reduce power consumption, this feature is especially useful on battery powered computers
where every milliampere counts.
12. Flexiblli1y
usos four transfer types and two speed (3 with version 2.0) make it feasible for many
types of peripherals. The.re arc tr-.11\Sfcr types suited for exchanging large and small blocks
of data, with and without time constraints. For data that cannot tolerate delays. USB can
guarantee a tran~fer rate or maximum ti.me between transfers .
.... .J ike otl-.cr interfaces, the USB does not assign specific functions to signals or make
other assumptions about how the interface wiU be use. For example, the status and control
linl'S on the PC's parallel port were defined with the intention o f communicating with line
priJ\t('rs,
For c.:ommunicating with common device types such as printers and mode.ITl.S, USB
s upports dasscs with defined devi~ requiremc:nts and protocols. This saves developers
from having to reinvent these for each peripheral.
13. Operating system support
Windows 98 was the fi rs t Windows operating system to reHably support USB? and its
successors such as Windows 2(XX') support USB as well. Other computers : nd operating
systems also have USB support. ON apples iMac, the only peripherals conn<ctors are USB.
Other Madntoshes also supp(lrt USB, and s upport is in progress fo r Linux, NetBSD, and
FrceBSO.
14. Peripheral support
O n the pcriphcrnl s ide, each USB dcvi<..'e's hardware mus t include a controller chip that
ho1ndJes the details of USB communkations. Some controiJers are complete m.icrocomputcrs
lhal include a CPU and memory thai stores the code that runs inside the peripheral.
Others handle only USB-specific tasks, with a data bus that connects to another
mk rocontrollcr thnt perfo rm~ non USB related functions and communicates with the USB
controller as needed.
ThC! peripheral is responsible for ret>pond ing to requests to send and receive
configuration data, and for reading and writing ot~r data when requested. In some chjps,
some of the functions are microcoded in ha rdwa re and don't need to be programmed.
Mnny USB controllers arc bo.s<.-d on popular architectures .!Ouch as Intel's 8051, with
added circuits and machine codes to support USB.
Most peripheral manufuctun."S provide sample code for their chips.
Copyrighted material
Microprocesors and Interfacing 10-27 Serial Communication
The controller
just about any new PC will have a USB controller and at least tw':l port col'mcctors. l(
a computer doesn't have a USB controller built into its motherboard, you co.n add one on
an expansion card tha t plugs into a s lot on the PCI bus.
The operating system
The other side of USB support is in the op-erating system. Windows 95 had some USB
support, but the support was greatJy improved and enh..1nced in Windows 98. WindO\\"S 95
and Windows 98 (;an't use the same devite drivers. Windows NT 4 dc~n' t s upport USB.
How('\tct, if you're deve:lopil\g a peripheral that needs to run under NT. there arc third
party products that you can use to create a device driver that enables the peripheral to be
used under NT. DOS and Windows 3.x also have no USB support, though again, third
party products may be available.
The components
The physical component~ of the Universal Serial Bus consist of the circuits. connectors.
and cables between a host and one or more devices.
The host is a PC or other computer that contains two components; a host controller
and a root hub. Th~e work together to enable the operating system to communicate with
the dcviCl'S on the bus. The host controller forma ts datn for transmitting on the bus and
translates received dal.c1 to a fo rmat th.itt operating system components can understand. The
host controller also perfonns other functions related to ma.naglng communications on the
bus. The root hub has one or more connectors for attuching devices. The root hub detects
the attachment and removal of devices, carries out requests from the host controUcr. and
passes data between devices and the host controller.
The dev~res arc the pc.riphernls and additional hubs that connect to the btL<:o. A hub has
one or more por1s for connecting devices. Each device must contain circuits and rode that
know how to oommunicate with the host.
Copyrighted material
Microprocessors and Interfacing 10-28 Serial Communication
Peripheral Peripheral
Peripheral
Periph~traJ Peripheral
Peripheral Peripheral
Peripheral Peripheral
oq ~
Peripheral
Peripheral
\
0
Host PC Host PC Peripheral
Peripheral
Hosl PC with 6 peripherats
Fig. 10.19 Different configurations for connecting USB devices to a host PC
Copyrighted material
Microprocessors and Interfacing 10.32 Serial Communication
connect to the bus detect the absence of bus activity for three miUi seconds,. they must
enter the suspend stntc and limit the current they dmw from the bus .
5. Exchange data with the host
Aftl'r the device is configured, it must respond to request to send and receive data.
The hos t may pole device at regular intervals or only when an application requests It)
comm unica t~ with it. TI\e device must respm\d to each poiJ by sending an
acknowledgment (ACK) thnt indicates that it receiver! the data, or a negative
acknO~'I:k>dg:men t (NAK) to ind icate that it is busy to handle the dali.'l.
Copyrighted material
Microprocessors ~n~ Interfacing 10 -3-4 S.rlal Communication
.....
1. Control transfer
Control transfer~ a re the only type with functions defined by the USB specification.
These tTiln~fer~ em1~~c the h~t to read and select configurations and other settings on the
devices being cnul'l\cr<ltcd. Control t ransfc~ may also send custom requests that send and
re<"eive blocks of dil til fo r any purpose. All USB devices must support contml transfers.
Ti'lis data t~r;!'(cr
' t, ,,
exchanges configuration, setup, and command information between
tht> device and host, CRC~ check the data and initiate retrafl..'tmissions when needed to
guarantee the correctneN uf these packets.
I .
Control Trans fers Use Message Pipe':'. In a message pipe, each transfer begins with a
Sch.Lp tran......,ction containing a request. To complete the transfer, the ho:->1 and device may
exch;mge data An<Jl~"~t~lu$ il'tformatior'l, or the devi<..~ may just St."'t"'d s tatus infonnation.
Th('re is alw<.\fs M leaSt one trar\So.'lCtion thnt sends information in cnch direction.
' ..,: . '
If th<. n ..>qy;.:;t JJ. qne that the device supports, it takes the requested action. A d evi~
may also respond with n code th.lt indicatl.'S that it doesn't support the rt.oquest.
2. Bulk transf'r _
Bulk trans.fers .,~ intended for s ituations where the rate of transfer is n't critical~ such
as send ing a file nr a printer or receiving data from a scanner. In these cases quick
IMnsfl!rS are nice, but the data can wait if necessary. If the bus is very busy with other
lransfl!rS that have guaranteed lran$fer rate$, bulk transfers must wait, bt.rt if the bus is
idle, bulk transfe~ ~rc very fast . Only fullspa~ devices can do bulk transfers. Devices
aren't required to support bulk transfers, but a specific device class might require it.
11liS datn tra.n:dcr moves large nmounts of data when timely delivery is not critical
Typical applications indude printers and scanners. Bulk transfers rare fiBers; claiming
unu.sc USB b~:~.ndw i dth when nothing more important is going on. CRCs protect these
packets.
3. Interrupt transfer
lnternlpt ITtmsfers arc for devices that must receive the host's or device's nttention
qukkJy. Other thiin co'nlrol transfers, interrupt transfers are the only way that low speed
devices can transfer- data. A keyboard or mouse can use interrupt transfers to send
keypress or mouse Jl!OVement dat-a. Both full and low speed devices can do interrupt
transfers. Devices aren't required to support interrupt transfers, but a specific device class
might require it.IL"'s ..,.
This data transfcr~r though nl>t interrupt in the CPU d iverting sense, poll devices to
see if they m..-ed service. Peripherals exchanging s mall amounts of data that need
Copyrighted material
Microprocessors and Interfaci ng 10.37 Serial Communication
susJX!"fld state, error checking information, and other information about how the chip will
be used and the current status of transmitted or received data. "'
, .,.. r-.r
5. USB port
A USB peripheral controller must of course have USB port and supporting circuits.
6. USB buffers
A USB controller must have transmit and receive buffers for storil)g 1,1SB data.
Review Questions
7. Comp.1re parnlld rmd Sf'Yial ty~
of tlattr trnnsfer.
2. Classify nnd expl1dn Sfrinl communicolion systems. ttl
.. : ''
Copyrighted material
8051 Microcontroller
11.1 Introduction
To makt a complete m icrocomputer sys-tem, only microprocessor is not :n1ffident. Jt is
nt.-'Ces..c;cuy to add o ther peripherab su ch as rei'td o n ly memory (ROM). read/write m(>mo ry
(RAM), dC!COders, drivers, number of input/output devices to make n complete
microcomputer system. In addition, special purpooc devices, such as intcJ'rupt controller,
programmable timers, program.mable 1/0 de\'ic.es, DMA controllers may be added to
improve the capability and performance and ncxibility of a microcomputer sy~ tcm .
The key fcahuc of micropr<X'CSsor based computer system is that it is possible to
dt'!'Sign a system with a great flexibility. lt is possible to oonfigure a system as Large sy:::tcm
or small system by adding suitable pe.riphe.rnls.
On the othN hartd, the mkrocontn)llcr incorpor.-.tcs a ll the featun.'!'l tha t M(' found in
microprocessor. However, it has a lso add4..--d fe~l tures to make a compl~te 1nicrocomputer
system un it'S uwn. The mkrt'>eOniTOllt!r ha ~ built-in ROM, RAM, parallel l/ 0. ~erial l/ 0,
COlu\t'c rs alld a dock circuit.
The microcontro11er hns on<hip (bui l t~ in) peripheral devices. The~
o n < hiy peripherals
make it possible to have sing.le-chip microcomputer system . There are (ew more
advantages o f built-in pe-ripherals : I
BuiltiJ\ peripherals have s maller acet.--ss times he:r'lce speed is more.
Hardware n..:.duces due to s ingle chip microcomputer system.
Less h..'lrdware. reduces PCB s ize and increases reliability of the system.
(1 1 1)
Copyrighted material
Microprocessors and Interfacing 11 -2 8051 Microcontrolle<
3. ll nas one or two bit handling instructions. It has many bit handling instrucOOns.
4. Access times for memory and 1/0 devices are Less aCC8:S$ times for buift.in memory and 110
more. devices.
5. Microprocessor b35ed system requires more Miorocontroller based syotem requires less
hardware. hardware reduci'lg PCB size and increasing
tne rellablltty.
6. Microprooessor based system is more flexible l ess nexille in design point of view.
in design point of view.
7. It has single memory map for data and code. It has separate memory map for data and
COde.
8. Less numbet of pins are multifunclioned. t.1ore number pins are multifunctiooed.
The 805 1 is i'ln 8~bit microcontroller designed by Intel It was optimized for S~bit math
and single bit l3oolean operations. Its family-MCS-51 include5 8031, 8051 and 8751
microcontrollers. The Table 11.1 gives the summary of MCS.Sl micnxontrollers.
Copynghted matenal
Microprocessors and Interfacing 11 - 3 8051 Microcontrolle r
In this chapter we are going to sec features nnd the int'e nla) hardware details
(architechue) of 8051 microcontroller.
Copyrighted material
3:
;;
a
r-------------
-- ----------------
'--------- - -: Port~
D .
------------------------------------;
]
J~.II
laiOIIo
A
Register I Slack I: - "'" n~- r =
0
POinter
Program
1
f
'
Bullur 0
,
:
:
..
Ol
~
c.
Temp Temp eot11ter
': :
....
.o
~
~
Register Reg.ttcr
-I
I DPTR H-~
PC
lnc:rementer
: I-
'
LatCh 1
Blflter i
:
;;
~
~
!!.
.,"
~
'
Ill
,..g
'------
_________ ___:' Buitftt' 2 ~ ~
.l
I
..
~
c. ' ~
;;;
~r- RAM P'rogra111 t-- latch 3 ' '
"';:3 Adc;lr(:fl!i
Register
Address
Regisoeo 1-- Buffr 3 ,
r"
-. .
!l. -................. -----------
. . ... _....,
.
...
0
~
PSE:N-!--1 11rni<Jg
-EA -+-I
ALE
. an<~ I I I RAM EPROI.V
16 bll add~S$
ROM
CO<IIIQI
: I
tnwntPt
...
c:
RST
''
'' I !'CON SOON I TMOO TCON
,...,., pen,
ilrne1 afiO
tuetnory road/ ..
0
-
~. ~
I OS<: I
hl11truc00n
1l40 Tl11 l l1 write <::onl.tot 3:
L- Regis:ler '!1.0
;;-
.-=r D.L :, '
g
~ ~I
~ S8lJf' IE IP
~
.~
Copyrighted material
Microprocessors and lnlerfaclng 11 7 8051 Mlcrocontroller
Gopynghted matenal
Microprocessors and Interfacing 11 - 8 8051 Mlcroeon1roll"
Byte
Addre-u Byte
Address , - - - - - - - ,
1F R, 7F
1E Ro
10 Rs
1C R,
Bank3
18 R,
1A R2
19 R,
18 Ro
17 R,
16 Ro
15 R,.
14 R,
Bank2
13 R,
12 R,
11 R, Byte
address Blt Addres'"
10 Ro
OF R, 2F 7F 78
OE Ro 2E 77 70
00 Rs 20 6F 68
oc R, 2C 67 60
Bank1
OB R, 28 SF 58
OA R2 2A 57 50
09 R, 29 4F 48
08 Ro 28 47 40
07 R, 27 3F 38
06 Ro 28 37 30
05 Ro 25 2F 28
04 R, 24 27 20
BankO
00 R, 23 1F 18
02 R, 22 17 10
01 R, 21 OF 08
00 Ro 20 07 00
30 L - -- ---J
Woo1dng Bit S it
Re-gister 7 5
Copyrighted material
Microprocessors and Interfacing 11 9 8051 Mk:roconlroller
0
Latch 0
PortO
' .. 110
o!p Driver .. AoAt
Buffer 0
'
. 1o,.o,
0
Latch 1
Port 1 ' .
.
o/p Driver . ..
Suffer 1
'
Latch 2
Port 2 '' ....
o/p Driver
Buffer 2 .
'
Latch 3
Sutler 3
Port 3
o/p Driver
'' ..
..
.
'I"'""'"
110
"""""'
Seriol 00o1a
RQ.wA
'
Fig. 11.4 1/0 Ports
Copyrighted material
Microprocessors and Interfacing 11 -10 8051 Microcontroller
All port pins of Port 3 arc multifunctional. They have spcd'-'.l functions as shown
below including two external interrupts, two counter inputs, two special data lines and
two timjng control strobes.
'
Symbol Position N1me and Signtfic:anee
RD P3.7 Read dala oonttd output. Adive aow pulse generated bY hatdware when
external data memory_ is react.
-WR P3.6 Write data control output. Active tow pulse generated by hardware when
e),,"'maJ data memory is written.
T1 P3.5 Ttmetlcountet 1 extetN11 lnout or test cln.
TO P3.4 Timer/oounter 0 external Input or test pin .
INT1 P3.3 lnte~pt 1 in_pu_t ~. l ow-level or faling:_e9g_e trjggered.
INTO P3.2 lnterruot (J fnout '*' lowlevel or fallln ttlooe<ed.
TXD P3.1 Transmit Data pin for serial port in UART mode. Ckx:t output In shift register
mode.
RXD P3.0 Receive Data pin for serial pon in UART mode. Data 1/0 pin in shift register
mode.
Table 11.2
11.3.6 Register Set of 8051
11.3.6.1 Register A (AcctJmulator)
It is an 8-bit register. It holds a source operand and rece.ives the rest1lt of the
arithmetic instructions (addition, subtraction, multiplication. and d ivision). 11le accumulator
cnn be the source or destina tion for logical operations <11\d a number of special data
movement instn1ctions, including look-up tables and external RAM expansion. Several
functions apply exclusively to the accumulator : rotatei parity computation , testing for
zero , and so on.
11.3.6.2 Roglster B
In addition to accumulator, an 3-bit &-register is available as a general purpose register
when ..... not being used for the hard ware multiply/divide operation.
it ~
Copyrighted material
.
Mlcrop>cessors and Interfacing 11 11 8051 Microcontroller
B, 0, o, B,
CY AC FO RS t RSO OV p
~~
6-bi1 8-bil.
Copyrighted material
Microprocessors al)d Interfacing 11 12 8051 Microcontroller
On-c::hip RAM Qn.chlp RAM On-chtpRAM
[}'E)-
l===l 08
07
l===l
1-----1 08
09
r- ,.,.
09
06
Stack pckller 06 SP -
07
SP - SP 1 ..J --~:::::~~=1 07
I 09
08
07
SP - SP-1 _ _ ~~~ E
(c) Read operation
Fig. 11.6
11.3.6.6 Program Counter
11te 8051 has n 16-bil program cou.nt~r. Jl is used to hold lhe address of memory
location from which the next instmction is to be fetched. Due to this the width of the
program counter dcddt."S the maxil'num program length in bytes. For example, 8051 is
16-bit hence it can addrt..--ss upto 2',. bytes (64 I<) of mcntory.
The PC is automatkally incremented to point the ne_x t instruction in the program
St-:.quence after execution of the current instruction. It may also be altered by certain
instructions. The PC is the only rt.'g:istcr thl'lt docs not have an internal address.
Copyrighted material
Mic:n>procnoo,.. and lnt.rfacl ng 11 13 8051 Mlcrocontroller
ones
llylo
- ( M S B)
(l68)
OffH
nl H I FS I IF31 f2 1fl I Fo II
AFI - 1-IACIABIMIMIAII
A71 Alii AS 1... 1All A2 1AI IAO P2
Copynghted materio1l
Microprocessors and Interfacing 11 -14 8051 Mlcroeontroller
Table 11.3 contnins a list oi nil the SFRs and their addresses and their value in binary.
COLnparing Table 11.3 and T.1ble 11.4 shows that all of the SFRs that are byte and bit
addres..,.lble nrc locate-d on th<' first column of the Table 11.4.
"PI
"P2
Port 1
Port 2
80H
OAOH
'I I' II II 1 1 1 1
11 1 1
Copyrighted material
Microprocessors and Interfacing 11 - 15 8051 Microcontroller
Bit 8 Bytes
Addressable
F8 FF
FO 8 F7
ea EF
eo ACC E7
08 OF
DO PSW 07
cs T2CON RCAP2t RCAP2H 71.2 1>12 CF.
co C7
B8 IP SF
BO P3 67
A8 IE Af
AO P2 AT
98 SCON SBUF 9F
90 PI 97
88 TCON TMOO TLO TL1 THO 1>11 SF
80 PO SP DPL OPH PCON 87
Table 11.4 SFR memory map
J't
' OFFFH
-
~
EA= 0
Extemat
4
0000
. 0000
L........................... J .....J .....i .
RD WR
RAO
LATCH
IHTERHAL
PUUUP
!NT BUS
P1.X
0 .) PIN
P I .X
WAJTE I.ATCH
TO -;~t---~CI.
LATCH
~ __;Ci!J------~~
Vee
-"""" OV$
REAO
I,.ATCH .. ~-~ t CONTR<>.
~
!NT SUS
P2.X
PitI
: ______ ___
.,_.,_ .
...
REAO
At.lE.RNAT'E
Ol/TPUT
RfAO FUNCTION' INTERNAl
LATCH P!A.t.UP
PlX
IN T OVS PON
0 0
P3X
!li'RITE I.AlCH
TO -;ll'---t<~L:.._~O~
t.ArCH
READ
ALTERNATE
""""
FUNCTION
Copyrighted material
Microprocessors and Interfacing 11 -1 8 8051 Microcontroller
As ~hown in the Fig. 11.9, for Port 0 and Port 2 drivers arc swHchable to internal
ADDR/ DATA and ADDR bus. respectively, by internal CONTROL signal. The switching is
required to access external memory. During external memory accesses, the P2 SFR
rema ins unchanged, but PO SFR ge~ ls written to it.
As m<.'nt-ioncd earlier, Port 3 htt.' muJtifunction pins. Therefore, each pin of Port 3 can
be programmed to usc as 1/0 or as one of the alternate function. This is achieved by the
another control input, "alternate output fu nction"', as s hown in the Fig. 11.9. When latch
bit of Port 3 conta ins I. the output level is controlled by control input, "alternate output
function."
The port pi_n can be configured as an input by writing 1 in the la tch bit of the
corl'L~punding pin. It turrL., OFF the output driver FET. Then for, Ports 1, 2 and 3, the pin
is pulled high by the internal pullup, but can be pulled low by an external source. There
is no internal pull-up for port 0. Therefore, its output pin floats when 1 is written in the
latch bit, and pin can be used as a high impedance input. The port 0 is said to be true
b idirectional"', bec..'lusc when configured as an input it floats..
On the otherhand, the output of Ports I, 2 and 3 arc pulled high with pull-up
registers, when configured as an input Thus they are sometimes called "'quasi
b id irectional" ports.
The Table 11 .5 summarize!; the functions of four ports.
Port Functiona
Pott 0
Used as an 1/0 port
Pott 1
Used as an input/output por1
Pott 2
Used as an inpuVol.rtput port
Pott 3
Used as an inpuVoutput port or u$0d for
alternate function as shown be.low.
P3.0.RXD Serial data input
P3.1TXD Serial data output
P3.21NTO Extem&t Interrupt 0
P3.31NT1 Extemel lntefTUpt 1
P3.-r o Extem$1 timer 0 input
P3.5-T1 External tmer 1 Input
P3.&-WR External memory write signal
P3.7-RO Extemal memory read signal
Copyrighted material
Microprocessors and lntertacing 11 -19 8051 Microcontroller
FFFF H FFFFH
60 Kbytes
External
64 Kb)"'e$
OR External
1000H
OFFFH
4 Kbytes
tntetnal 0000
0000 )
through OFFFH a re d irected to the internal ROM and progTam fe tches to addres..<OCS IOOOH
through FFFFH arc directed to external ROM/ EPROM. On the other hand when EA pin is
grounded, all addresses (OOOOH to FFFFH) fetched by program are dire<:t<'<l to the extcrn.,l
ROM/EPROM. The PSEN s it,ona l is usc..>d to activate output enable ~ignal of the external
ROM/EPROM, os shown in the Fig. 11.11.
A
P, Po Do
' v 0,
EA
~
ROM/EPROM
8051
l
A
T
c
"v ...A,
ALE
Cl.K H MrJr.
"--"
P, Aa
p2 "v Al5
PSEN 5E
.
Fig. 11.11 Accessing external program memory
Copyrighted material
Microprocessors and Interfacing 11 -21 8051 Microcontroller
Mnemonic Operation
Internal Memory
~ FFFF H
FFH
..................... ISFRs) .
Accessible by
Aoce&sible by
Indirect
Uppe< Addressing
Direct
128 Ad0re:$$1ng 64 Kbytes
Only
Extemal
SOH Memo<y
+-AND-+
7FH
Aocenible by
lowe< Oirec:l & Indirect
128 Addrt$$ing
OOOOH
0 I
The 8051 ca n address upto 64 Kbytes of externa l data memory. The "MOVX"
instruction is uSL~ to access the external data 1\'lcmory. The inten1al data memory space for
8051 is d ivided into three blocks : Lower 128 byte'S, Upper 128 bytes and SFRs. The upper
addrt"SSeS and SFRs occupy the same bloc-k of address space.. SOH through FFH, although
they a re physicaJJy separate entities. As shown in the Fig. 11 .14, the upper address s pace is
ao:~siblc by indirect addressing onJy and SFRs are accessible by direct addressing only.
On the other hand, lower address s pace can be ac~ either by din."Ct addrcs.o;ing or by
indirec-t addressing.
Copyrighted material
Microprocessors and Interfacing 11 - 23 8051 Mlcroeontroller
ALE
_/ \'--- ------'/ \..__-----'!
PSEN
WR
PORT 2 ----'x'----P-2.1_H'_2._7 o
_R_ A_o-_ ~x... -A 1, FROM PCH
A _,,_r_R_O_M_o_P_H_ _
Fig . 11.16 (b) Timing waveforms for external data memory write cycle
Instructions to Access External Data Memory
The tabll.' 11.7 explains the instruction to access extem.d data memory.
Mnemonic Operatio n
Table 11.7
11.6.3 Important Points to Remember In Accessing External Memory
AU external datil moves with external ROM or externa l RAM involve the A
register.
While accessing external memory, Rr can address 256 bytes and DPTH can
address 64 Kbyte;;.
MOVX instruction is used to access external RAM or 1/0 add resses.
\P\' hen PC is ust>d to acccs5 externa l ROM, it is incremented by 1 (to point to the next
instr\ICtion) before it is addc.>d to A to form lh~ physical address o r external ROM.
Copyrighted material
Microprocessors and Interfacing 11 -25 8051 Microcontroner
(MSB) (lS B)
r
I
- l
'I
' -
ctr=O
'I
I
TU Ttt1
TF I ,. lnterrupl
II Bl"l ~ llll)
C'T:t 'I
n PIN - - - - - - . . . . J
'
I
TR1 I
I
I
' G/ITE C"'llf(ll
I
1 INT1 PIN _ _/-,.- - '
----.. --__. . --.. ----- -4co.--------
~mr I counter conltof log9c
I 1 I lh t I II I
Microprocessors and Interfacing 11 -26 8051 Mlcrocontrolle r
Both Timers in Mode 0 is an S~b it Counter with a divide-by-32 prescaJer. This 13-bit
timer is MCS-48 compatible. Fig. 11.19 shows the Mode 0 opera tion as it applies to Timer
L In this mode. the Timcr register is configured as a 1J..bit register. As the count rolls over
from all ls to all Os, it SC'ts the Timer interrupt flag TFl. nu~ COW'Ited input is enabled to
the Timer when TRI = I and either GATE= 0 or INTI =1. (Setting GATE = 1 allows the
Timer to be o.)ntrol1ed by externa l input INTI, to fad litate pulse width measurements..)
TRI is n control bit in the Spial Function Register TCON (fig. 11.20) GATE is in TMOD.
(MSB) (LSB)
TFt TCON.7 Timet 1 Overftow f lag. Set by hatdwate on timer/counter overllow. Cieared when
lnterrupc processed.
TR1 TCON.6 Timer t Run control bit SeVcteared by software to tum timer/counter on/off.
TFO TCON.S Tll'flef' 0 Ovetftow Flag. Set by Ml'<twate on timerlcoun~er 0\'erflow, Cle3red when
lnterrupc processed.
TRO TCON.-4 Tlmet 0 Run eorttrot til. SeVdeared by software to tum tlmer.'counter onfolf.
IE1 TCON.3 lmcrrvpt 1 Edgo Flag. Sol by hardWare when external W'lterrupt cdgo delectod.
Cleared when intonupl procflMd,
ITt TCON.2 lnterrupl 1 Type control olt. SeVcleared by software to speeity ramng edgeiiOw
leVel triggered external interrupls.
lEO TCON.1 huertupt 0 Edge R&g. $et by hllrdw,re when extemal iOtettt.JI)t edge delbCted.
Cle81ed when Interrupt processed.
ITO TCONO lnten'IJS)t 0 Type conlrOf bll. $eVCie3rod by sottw&re to specify telling edgollow
level triggered e:xt.ernat imerrupts.
Copyrighted material
Microprocessors and Interfacing 11 28 8051 Mlcrocontroller
MOOE 3
Timer l in Mode 3 simply holds its count. The effecr is [he same afol setting "ffi.1 = 0.
1'imer 0 in Mode 3 \.-"St.lblishes TLO and THO >lS two scpar,1te count.ers. The logic for
Modt!3 nn Timer 0 is ,shl)wn in Fi)). 11 .21. n.o uses th(;! T iml!r 0 amtrol bits : C/ 'f, GATE.
TRO, iNTO, ond lFO. THu is locked into a tim<.'! mode (counting machine cycles) and lakes
over the use llf TRI and TFl from 'Timer J. Thus, THO now control$ lh~ : Timer 1
intcr:rupt.
'tOF11~-------'
1f12 I OSC
T>iO
(8 81~1 r--1 EJ-- inlerruot
CONtROL
II I
Microprocessors and Interfacing 11-30 8051 Microcontrolter
SMOO PCON.7 Serial boaud rnto modify bit, 11 is 0 at ~. It is &el to 1 by progrom to doul *
the baud rate.
-
GF1
PCON.&-4 Not defined
Copyrighted material
M icropr~ssors and Interfacing 11 - 31 8051 Microcontroller
MODE 2
ln this mod~. 11 bils a re tr<Ul$mitted (thorug h TXD) or r<.>eeived (through RXD) : a start
bit (0), 8 data bits (lSB first), n programmable 9th data bit, and a stop bit (1). On
Tran~mil, the 9 th data bit (1138 in SCON) can be assigned the value of 0 o r 1. Or, fo r
example, the parity bit (1', in the PSW) could be moved i11to TBS. On receive, the 9th datn
bit goes into R BS in Special Function Rcgsitcr SCON. while the stop bit is ignored. The
baud r.lte is prosmmmable to either Y~ or y64 the oscillator frequency.
MODE 3
In thi~ Mt)de, 1 J bits are tr<~nsmitted (through TXO) or rt;.-ceivtod (through RXD) : n start
bil (0), S data bits (lSB first), a progmmmnblc 9th data bit o.nd a s top bit ( 1). In fact,
MOOe ? is the s.1mt> as Mode 2 in aU respeocts except the bc1ud r.ite. The baud rate in Mode
3 is v,uinble.
In ,,n fo ur mOO..-s, tnmsmis!'ion ~ initiated by any ins tn.1ction that uses SBUF as a
destination n:.-gislcr. Rcccpti()J"' i~ initia ted in Mode 0 by the condition Rl 0 and REN =; 1.
R(orrccption is initintcd in t h~ o thLr mt1d~ by th(' incoming start bit if REN :: 1.
TI\C Table 11.9 Stunm~riL-'S the four serinl port modes provided by 8051.
Copyrighted material
Microprocessors and Interfacing 11 32 8051 Microcontroller
Serial port in Mode 1
Mode 1 has a variable baud rate. The baud rate can be generated by either Timer 1 or
Timer 2 (8052 only).
Using Timer/Counter 1 to Generate Baud Rates
For this purpose, Timer 1 is usai in mode 2 (Auto-Reload).
k x Osdlliltor Freq.
Baud Rate = 32x12x[256 - THI)J
If SMOD = 0, then k = 1.
If SMOD = l , then k 7 2. (SMOD is the PCON register)
Most of the time the user knows the baud rate and needs to know the reload value for
THl. Therefore, the equation t'o calculate THl can be written as :
TH J = 256 _ kx Osc Freq.
384xbaud rate
THl must be an integer value. Rounding off 11-:11 to the nearest integer may not
produre the desired baud rate. In this case, the u~r may have to choose another crystal
frequency.
Since the PCON register ls not bit addressable, one way to set the bit is logical QR.ing
the PCON register. (i.e. ORL PCON, #SOH). The address of PCON is 87H.
Using Timer/Counter 2 to Genrate Baud Rates
For this purpose, Timer 2 must be used in the baud rate generating mode. If Timer 2
is being clocked through p in T2 (1'1.0) the baud rate is :
a. d R Timer 2 Overflow Rate
uau n1c =
16
And if it is being clocked internally the baud rate is :
Osc Freq.
Bau d Rote = 32x[65536 - (RCAP2H,RCAP2L))
To obtain the reload value for RCAP2H and RECAP2L the above equation can be
rewritten as :
Osc Freq.
Rc P2H Rc P2L
A ' A = 65536 - 3'h6audrate
Copyrighted material
Microprocessors and Interfaci ng 11 33 8051 Mlcrocontroller
TPO - - - - - - - - -
0 Interrupt
sources
1
TF1
Tt
Rl - D>----
Fig. 11.25 MCS 51 Interrupt structure
The Time-r 0 and Timer 1 Interrupts are generated by TFO and TF1, \vhich a re ::>et by a
rollover in U\eir rcspt..-ctivc Timer/ Counter registers (except sec Timer 0 in Mode 3). 11lc
timer flag set upon generation of interrupt is cleared by the on-chip hardware when
micnxontroller starts ext.-cution of particular interrupt service routine.
The Serial port Inte rrupt is generated by the logical OR o f Rl and Tl. Neither of these
fli'lgs is clearOO by hardware when the service routine is vectored to. ln ftlct, the service
Copyrighted material
Microproceoaors and Interfacing 11-35 8051 Mlcrocontroller
(MSB) (lSB)
I I PS PT1 PXI
- IP.7 IRese<Ve<lt
- IP.6 (Reserved)
- IP.S (ResOM>d)
1. lEO (Nghe$1)
2. TFO
3. lEI
4. TFI
s. Rl Tl (IOW0$1)
Note tha t the "priority within level" structure is only used to resolve s imultaneous
requests of the same priority level.
The U' register ront..1.ins a number of unimplemented bits. 11'. 7 and IP.6 arc vacant in
the 8052s, and in the 8051s these and IP.S are vacant. User software should not write l s to
these bit positions, since they may be used in future MCs-51 products.
Copyrighted material
Microprocessors and Interfacing 11.37 8051 Mlcrocontroller
M .....'
...
"-
XTAL1
......
l
XTAL2
......
...
....,,"' '*
"'
.!..
..,, .,.
RST "'
'
~
RXD
TXO
........, ' ,...
"
...
.""' . .....,1.~
~
"'" """
-H
~"
..,
.. '
82SS
2
1
~
t.SU
'* ~
f-2 " fL
.
...
.
.... "
.~.
1
"'
" "
,.
..,
......... '
2 '''"
cl ~ [: '
"
1"
Fig. 11.28 110 expansion using 8255
Copyrighted material
Microprocessors and Interfacing A-4 Appendix A
M,.._nlcncl
OMcrlpdon I ....lnllott Codt
"""'--
. - . Unuonc!IU-..1 AIIOIP
o;,<tts ..iiiWI ~
Jfi<IISI10
! u t01001
! tt 10 1 0 11 -...
tfUU 1 f ?f$ 1
:1310
ol~h
ll'dr.ct.,.... ~
Ol!ea lnlll~".,..enl
1nctto.c11n...,.._1
1 11101010
l t t111 1 11
--
1 111 1 111 1 moOIOOdm
........
IIIOd tO 1 Ntf>
_,.,.
Oll'wtf'i'i
-
,...~
I UOOOIO
ltt0010 11 ---- -- .......,.
~ AOclonlll"'"*'-leiiD $P
I ott 10 1 00
,
.....
JUJNGIE J~~mp 0t1 LH$/NOt a-t lott1t100
orf(ll.;81
JUIJNO Jun'oll on '-"t 01 ECIU'it
Gto
Mol;
J.,JNM Nolp hlow.M:II
01> ~
lo t tttllo
l ot~tOoto
......
Mf -
.........
JlfJJH.A Jump "" 8alcwrt 01 f(Wati
01111010
""'
....
JO JUMP Cl!l 0...,_.
Jl Jut!IP on SII;J'I
01110000
011 11 0 00
-""
JNEJ.INZ .Aifl'lll MHCil C)ullllttll
JHV.ICC "~
Nqt on Nol tM~~o'G~aler
~-
011 U101
0111tl01
~-
Jlllll/JA Jlrp Ql! Nol hlo- Of 01110,1
--...
EQI.IIIi'A bo.,..
JHI'fJf'O ~on Nol P,<P OciCI 0111 1011
...
---
LOOI" LOOP X Tmn 11100010
JIQCZ ""'*"P on ex z-
1 11 00001
1 l1000 00
1 1100011 -...
,._
INT I' * " " "
,..
,., 1 1100110 1 1
1 1 1001100 1
INTO 1flllon\.4ll ot1 o..rtll)w l t 10011tO !
tftiT "*""" ltiMunot l tt 0 0 1 11 t l
Copyrighted material
A l
.. .........
MOCQICIIR CC*I AOi. JI U U U nu n u
CLC C...CM\o tt tttuo i
Cllt Col~~ Ceny ttt to t ot!
lTC Soli CltiY tt t noo 1)
CUIC...~ IUt!UO J
ITI k~ l!1t 1 0n
l:ll:ll:l
Copyrighted material
.Mlaropi'G-Ion end ~ a.fKing Bl r>
'
- ... ~ , Appendix a
-
ma llllc Oee u lptlcM ~cyctee Number of Page No.
byiH
ON . 2,. .. .
Unligned-
8-bil,...,
18-l>llrogi~W
80-90
1-162 2 '
"'
8-l>ii"*""'Y (8&-96) + EA .;2-4
1 - motnOIY (150-168) + EA -2-4
<"
uc Eocljle 203
Regioter 2 )1 -~ ~ . .'
. ~ 8 + EA
..
2-4
Hl.T ...... 2 '- - 202
.. 18-tMt memory
lnpu1 from 110 pori
FII<Od pori
(IU-180) + EA
10 .
""'
2
1
2-4
180
V.:l- pori 8
IIIC incremetllb'( 1
16-bit registlf 2
----
..1...
181
'
8-bll rog;oler . 3 2
Memory
- 15 + EA 24 ,.
MY lntenupt
- ' 20(
Type3 52 1
Type.l 51 2
*YO ln'-'Up< W - 1 . 20(
lnterrupl io taken
. 53 . --- -
lnWNPC il not taken 4
": ...
ltET Retum from interrupt 24
"
20(
..
-
JN Jump if aboYW 16/4 2 200
Copyrighted material
Microprocessors and Interfacing B -4
Copyrighted material
........
lllcnopnlceMors ancllm.rtKiftt
_.,.... ..
-
Appendix
IIIOV Move
of """ 171
Accumulator to memory 10 3
~"to aoc~.mUIItor 10 3
RogitiO< 10 rogiiiO< 2 2
Mti\'Q'YIOregl- 8 EA 2-4
Regis& to memory D + EA 24
Immediate to regia.ter 4 2-3
lmmedi.... 10 memory 10 + EA :HI
Roglslet 10 SS. DS. "' ES 2 2
Momc.y 10 SS. OS. 0t ES 8 EA 2-4 -
S!!!troen ~ oo rog~,.., 2 2
Segment tegiltlf to memory D EA 2-4
MOYSW ~ . 11ring
205
Not~ 18
9 + 11Jtep
11M. ~- mulliplieallon 117
8-bll regil1er 7().77 2
16-bit;~ilter
8-bii"~!QVY
118-133
(76-83) EA
2
2-4
.
16-bh ""'mory (124-138) EA 2-4
NEG Negale
i ..
115
Reg-.r 3 2
Mem~>iY'" 16 + EA 24
NOf' No operation 3 1 :104
NOT Logicol NpT 1t1
Roglolo< 3 2
Mtmo<y
: .
Logiall OR
. 18 + EA 2-4
OR 1t1
~ilti, regllllr 3 2
Mlmoty .to register 9 EA 2-4
Regi&W' to rnerr101Y 16 + EA 2-4
Immediate to IICCI.WftUIIIor 4 2-3
lmmedWe to register 4 3-4
lmmedi8tit to memory .. . . '
17 + EA . :HI
~-
Copyrighted material
I
- .
~.og~eo~.-OR
Roglllotwllh . . . . .
Memory wllh ,.ai.. IJ'
RegisW wtlh nwmory
3
8 + EA
18 + EA
2
2-<1
'2-<1
.
-
lnllnedt...... IIC:C:UrftUIMDr
2-3
,, lmmtdillllt wilh ~-.,
lniR'..ctl wtlh ,.,.,..'1 17 + EA
3-<1
3-e
.- I 1
tliJtl
Copyrighted material
Microprocessors and Interfacing C-2 Appendix- C
If address is not spt.-x-ified, the IOGltion begins whe.re the last D command efrot: or ,lt
locati(~n DS:O if the oon"'mnn.d us being typed for the first time. An address m'ons1st of
a segment-offset address or JUSt a n offset :
D 6000:() (segment-offset)
.;.t
c .
-,,<"
),.,
!li tlr> >; ES:2001
. -
.1' (segment register-offset)
"" ~ ,W\L- ~ ,.. ,.,;=,.(offse t)
The defauJt segment is OS. so it is not nect-'SSary to specify segment
dump an offset from another 5eb'1l1ent location.
A range m.1y be given. tehing DEBUG to dump all bytes ~ithin the range :
D 100 200 ; Dump 0 5:0100 through 0200
Other segment regis ters or absolute addresses may be used, as shown in the fo llowing
examples.
Examples
E (Etter)
The E command places indivictual bytes in memory. We must supply a starting
memory locat1on where the values will be stored. U only an o((set value is entered, the
oHset is as..~umed to be from OS. Otherwise, a 32-bit address may be entered, or another
segment register may be used. The syntax is :
E address Enter new byte value at address
E address (list) Replace the contents of memory storting at
,, ..the,' ...
specified address with the values contained
..
in the list.
\J.
To begin entering hexadecimal or choracter data a t 05:200, type, Ji.200. Press the space
bar to advance to the neXt byte, and press ENTER to s top. To enter a string into memory
starling at location CS:200, type E CS:200 "This is a string". r~lttl.-1 ~
Copyrighted material
Microprocessors and.Interfaci ng C-3 .
F (Fill) :..1~.~ , '
The F command fills a range of memory with a single value or a list of values. The
range must be spcd.fied as two offset addns.~cos or segme:ntoffset addresses: The syntax is :
F range list
Examples
1. F 100-200, ' ' Fill with spaces.
2. F CS:0100 CS:0200, FF Fill with hex OFF.
3.F200L30'A' Fill 30 hex bytos with the letter
'A', starting at location 200.
'
G (hecate)
The G command executes the program in the memory. We can specify a starting
address and a breakpoint. causing the program to sto~ at a given add!'e55. The syntax is :
G [= startaddress) brkptaddress [brkptaddress ... )
JJ no breakpoint is specified, the program runs until it stops by itself and returns to
DEBUG. Up to 10 breakpoints m"y be specified.
Examples
t.G Execute from IP to the end of. the program.
2. G tOO Exe<Ute from the lP to CS:1 OOh and stop.
3. G = 100 500 Begin execution at offset 1001\ and stop before
the instruction at offset 5001\
H (Henrithmetlc) ,, -; ._
The H cqmmand perfonns addition and subtraction on two hexadecimal numbers,
entered in the following syntax :
H valuel valuc2
\
Example
I ' ..
H 10 20 Hexadecimal values 10 and 20 are added and subtTacted
I
0030 0010 <- displayed by Debugger
I
I
I
Copyrighted material
Hidden page
Mlcroprocnso,.. and Interfacing C-6 Appendix C
T (Tract )
The T command executes one or more instruc~ons from the current CS:IP location or
an optional address, if specified. The contents of the registers are shown after each
instn1ction is exect1ted. The syntax is : -..v.- N.
Examples
I. T
.
Trace one instruction from the current location
2. T 5 T race five ins tructions.
3. T = 5, 10 Start tracing at eS:5, and trace the next 16 s teps.
This command traces individual loop i!erations, so we can use it to debug statements
within a loop. Also, the T command traces into procedure calls, whereas the P command
executes a procedure caU in its entirely withotlt tracing.
U (Uausemble)
The U command translates memory into assembly language mnemonics. This is called
unasscmbling or disassembHng memory. If we don't specify an address, debugger
disassembles from the location where the last U command is left off. If the command is
used fo r the first time aJter loading debugger, memory is disassembled from location CS :
100. The syntax is :
Syntax I : U (address)
Syntax 2 : U (range)
Eumples
i. U Unassemble the next 32 bytes from the current location.
2. u0 Unassemble 32 bytes from location 0.
3. u 100, 200 Unassemble all bytos from offset 100h200h.
W (Write)
The W command writes a block of memory to a file or to individua l d is k sectors. If we
want to write to a file, it must first be initialized with the N command . (If the file was just
loaded either on the DOS command line or with the Load command, we do not need to
repeat the Name command.)
Place the number of bytes to be written in BX and ex (BX contains the high 16 bits,
.tnd CX cont3ins the tow 16 bits). If a fi le is 256 bytes long, for example, the BX and CX
registers will contain the following :
ax = oooo e x = 0100
Copyrighted material
MicroprocHsors and Interfacing C7 Appendix C
Exmples
I. N MYFILE.COM lnitiali1.e the filen.am~ MYFILE.COM
on the default drive.
2. RCX 20 Set the ex register to 20h, the length of the file.
3. w Write 20h bytes to the file, s tarting at CS : 100.
4. wo Write from location CS : 0 to the file.
aaa
Copyrighted material
Microprocessors
& Interfacing
(P - 1)
Copyrighted material
8086 Instruction Set and
Assembly Language Programminl
Q.l DiS<:u:;s l~1rious brnuch i11Stmctiou of 8086 micrtJprqce$:i(Jr, thnt are u.;.eful for
re/ocntio11. 1Aprii!May-21Y.J5, Sel-l, 8 Marks; Aprii/May-2006, Set-1, 8 Marksf
Ans. : Refer section 3.7.
Q.2 It is 11eressary to cherk w/ret/r.r the word >tdrcd in location 4(}()()H: A(}()()H is posiliVt'
mm1btr of not. Sholl/ all p()SSible Wily$ of lestiug the above condition aud store 001-1 if
lhe condition is ::atisfied ;, location 3000: 2002. Otl1erwi~ store OFFH.
IAprii/May-2005, Set-2, 16 Marksl
Ans. : Rcit"'r program 12 in chapte r 4.
Q .3 Distinguish l~tween iuter~segmeut aud iutra ~stgmmt CALL instructions smd explain
willl txnmplc'S !tow they an~ executed. (Aprii/May2005, Set2, 8 Mark.i )
Ans. : Rdc.r st"Ction 3.7.1.
Q .-l Gi;tr. d umt flow chart mul lht corrtsJ'cmdiug 80d6 assembly lauguagt' program for
J'l'fformiug bubble sort ;, m; array of N tltmmts of 4--digit Htx number.
[Aprii/May-2005, Set-2, Set-3, 8 Ma rks]
Ans. : R(f..:r p rograr.1 l 9 :n ch aprer 4. '
Q.S What is a procedure ? Hqzv is a procedure idt!ntified as nmr or Jar ?
IAprii/May-2005, Set_., 8 Marksf
Ans.: Keicr St.-<:tion 3.17.
Q.6 D1scus.s the importanu of proc.,"'tfures in assembly language programming.
(NovJDec.-2005, Set-!. 8 Marks!
Ans. : Rek>r section 3.17
Q.7 Wl~t~l l:i- ,, rtrur:;ir't' pr(J(t'dur~ ? Writf' a recursive procedure to calulalf the factorial of
tmmbtr N, when N is 11 two-digit Hex rrumber.
(NovJDec.-2005, Set-2, Set-4, 8 Marks]
Ans. : Rd..-r prog:r.lm 5 of chapter 4.
(P 4)
Copyrighted material
Microprocessors and Interfacing f P-5
' .
8086 Instruction Set and ALP
Q.8 Wlrat are tire loop instructions of8086 ? Explllin tire u& of DF flag in tlr. execution
of string instmctions. (NovJOec.-2005, Set-2, 8 Marks)
Ans. : Refer se.-tions 3.8 and 3.6.
Q. 9 What ;nstruction set support is providtd in 8086 ? {NovJOec.-2005, Set-2,. 4 Marks)
Ans. : Refer section 3.3.
Q.lO Ot'Vt!lop a far procedure declared as PUBLIC to convert a 4-digit BCD mtml>r to its
equivalent ht'x nllmber. [Nov./0.-2005, Set-3, 8 Marks)
Ans. : Rcfe.r program 13 of chapter 13.
Q .ll Giw tlrPassembly lmrguage implementation of tire following.
i) DO WHILE ii) FOR (NovJOec.-2005, Set-4, 8 Marks)
Ans. : i) DO WHILE
DO WHILE
Statementfs label :
::::::: } lnsttuc:tiOns
...... .
.......
Compare instruction
Yes J conditional instruction
if condition is tr\le goc.o Label
OthervMe exit loop
Fig. 1
'
Copyrighted material
Microprocessors and Interfacing P-6 8086 Instruction Set and ALP
iil FOR
FOR
Assembly Implementation
Initialization or
variable with initial count
Initialize Register with
Jnlt1al value. FOt example,
MOV CX. 0020H
Label : Compare registor value
with final vatoe. For example,
CMP CX,OG40H
tf ex = 0040H exit
For example, JE exrr
OU\etwi&e continue
Fig. 2
Q.12 Explaitr /row !RET instruction is executed ? (NovJ Dec.-2005, Set-4, 8 Marks )
Ans. : Refer section 3.1 1.
Q.13 Using a do-while construct, develop a sequence of 8086 inslntelions tl111t reads a
cllnrncler string from tht kcybonrd and after prtsSing the enter key tire charactn- string
is to be displayed again. [April/May-2006, Set-1, 8 Marks]
Ans.:
model small
stack 100
dat a
msl db 10 , 13 , ' Enter tho st r ing S
buff db 80 dupl$ )
cod e
Copyrighted material
Microprocessors and Interfacing P-7 8086 Instruction Set and ALP
mov ah , 09H
i n t 21 H
back mov ah , 0 1 ; Read character
i n t 21 H
mov ( BX) , AL ; Save the chatilcter
inc BX Increment pointer
cmp AL, 13 ; Chec k i f i t >S ente r
jnz back I f not read next character
lea d x, bu ff Display the strinq
mov ah, 09H
int 2lh
mov a h , 4c h; (Ex i t to
i nt 2 l h ; DOS)
end s t.a r t.
/ e nd
Q.14 Discuss tilt' addressing modes prDVidt~ by 8086 and txplain tuitlr examples.
[ApriiiMay-2006, Set-2, 8 Marks)
Ans. : Refer se<:tion 3.2.
Q.lS It is neC<'ssary to define a block of data in 8086 assemble languagr program. The
lmgth of the block is 80,(}()(} Bytes. Ciw the initialization of data segment for the
abow data. It is nec=ry to excla11ge second element and 7001JCi element in the
abcrve. Glue the sequence of instructions to perform the above operation.
[ApriliMay-2006, Set-2, 16 Marks)
Ans.:
mode l l a rge
da ta s e gment
bu f f db 65535 dupo
data ends
da tal segment
buf f! db 14465 dup 0
dat al ends
code segment
assume cs code, ds data
Copyrighted material
Microprocessors and lnterfaclr/9_.~1_
' _ ___,Pc...::.-,8_ __ ____,80~86~1:!!n.!.st,r,u~etl,;o!!n~Se~t!!an,_,d"-'=ALP=
Copyrighted material
Micr oprocessors and Interfacing p.g 8086 Instruction Set and ALP
Q .19 It is "'-'CtsSllry to check whttlrer the rvord stored ;n location 3000H : 2000H ;s uro or
not. Shotv all po$$ible Wb)!S of trsting the abo"" condition using different addmsing
modes and stort> OFFH if tJre condiUou is sntisfied hr location 3000H : 2002H.
Otllmvise store OOH. [Aprii/May-2006, Set-4, 16 Marks)
Ans. : Refer section 3.2.
[J[J[J
Copyrighted material
Assembly Language Programs
Q .l Detelop n11 8086 t1SSembly language program Orat will determine if a given SllfJ..Siriug
i$ prt!Sent or not i11 t1 mnin string of characters. Place tire result as 'P' if present else
plnct 'N' iu memory loc.atio11 'rt!Su/1'. (ApriUMay200S, Set-4, 8 Marks)
Ans. : Refer prog:ram 18.
Q.2 Using OF flag and string instrucfi(mS, write mr u$S('mbly langungt program to moue
n block of data of length N from source to dt'Siirration. Assumt' all possible conditions.
INovJOec.-2005, Set-1, 8 Mark.<I
Ans. : Refer program 1L
Q.J Dnoelop a near procedure lo find lite CCD of two numbers of 2-digil Hex. Use litis
proadnre to finci lite GCD of IIITt'e 1111mbers. INovJOec.-2005, set-3, 8 Marks I
Ans. : Re fer program 22.
DDCJ
(P -10)
Copyrighted material
Microprocessors and Interfacing p -12 8086 System Config.,ration
110 Map :
SHe .... A,, ":l .... A,, .... Ag Ao A, ... ... A, A, A, ... Ao HEX
&ddress
VO O~Ice
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 OFOOH 1-<lata
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0 OF02H 1status
0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 OF01H 2-data
0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 OF03H 2-smtus
1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 OF04H 3-<fa1a
1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 0 OF06H 3status
0 0 0 0 0 1 1 I 1 0 0 0 0 0 1 0 1 OF05H 4-data
0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 OF07H 4status
'
1 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 OF06H 5-data
1 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 OFOAH ~status
Copyrighted material
MlcroproceHora and Interfacing p -13 10116 Systam Confil!llration
Q. 4 Describe the function of the fo//()wing pins and their use in 8086 bastd system.
a) NMI b) WCK c) TEST d) RESET. (April/May-2005, Set-4, 16 Marks)
Ans. : Refer section 5.2.
Q. 5 ~be the futrclion of tire following pins in 8086 maximum modo of operation.
(a) TEST
r Ya
Ao v,
3 inputS { A,
3:8
v,
"' Decoder
7US1$8
v,
v,
v,
Acelve hiGh enable e,
~.
v,
Ac!M>IOw {
enabht $lgn8IS E, v,
GNO
. j_
Fig. 2
The IC 74LSJ38 is a 3 : 8 decoder. It ru.s 3 input lines (select lines), 8 output lines
(Active low) and three enable signals : E1 , E2 and E3 To make decoder
active 3 should be high, and E1 and E2 should be low. Once 74LSI38 is enabled,
according to the inputs A 0 , A 1 and A 2 one of the output pin is activated.
Copyrighted material
Microprocessors and Interfacing p -14 8086 System Configuration
INPUTS OUTPUTS
E, e. e, Ao A, A, 0 1 2 3 4 5 6 7
H X X X X X H H H H H H H H
X H X X X X H H H H H H H H
X X L X X X H H H H H H H H
L L H L L L L H H H H H H H
L L H H L L H L H H H H H H
L L H L H L H H L H H H H H
L L H H H L H H H L H H H H
L L H L L H H H H H L H H H
L L H H L H H H H H H L H H
L L H L H H H H H H H H L H
L L H H H H H H H H H H H L
The 74LS138 decoder is used fo r generating chip select signals by decoding the
address.
Q. 7 C~nerate chip sdL>ct siguals wit11 tile llrlp of 74LS138 to six memory cl1ips of siu
16 kB, witlr II" addms map from OOOOOH to 17FFFH.
INo vJ Dcc.-2005, S<t-1, 8 Mark&)
Ans. : The 16 kB memory requires 2a address lines, i.e. A 0 - A 13 The remaining
address lines are used as a~decoder input.
Yo
Ao CSotochipO
v, cs, to <hlp 1
A,
3 :8
v. CS to <hlp 2
A,
Oecodtf v, cs,2 to <hlp 3
74LS138 v, cs,. to chip 4
-t>- ,E3 Ys
CSs to chip s
E,
Fig. 3
Copyrighted material
Mic,roprocessors and Interfacing p -16 8086 System Configuration
Q. 10 A lnrgd systrm based on 8086 processor uses less amount of SRAM. Tire programs
art' stomf in EPROM tllat stnrls from F()()()()H ends witll f),. a.tdress of FFFFFH.
Tire capacity of SRAM is 8 KB int"fnwt nddress OOQOOH. Tl.r cllip siu is 8 KB for
PROM nnd St~AM. Sllow tile compiete memory interface.
INovJDcc.2005, Set-2. 16 Marks)
Ans. : KcfL"r section 5.10.
Q. 11 Wlmt is fJ~e purpose of ALE, BHE. DTiR nnd DEN pins of 8086 ? Show their timing
in tile system bus cycle of8086 . )NovJDec.-2005, Set-3, 8 Marks)
Ans. : Refer section 5.2.
Q. 12 Wiry 8086 mtmory is mapped into 2 byte wide banks ? Wllnt losic h.,..ls are found
with BH and AO tvht>ll 8C86 rrods n word fro, the> addrt.'SS OAOAH ?
)NovJDec.-2005, SetJ, 8 Marks ; ApriUMay-2006, Set-1, Set-4, 8 Marks)
Ans. : Refer se<:tion 5.3.
Q. 13 DistinguisJr bt'tnJt'e11 a memory read and write maclliue c-ycle. Draw tire timing
dingrams i11 minimum ;md maximum modes of Opt.'T'ntion.
(Nov./Dec.-2005, Set-4, 16 Marks)
Ans. : Refer S<.><:tion 5.6.3.
Q. 14 /11 an SDK-86 kit !28 KB SRAM and 64 KB F.PROM is prm>ioied on system aud
provisiou for t>xpausiou of anol-hlr 128 KB SRAM is siveu. Tire 011 system SRAM
address starts from OOOOOH mrd flint of EPROM mds with FFFFFH. Tlrt expansion
slot address map is from 8()()001-1 to 9PFFFH. Tl~t siu of SRAM cltip is 64 KB.
EPROM chip siu is 16 KB. Give til~ cvmplrtf mt!mory iuterfirce nud also tile addn!-SS
map for individual clrip:;. (NovJDec.-2005, Set-4, 16 Marks)
Ans. : Please ref!![ Fig. 5 on next page.
Memory map:
I
1
1
0
I
0
I
0
I
0
I
0
I
0
1
0
1
0
1
0
1
.. ... ... .., ... ... ......... .........
0
1
0
1
0
1
0
1
0
r
"''
0 f8000H
-
0 FFFFEH EAAOMr
0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 F8001H O<ld
0 1 1 r 1 1 0 0 0 r 1 1 1 1 1 1 . 1 1 1 1 1 FaFFFH EPROM2
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OOOOClli e....
1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 OFFFEH RAM1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 00001H O<ld
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 OFFFFH IW.I2
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 llOOOIIH .....
1 I 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 8FFFEH IW.I2
0
0
1
1
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
r
0
1
0
I
0
1
0
1
0
1
1 80001H
1 8FFFFH RAM2"""
Copyrighted material
Microprocessors and Interfacing p 11 808E System Configuration
'
I~
i
~~ro
.! A
11! ,....,
~
~
I~ ~<
'~~ro
'l. A
~
~
Ill
Q
I~ ,...., ,....,
L
:
~
'<
$ ~ ltl
Ill
A !
~
,...., 8
~
15
{
< '-
,....,
}w~ 1!1
L
I~
A
,...,
~ >.
,Jlo- .;
i
,,. ~ ,l!o. ~~
UJ u l ow
a ..-
<m<>
<I(GIOO
-y,,
II I
~
I
-1<1-0% I
iO I~ Ill~ I I-,.- ' ~ ~ ~ ,~
<<<< ID
.. II J1- U1-1 1~
~ I- ._
Fig. 5
Copyrighted material
Direct Memory Access
(DMA)- 8237/8257
(P 19)
Copyrighted material
8255 PPI (Programmable
Peripheral Interface)
. .
Q. 1 Explain how to interfn~ a stepptr mQtor with 4 step input stquen~ to 8086 bastd
system witl1 the lwlp of hardware design. Write the instruction sequen~ to move the
stepper motor 10 steps i11 clockwise tmd 12 steps in anti-clockwise direction.
[ApriiiM;oy-2005, Set-1, 16 Marks]
And. : Refer section 7.12.
Q. 2 Explain why 8255 ports are divided inl<> two groups. Discuss how these groups are
controlled in different modes of operation. Explain diffrrent control signals and their
associated pins for ui-directional 110 mode of operation.
(April/Moy-2005, Set-2, 16 Marks; NovJDec.-2005, Set..J, 16 Marks ;
April/May-2006, SetI, Set:Z. 8 Marks]
And. : Refer section 7.4.
Q. 3 lnterfnet :. 12-bit DAC to 8255 with an address map of OCOOH to OC03H. Tht DAC
provide-s output in th~ range of+ 5 V to - 5 V. Write the instruction sequence.
(a) For generating a square wave with a peak to peak voltage of 4V and the frequency
will be stltv:ted from memory location 'F'.
(b) For generating c triangulnr wave with a maximum voltage of + 3V and n
minimum of- 2 V. [Nov.!Oec. 2005, Set-1, 16 Marks)
Ans. :
Interface :
Please refer Fig. 1 on next page.
JOV
Resolution =
2 12 - I
= 2.442 mV
(P 20)
Copyrighted material
Mlcooprocesoors - ~lllorfacina P 21 1255 PPI (PfO!!!'!!I!INible P!!'!p!!!nll lntofface)
IIOo
AD
7
(
ADo
AD,
IPAo
PA7 -
MEMR - PBo
-
RD
I
MEMW ViR 2 DAC v.,..
5 P83
Reset Out Reset
5
PC0 Latch
Ao Ao
A, A,
cs
~
4/
")
.
Fig. 1
OOOH - 5V
FFFH +5V
7FFH ov -
4CCH -2V
..
CCCH 3V
E65H 4V
19AH - 4V
Copyrighted material
Mleroproceyors and Interfacing P- 22 8a55 P~ (f!!oJ!rsmmable Perlptl!rallnterlaee)
MVI
" OIH --~ -- -
STA OCOlH
MV! A, OIH ; Enab l~ latch signal
S'l'A OC02H
NOP '
MVIA, OOH
STA 0C02H
CAl.L Delay wait for OFF period
MVI A, 65 H Load and send digital data
STA OCOOH corresponds to + 4 V
MVI A, OEH
STA OCOl H
HV! A, OIH ; Enable latch siqnal
STA 0C02H
NOP
MVI A, DOH
STA OC02H
CALL Delay ; Wait f o r ON p~riod
JMPLOOP : 'Repeat
Copyrighted material
Mlcroprocnaon nd lnt.rfac:lng P 23 8255 PPI (P!'Oj!'!!!!!!!!blliPerifil'!rl lntert.c:e)
MOV A, L ; Check digital data foi pos itive
CP! CCH peak output (+3)
' JNZ LOOP!
MOV A, H
CP! OCH
JNZ LOOP!
LOOP2 : SHLD OCOOH ; Send digital data
CALL LATCH
DCX H Decrement di9ital data
MOV A, L ; Check digital data for negative
CP! CCH peak output (-2>
JNZ LOOP2
MOV A, H
CPI 04H
JNZ LOOP2
JMP BACK Repeat
LATCH : MVI A, OlH Enable l atch siqnal
STA 0C02H
NOP
MVI A, OOH
STA 0C02H
Q. 4 Write tile rzect'SSnry instruction sequrnce to inililllize 8255 rvitlt address OCOOH to
OC03H for flU! follmuing combinations.
a) Pori A as input port in mode 1 and port B as input port in mo,ie 1 without tire
interntpt driven 1/0.
b) Port A in modt 2 as output port and port B as iuput port iu mode 0 with
iuterrupt driven 1/0.
c) Port A in mode 0, port C upper lwlf as input ports and port 8 as input port in
m.ode 1 witiJ interrupt driven 1/0.
d) Port A as output port in mode I witlt activt intn-ntpt, port 8 as irrp11t port in
mode 0 and port C lowt'T lrnlf as output port in mode 0.
(Nov./Dec.-2005, Set-4, 16 Marks!
Ans. : Refer section 7.5.
Copyrighted material
MlcroprocHaors and Interfacing P 24 8255 PPI (Programmable Peripheral Interface)
".
'.
' ..
,-
Copyrighted material
Microprocessors-and Interfacing p - 26 8086 Interrupts
Q. 7 Addr.ss OOOEOH in the interrupt l'eclor table contains 4132H and address OOOE2H
cot~tains 0040H.
,-_.
l ... l
OOOE3H OOH CS (High)
Copyrighted material
MiC(Oprocessor:s and Interfacing p -27 ...,,..80861nterrupts
T '
39,pF 16 hi .. .
r
330K
"
10 ..
"
. ;[=
rJ '
32768 Hz 15MO
4060
3
a ,. Output frequency
2HZ
.' .
r-
'
n- "' ~F 11
8
J. Divide
by I-To NMI
2
Fig . 2
Algorithm (lntem.tpt service routine) :
1. Save registers.
2. Increment seconds.
3. If seconds = 60 , ake seconds = 0 and increment minutes.
4. If minutes :;; 60, ake minutes = 0 and increment hours.
5. If hours = 13, ake hours = 1.
6. Return to main program.
Q. 10 Write a11 initia/izntion S<'qllf.nce for an 8259 that is lilt 011/y 8259 in a11 8086 based
s_vstem, with n11 even addrrss of OFOH that wilt cauu.
a) Request to tire edge triggered motle
b) IR 0 r.,uest to a11 i11terrupt typo 30
c) SP/I?.N to output a disable signal to the data-bus trmtsceir,.rs "
d) The IMR to be cleared
t) Tht highest priority interrupt will be IR6. [NovJOec.-2005, Set-3, 16 Marks)
An$. : Refer section 8.5.5.
Q . 11 Draw the block diagram of 8259 and explai11 I'Jlch block ?
(Nov./Dec.-2005, Set-4. 8 Marks)
. .:.
Ans. : Refer section 8.5.2.
Q. 12 Under wlrat conditions type 0 interrupt is initiattd ? L1sl out the instructiOJJS that
may CllliSt type 0 intt rrupt. (April/May 2006, Set-1, Set-2.,Set-3, 6 Marks]
Ans. : Refer section 8.3.1.
Copyrighted material
Microprocessors and Interlacing p 28 8086 Interrupts
Copyrighted material
Serial Communication
I I I o I 1 I 1 I 1 I 1 I 1 I =DFH
'-v-' ~....__.,_....., Baud rate
2 saop Odd Char&Cter factor 64
bils parity ltllglh
8 . bils
Fig. 1
(P- 29)
Copyrighted material
Mlcroprocessors and Interfacing p. 31 Serial Communication
'
Copyrighted material
8051 Microcontroller
(P 32)
Copyrighted material
Mlcroproceoso111 and lnterfaclng p 33 8051 Mlcroconlroller
Copyrighted material
Contents I
tv.OWS'\.... --~- ~ ~80616. Mlu"4*\)CiS'Q. Spec.1i~d,...... ~ ~ fDibllg
- ond ......... d,.,., . .
Add~llQ onortrt. oii'QHb ~ wt ~ AOS6 ~ dddlws llmpW ~' fl'nxerdum.. .net MIDot
~ ~ proq,llml lnYOII.ng liJglc:N ~and c.l ~,.. ~J ~iOn ot arrthmetlc
AJ)rtlt'aun,, 'Kring n'lciMII)UWtQn
P\t\ dla(Jri)M ~ ~Mu11mum tt'l~ af'd triMlffl'.ml rnodll ~ C'lpllftldon. Timing <hlli'.J"'" Memotv nt~dltCinQ co
W)661$ttJC" RAM Met EPROM., ~lid for DMA. DMA dolt;) trnnsfet mnhod. ln.,trl"n"''l ~llh ~7'8257
825tt PPt VMifA mcxW ol ()f'lf'TNinn '"ld i~r,cmg to 8086. lnww f<KIWJ "~ 01~. Stepper motor &nd
~te~\lolkltt. OA. m'ld AD tofMir1it intertac:tng.
lrtrrvP' ,trt,lt'llnit ofHON>, V11m int.mupt k1b1,t._ !Norupr .,.,_'k:~ tW.fM' lntn)(iu&-:-n m I~ lind BIOS in'bmuph
~ PK: Cllthl~ .nd ,.,iet~M'tng ~ng ol intlm'ui'lt tanlmlk!f Mid Mllmpol'llbfi(.O!
sm...t d.6t.t ...~ ..;Nmt_, M;"ndwoncus and Sl,ndu:oncJul cl.t;a ....... ~.,...,.,_ KlSl U'Wn' atdl-.lfrrft -
~nMt.:mg. m ~o A::; 2J2C and RS232C., T1_ coo.'ft'Sion. ~ PfUIItN'rl "' MW ct.. rrcn.kr. ll"'trcduC!on 10
~--~USB-
~~~~adl4a:w ....... wti1051 Nodttal~~l80ft..~t1Ul~~
~ol.,l ~aondlOinlilf.-:'19t;O)l
---.- ...
I>H\ V l S-~1-8431-115-9
Technical Publications Pu ne
111, Amlt Rea,d e ncy, 412 Shaniwa r Peth, Pune 411030, M.S., India.
Te,efa.x t +91 (020) 24495496/97. Email: tchnlcai@Y1ubooke.com
V1sil us al www.vt.u books.com 4