Ytha Yu, Charles Marut-Assembly Language Programming Organization of the IBM PC (1992)

February 20, 2017 | Author: harini | Category: N/A
Share Embed Donate


Short Description

Systems prigramming...

Description

Asse1nbly Langua.ge Programrriing and Organizat~on

of

the IBM PC

Ytha Yu

Department of Mathematics and Computer Science California State University, Hayward, California

Charles Marut

.

Department of Mathematics and Computer Science California State University, Hayward, California

Mitchell McCiAAW-Hlll

New York St. Lou1\ San

Franc1~0

Auddand Begot.\ Caraca\

l1\bon London Madrid Mexico Milan Montreal New Delhi Paris San Juan Singapore Sydney Tok)o Toronto

Wat\00\'1\le

ASSEl\ffiLY LANGUAGE PROGRAMMING & ORGANIZATION OF TIIE IDM PC International Editions 1992

Exclusi\'e rights by McGraw-Hill Boole: Co-Singapore for manufacture and export. Tiiis book cannot be re-exported from the country tO which it is consigned by McGraw-Hill. Copyright C 1992 by McGraw-Hill, Inc. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written pemlission of the publisher.

567890 KKP 98765

ISBN 0-07-072692-2 Sponi;Oring editor: Stephen Mitchell Eduorial assistant: Denise Nickeson Drrcctor of Production: Jane SomLTS Production assistant: Richard De Vitto Pro1cct management: BMR

Library of Congrcu Calalog Card Number 91-66269 Ill~

1s a regislcrcd trademark oflnternational Business Machines, Inc. Intel is a registered trademark of Microsoft Corporation.

When ordering lhis title, use ISBN 0--07-112896-4

Printed in Singapore

Dedication /11 memory of my father, Ping Chau

To my motlier, Monica To my wife, Joanne and our children Alan, Yolanda, and Brian

for my parents, Georsc For Beth

1111.t

/?111/i

Marut

Contents Preface xiii

Chapter 1 Microcomputer Systems 3

~apt~r2 ifepresentation of Numbers and Characters 19

Chapter 3 Organization of the IBM Personal Computers 31

1.1 The Components of a Microcomputer System 3 I.I.I Memory:. 4. 1.1.2 Tiie CPU 7 1.1.3 I/0 Port.s. 9 1.2 Instruction Execution 9 1.3 1/0 D~vices 1f · . 1.4 Progral!\ll1ing Languages fl , 1.5 An Assembly Language Program 14 Glossary 1s Exercises _11

2.1 2.2 2.3 2.4

Numtier Systems 19 , Conversion. Between Number Systems 22 Addition and Subtraction 24 How. Integers Are Represented in the Computer 2.4.1 Unsigr1£d Integers 26 · 2.4.2 Signed Integers 26 , 2A.3 · Decimal Interpretation 28 2.5 Character Representation 30 Sµmmary 33 · · · Glossary 34 Exerdses 34

26

3.1 ,The Intel 8086 Family of Microprocessors 37 3.2 Organization of the 8086/8088 Microprocessors 39 3.2.1 Registers 39 3.2.2 Data Registers: AX, BX, CX, DX 39 3.2.3 Segmc11t Registers: CS, DS, SS, ES 41 3.2.4 Pointer and Index Registers: SP, Bl~ SI, DI 44 3.2.5 Instruction Pointer: IP 45 . 3.2.6. _Fl:.AGS Register 45 3.3 Organization of the PC. 45 3.3.1 The Opera ti rig System 46 , 3.3.2 .Memory Orga11izatio11 of the PC 47 3.3.3 1/0 Port Addtesses 49 3.3.4 Start-up Operation' 49 · "'Summary 49 Glossary so Exercises 51

viii

Contents

Chapt~r

4

Introduction to IBM PC Assembly Language 53

4.1 Assembly Language Syntax 54 4.1.1 4.1.2 4.1 .3 4.1.4

Name Field 54 Operation Field SS Operand Field SS Comment Field SS

4.2 Program Data S6 4.3 Variables S7 4.3.1 Byte Variables 57 4.3.2 Word Variables 57 4.3.3 Arrays SB

4.4 Named Constants S9 4.5 A Few Basic Instructions 60 4.5.1 MOV and XCHG 60 4.5.2 ADD, SUll, INC, and DEC 62 4.5.3 NEG 64

4.6 Translation of High-Level Language to Assembly Language 64 4.7 Program Structure 6S 4.7. 1 4.7.2 4.7.3 -1.7.4 .J.7.5

Me111ory Models 65 Data Segment 66 Stack Sesment 66 Code Sesmc11t 66 f'utti11s It Tosctiler 67

4.8 Input and Output Instructions 67 4.8.1 INT 21~·67 4.9 A First PrograUV69 4.10 Creating and Running a Program 70 4.11 Displaying a String 73. 4.12 A Case Conversion Program 7!14 Summary 7~ Glossary 77 Exercises 78 Programming Exercises 80

Chapter 5 The Processor Status and the FLAGS Register 81

5. 1 The FLAGS Register 81 5.2 Overflow 83 5.3 How Imtruclions Affect the Flags BS 5.4 The DEi.JUG Program 87 Summary 90 Glossary· 91 Exercises 91

Jump

Chapter 6

6.1 An Example of a

Flow Control Instructions 93

6.2 Conditional Jumps 94 6.3 The JMP Instruction -!Is 6.4 High-Level Lan~uagc Structur~ 98 6.-1.1 Bm11«11111.i; St1uct11r11l "'68 6.-1.2 Loopins Structures 104 6.5 Programming with High-1.evel Structures 108

Summan· 112 Glossary. 113 Exercises 113 Programming Exercises

Chapter 7

Logic, Shift, ancl Rotate Instructions 117

7.1 Logic Instructions

93

115

118

__ _1.J.l_AND, OR,.and XOR J11strucno11SV119·

7.1 .2 NOT Instruction 12\, 7.1 .3 TEST lnstructio11 122 7 .2 Shift Instructions 12~

Contents

7.2.1 Left Shift l11Structions 123 7.2.2 · Rigllt Sllift Instructio11s 12's 7.3 Rotate Instructions 127'

7.4 Binary and Hex I/O 130 Summary 134 Glossary 135 Exercises 135 Programming Exercises 136

Chaoter 8 'the Stack and Introduction to Procedures 139.

Chapter 9 Multiplication and Division Instructions 161

:hapter 10 !lrrays and Addressing Vlodes r79

8.1 The Stack

139

, 8.2 A Stack Applicatio11 144

8.3 Terminology of Procedures

146

8.4 CALL and RET 147-

8.S An Example of a Procedure Summary 157 Glossary 158 Exercises 158 Program.m:rig Exercises 159

150.

9.1 MUL and IMUL 161 9.2 Simple Applicatiom of MUL and IMUL 164 9.3 DIV and IDIV 165 9.4 Sign Extension of the Dividend 166 9.5 Decimal Input and Output Procedures 167 Summary 175 Exercbcs 176 Programming Exercises 177

10.1 On'e·-Diinci1si~nal Arravs 10.2 Addressing Modes 181 •

179

10.2.1 Register /11dim:t Mode 182 10.2.2 Based aw/./11drxed Addressi11s Modes 184 lV.2.3 Tile 1"11< Upnator 1111d the LAllEL l'seudu-up 1t;16 10.2.4 Seg111mt Override 188 · 10.2.5 ·Acceisi11s tile Stack 189 10.3 An Application: Sorting an Array 189

10.4 Two-Dimensional Arrays .192 • 10.5 J3ascd Indexed Atldrcssing Mode 194 10.6 An Application: /,vernging Test Scores 10.7 The XLAT Instruction 197 Summary 200 Glos,ary 201

195

Exercises 201

Programming Exercises

hapter 11 'Je String Instructions 'JS •

·203

Til~ Direction flag 205 :\1o,·ini; a String 206. Store String 209 Load String 211 Scan String 214 Compare String 217 · 11 .6.1 Fi11di11s" Substring of a Stri11g 219 11.7 General Form of the String Imtructions. 223 Summarv 224 Glossary· 22s

11.1 11.2. 11.3 11.4 11.S 11.6

Exercises 225 l'rogram1.11ing

Exerci~e~

226

ix

x

Contents

Chapter 12 Text Display and Keyboard Programming 231

12.1 The Monitor 231 12.2 Video Adapters and Display Modes 12.3 Text Mode Programming 234

232

12.3.1 The Attribute Byte 235 12.3.2 A Display Page Demo11sl:Tation 237 12.3.3 INT JOH 238 12.3.4 A Comprehensive Example 243 The Keyboard 244

12.4 12.5 A Screen Editor 247 Summary 252 Glossary 253 Exercises 254 Programming Exercises 254

Chapter 13 Macros 257

Chapter 14 Memory Management 281

13.1 Macro Definition and Invocation 257 13.2 Local Labels 262 13.3 Macros That Invoke Other Macros 263 13.4 A Macro Library 264 13.5 Repetition Macros 268 13.6 An Output Macro 270 13.7 Conditionals 272 13.8 Macros and Procedures 27G Summary 276 Glossary 277 Exercises 278

14.1 .COM Programs 281 14.2 Program Modules 285 H.3 full Segment Definitions 291 14.3.1 Form o( an .EXE Program with Full Segment Defi11itio11s 295 14.3.2 Using the Full Segment Definitions 295

14.4 More About the Simplified Segment Definitions 14.5 Passing Data Between Procedures 300 14.5.1 Global Variables 300 · 14.5.2 Passing the Addresses o( the Data 302 14.5.3 Usi11g tile Stack 303

Summary 306 Glossary 306 Exercises 307 Programming Exercises 307

Chapter 15 BIOS and DOS Interrupts 309

1 5.1 Interrupt Service

309

15.1.1 I11tem1pl Vector 310 15.1.2 I11tc1TUpt Ro11ti11es 312

15.2 BIOS Interrupts 312 15.3 DOS Interrupts 316 15.4 A Time Display Program 316 15.S User Interrupt Procedures 318 15.6 Memory Resident Program 322 Summary 3.J9 Glossary 329 Exercises 330. Programming Exercises 330

299

Contents

Chapter 16 Color Graphics 331

-

Chapter 17 Recursion 357

Chapter 18 Advanced Arithmetic

~ 371

16.1 16.2 16-3 16.4 16.5 16.6

Graphics Modes 331 CGA Graphics 333 EGA Graphics 339 VGA Graphics 340 Animation 341 An Interactive Video Game 347 16.6.1 Adding Sound 347 16.6.2 Adding a Paddle 350 Summary 355 Glossary 356 · Ei,:erciscs 35.6 Programming Exercises 356

17 .1 The Idea of Recursion 357 17 .2 Recursive Procedures 358 17.3 Passing-Parameters on the Stack 360 17.4 The Activation Record 361 17.5 Implementation of Recursive Procequres 363 17 .6 - More Complex Recursion 367 Summar}' 369 Glossary· 369 Exercises 370 Programming Exercises 370

18. l

Double-Precision Numbers 371 18.1.1 Do,-1blc-Precisio11 Addition, Subtraction, and Negation 372 18.1.2 Do11ble-l'recision Multiplication and Division 374 18.2 Bir1arv-Codcd Decimal Numbers 374 1s:2.1 l'c1cked and U11p1Kked BCD 375 18-2.2' UCD Addition and tlle AAA lnstrnction 375 18.2-3 BCD S11btraclio11 and tile AAS lnstmction 377 18.2.4 /iC[) M11lliplication and lite AAM lmtmction 378 18.2.5 UCO Division and the Mb lnstr11ction 378 I8.3 1-loating-Point Numbers 379· 18.3.1 Co111·e11i11s Decimal Fraction$ i1110 llinary 379 18.3.2 Floatins-Puillt Represl!nt11tio11 380 Ui.3.3 Floati11s-l'oi11t Operations 380 18.4 The 8087 Nurnedc Processor 381 18.-1.l JJata Types 381 18.-1.2 S087 Jfrsiste1., 382 18.-1.3 J11.1t111ctiuns 382 18.-1.4 M11lliple-P1ccision Integer 110 384 18.4.5 R..:a1-Nw11bcr 1/0 389

Summary 391 Glossary 392 Exerci~cs

393

Programming Exercises 394·

Chapter 19 Disk and File Operations 395

19.1 Kinds of Disks 395 19.2 Disk Structure 397 19.2.1 Disk Capacity 398 19.2.2 Di.1k Acces.1 399 19.2.3 Fil
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF