ebook img

Assembly Language for x86 Processors (6th Edition) PDF

747 Pages·2010·1.825 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Assembly Language for x86 Processors (6th Edition)

Assembly Language for x86 Processors Sixth Edition KIP R. IRVINE Florida International University School of Computing and Information Sciences Upper Saddle River Boston Columbus San Francisco New York Indianapolis London Toronto Sydney Singapore Tokyo Montreal Dubai Madrid Hong Kong Mexico City Munich Paris Amsterdam Cape Town Vice President and Editorial Director, ECS: Marcia J. Horton Editor-in-Chief: Michael Hirsch Executive Editor: Tracy Dunkelberger Assistant Editor: Melinda Haggerty Editorial Assistant: Allison Michael Vice President, Production: Vince O’Brien Senior Managing Editor: Scott Disanno Production Liaison: Jane Bonnell Production Editor: Maheswari PonSaravanan, TexTech International Senior Operations Supervisor: Alan Fischer Marketing Manager: Erin Davis Marketing Assistant: Mack Patterson Art Director: Kenny Beck Cover Designer: Laura C. Ierardi Cover Image: Color enhanced x-ray of nautilus shell / Bert Myers / Science Photo Library Art Editor: Greg Dulles Media Editor: Daniel Sandin Media Project Manager: Danielle Leone Composition/Full-Service Project Management: TexTech International IA-32, Pentium, i486, Intel64, Celeron, and Intel 386 are trademarks of Intel Corporation. Athlon, Phenom, and Opteron are trademarks of Advanced Micro Devices. TASM and Turbo Debugger are trademarks of Borland International. Microsoft Assembler (MASM), Windows Vista, Windows 7, Windows NT, Windows Me, Windows 95, Windows 98, Windows 2000, Windows XP, MS-Windows, PowerPoint, Win32, DEBUG, WinDbg, MS-DOS, Visual Studio, Visual C++, and CodeView are registered trademarks of Microsoft Corporation. Autocad is a trademark of Autodesk. Java is a trademark of Sun Microsystems. PartitionMagic is a trademark of Symantec. All other trademarks or product names are the property of their respective owners. Copyright © 2011, 2007, 2003, 1999 by Pearson Education, Inc., Upper Saddle River, New Jersey 07458. All rights reserved. Manufactured in the United States of America. This publication is protected by Copyright and permissions should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use materials from this work, please submit a written request to Pearson Higher Education, Permissions Department, 1 Lake Street, Upper Saddle River, NJ 07458. Previously published as Assembly Language for Intel-Based Computers. The author and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The author and pub- lisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation contained in this book. The author and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs. Library of Congress Cataloging-in-Publication Data Irvine, Kip R. Assembly language for x86 processors / Kip R. Irvine. -- 6th ed. p. cm. Rev. ed. of: Assembly language for intel-based computers, 5th ed., 2007. ISBN 0-13-602212-X (alk. paper) 1. IBM microcomputers--Programming. 2. Assembler language (Computer program language) I. Irvine, Kip R. - Assembly language for intel-based computers. II. Title. QA76.8.I77 2011 005.265--dc22 2009049014 10 9 8 7 6 5 4 3 2 1 ISBN-13: 978-0-13-602212-1 ISBN-10: 0-13-602212-X To Jack and Candy Irvine This page intentionally left blank Contents Preface xix 1 Basic Concepts 1 1.1 Welcome to Assembly Language 1 1.1.1 Good Questions to Ask 2 1.1.2 Assembly Language Applications 5 1.1.3 Section Review 6 1.2 Virtual Machine Concept 7 1.2.1 Section Review 9 1.3 Data Representation 9 1.3.1 Binary Integers 9 1.3.2 Binary Addition 11 1.3.3 Integer Storage Sizes 12 1.3.4 Hexadecimal Integers 13 1.3.5 Signed Integers 15 1.3.6 Character Storage 17 1.3.7 Section Review 19 1.4 Boolean Operations 22 1.4.1 Truth Tables for Boolean Functions 24 1.4.2 Section Review 26 1.5 Chapter Summary 26 1.6 Exercises 27 1.6.1 Programming Tasks 27 1.6.2 Nonprogramming Tasks 27 2 x86 Processor Architecture 29 2.1 General Concepts 29 2.1.1 Basic Microcomputer Design 30 2.1.2 Instruction Execution Cycle 31 2.1.3 Reading from Memory 33 2.1.4 How Programs Run 34 2.1.5 Section Review 35 v vi Contents 2.2 x86 Architecture Details 36 2.2.1 Modes of Operation 36 2.2.2 Basic Execution Environment 36 2.2.3 Floating-Point Unit 39 2.2.4 Overview of Intel Microprocessors 39 2.2.5 Section Review 42 2.3 x86 Memory Management 43 2.3.1 Real-Address Mode 43 2.3.2 Protected Mode 45 2.3.3 Section Review 47 2.4 Components of a Typical x86 Computer 48 2.4.1 Motherboard 48 2.4.2 Video Output 50 2.4.3 Memory 50 2.4.4 Input-Output Ports and Device Interfaces 50 2.4.5 Section Review 52 2.5 Input-Output System 52 2.5.1 Levels of I/O Access 52 2.5.2 Section Review 55 2.6 Chapter Summary 55 2.7 Chapter Exercises 57 3 Assembly Language Fundamentals 58 3.1 Basic Elements of Assembly Language 58 3.1.1 Integer Constants 59 3.1.2 Integer Expressions 60 3.1.3 Real Number Constants 61 3.1.4 Character Constants 61 3.1.5 String Constants 61 3.1.6 Reserved Words 62 3.1.7 Identifiers 62 3.1.8 Directives 62 3.1.9 Instructions 63 3.1.10 The NOP (No Operation) Instruction 65 3.1.11 Section Review 66 3.2 Example: Adding and Subtracting Integers 66 3.2.1 Alternative Version of AddSub 69 3.2.2 Program Template 70 3.2.3 Section Review 70 3.3 Assembling, Linking, and Running Programs 71 3.3.1 The Assemble-Link-Execute Cycle 71 3.3.2 Section Review 77 Contents vii 3.4 Defining Data 77 3.4.1 Intrinsic Data Types 77 3.4.2 Data Definition Statement 77 3.4.3 Defining BYTE and SBYTE Data 78 3.4.4 Defining WORD and SWORD Data 80 3.4.5 Defining DWORD and SDWORD Data 81 3.4.6 Defining QWORD Data 81 3.4.7 Defining Packed Binary Coded Decimal (TBYTE) Data 82 3.4.8 Defining Real Number Data 83 3.4.9 Little Endian Order 83 3.4.10 Adding Variables to the AddSub Program 84 3.4.11 Declaring Uninitialized Data 85 3.4.12 Section Review 85 3.5 Symbolic Constants 86 3.5.1 Equal-Sign Directive 86 3.5.2 Calculating the Sizes of Arrays and Strings 87 3.5.3 EQU Directive 88 3.5.4 TEXTEQU Directive 89 3.5.5 Section Review 90 3.6 Real-Address Mode Programming (Optional) 90 3.6.1 Basic Changes 90 3.7 Chapter Summary 91 3.8 Programming Exercises 92 4 Data Transfers, Addressing, and Arithmetic 94 4.1 Data Transfer Instructions 94 4.1.1 Introduction 94 4.1.2 Operand Types 95 4.1.3 Direct Memory Operands 96 4.1.4 MOV Instruction 96 4.1.5 Zero/Sign Extension of Integers 98 4.1.6 LAHF and SAHF Instructions 100 4.1.7 XCHG Instruction 100 4.1.8 Direct-Offset Operands 101 4.1.9 Example Program (Moves) 102 4.1.10 Section Review 103 4.2 Addition and Subtraction 104 4.2.1 INC and DEC Instructions 104 4.2.2 ADD Instruction 104 4.2.3 SUB Instruction 105 4.2.4 NEG Instruction 105 viii Contents 4.2.5 Implementing Arithmetic Expressions 106 4.2.6 Flags Affected by Addition and Subtraction 106 4.2.7 Example Program (AddSub3) 110 4.2.8 Section Review 111 4.3 Data-Related Operators and Directives 112 4.3.1 OFFSET Operator 112 4.3.2 ALIGN Directive 113 4.3.3 PTR Operator 114 4.3.4 TYPE Operator 115 4.3.5 LENGTHOF Operator 115 4.3.6 SIZEOF Operator 116 4.3.7 LABEL Directive 116 4.3.8 Section Review 117 4.4 Indirect Addressing 117 4.4.1 Indirect Operands 118 4.4.2 Arrays 119 4.4.3 Indexed Operands 120 4.4.4 Pointers 121 4.4.5 Section Review 123 4.5 JMP and LOOP Instructions 124 4.5.1 JMP Instruction 124 4.5.2 LOOP Instruction 124 4.5.3 Summing an Integer Array 126 4.5.4 Copying a String 126 4.5.5 Section Review 127 4.6 Chapter Summary 128 4.7 Programming Exercises 129 5 Procedures 132 5.1 Introduction 132 5.2 Linking to an External Library 132 5.2.1 Background Information 133 5.2.2 Section Review 134 5.3 The Book’s Link Library 134 5.3.1 Overview 136 5.3.2 Individual Procedure Descriptions 137 5.3.3 Library Test Programs 149 5.3.4 Section Review 157 5.4 Stack Operations 157 5.4.1 Runtime Stack 158 5.4.2 PUSH and POP Instructions 160 5.4.3 Section Review 162 Contents ix 5.5 Defining and Using Procedures 163 5.5.1 PROC Directive 163 5.5.2 CALL and RET Instructions 165 5.5.3 Example: Summing an Integer Array 168 5.5.4 Flowcharts 169 5.5.5 Saving and Restoring Registers 170 5.5.6 Section Review 171 5.6 Program Design Using Procedures 172 5.6.1 Integer Summation Program (Design) 173 5.6.2 Integer Summation Implementation 175 5.6.3 Section Review 177 5.7 Chapter Summary 177 5.8 Programming Exercises 178 6 Conditional Processing 180 6.1 Introduction 180 6.2 Boolean and Comparison Instructions 181 6.2.1 The CPU Flags 182 6.2.2 AND Instruction 182 6.2.3 OR Instruction 183 6.2.4 Bit-Mapped Sets 184 6.2.5 XOR Instruction 186 6.2.6 NOT Instruction 187 6.2.7 TEST Instruction 187 6.2.8 CMP Instruction 188 6.2.9 Setting and Clearing Individual CPU Flags 189 6.2.10 Section Review 189 6.3 Conditional Jumps 190 6.3.1 Conditional Structures 190 6.3.2 Jcond Instruction 191 6.3.3 Types of Conditional Jump Instructions 192 6.3.4 Conditional Jump Applications 195 6.3.5 Section Review 199 6.4 Conditional Loop Instructions 200 6.4.1 LOOPZ and LOOPE Instructions 200 6.4.2 LOOPNZ and LOOPNE Instructions 201 6.4.3 Section Review 201 6.5 Conditional Structures 202 6.5.1 Block-Structured IF Statements 202 6.5.2 Compound Expressions 204 6.5.3 WHILE Loops 206 6.5.4 Table-Driven Selection 208 6.5.5 Section Review 210

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.