• Название: The Intel Microprocessors 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium, Pentium Pro Processor, Pentium II, Pentium III, Pentium 4, and Core2 with 64-bit Extensions: Architecture, Programming, and Interfacing
  • Автор: Barry B. Brey

THE INTEL MICROPROCESSORS
8086/8088, 80186/80188, 80286, 80386,
80486, Pentium, Pentium Pro Processor,
Pentium II, Pentium III, Pentium 4, and Core2
with 64-Bit Extensions
Architecture, Programming, and Interfacing

Eighth Edition

BARRY B. BREY

Upper Saddle River, New Jersey
Columbus, Ohio

Library of Congress Cataloging in Publication Data
Brey, Barry B.
The Intel microprocessors 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium, Pentium
Pro processor, Pentium II, Pentium III, Pentium 4, and Core2 with 64-bit extensions:
architecture, programming, and interfacing / Barry B. Brey—8th ed.
p. cm.
Includes index.
ISBN 0-13-502645-8
1. Intel 80xxx series microprocessors. 2. Pentium (Microprocessor) 3. Computer interfaces.
I. Title.
QA76.8.I292B75 2009
004.165—dc22
2008009338

Editor in Chief: Vernon Anthony
Acquisitions Editor: Wyatt Morris
Editorial Assistant: Christopher Reed
Production Coordination: GGS Book Services
Project Manager: Jessica Sykes
Operations Specialist: Laura Weaver
Design Coordinator: Mike Fruhbeis
Cover Designer: Ilze Lemesis
Cover image: iStockphoto
Director of Marketing: David Gesell
Marketing Manager: Jimmy Stephens
Marketing Assistant: Les Roberts

This book was set in Times by GGS Book Services. It was printed and bound by Hamilton
Printing. The cover was printed by Phoenix Color Corp.

Copyright © 2009, 2006, 2003, 2000, 1997, 1994, 1991, 1987 by Pearson Education,
Inc., Upper Saddle River, New Jersey 07458. Pearson Prentice Hall. All rights reserved.
Printed in the United States of America. This publication is protected by Copyright and permission 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. For information regarding permission(s), write to:
Rights and Permissions Department.

Pearson Prentice Hall™ is a trademark of Pearson Education, Inc.
Pearson® is a registered trademark of Pearson plc
Prentice Hall® is a registered trademark of Pearson Education, Inc.

Pearson Education Ltd., London
Pearson Education Singapore Pte. Ltd.
Pearson Education Canada, Inc.
Pearson Education—Japan

Pearson Education Australia Pty. Limited
Pearson Education North Asia Ltd., Hong Kong
Pearson Educación de Mexico, S.A. de C.V.
Pearson Education Malaysia Pte. Ltd.

10 9 8 7 6 5 4 3 2 1
ISBN–13: 978–0–13–502645–8
ISBN–10:
0–13–502645–8

This text is dedicated to my progenies, Brenda (the programmer) and Gary (the
veterinarian technician), and to my constant four-legged companions: Romy,
Sassy, Sir Elton, Eye Envy, and Baby Hooter.

iii

This page intentionally left blank

PREFACE

This practical reference text is written for students who require a thorough knowledge of programming and interfacing of the Intel family of microprocessors. Today, anyone functioning or
striving to function in a field of study that uses computers must understand assembly language
programming, a version of C language, and interfacing. Intel microprocessors have gained wide,
and at times exclusive, application in many areas of electronics, communications, and control
systems, particularly in desktop computer systems. A major addition to this eighth edition
explains how to interface C/C++ using Visual C++ Express, which is a free download from
Microsoft, with assembly language for both the older DOS and the Windows environments.
Many applications include Visual C++ as a basis for learning assembly language using the inline
assembler. Updated sections that detail new events in the fields of microprocessors and microprocessor interfacing have been added.

ORGANIZATION AND COVERAGE
To cultivate a comprehensive approach to learning, each chapter begins with a set of objectives
that briefly define its content. Chapters contain many programming applications and examples
that illustrate the main topics. Each chapter ends with a numerical summary, which doubles as a
study guide, and reviews the information just presented. Questions and problems are provided
for reinforcement and practice, including research paper suggestions.
This text contains many example programs using the Microsoft Macro Assembler program
and the inline assembler in the Visual C++ environment, which provide a learning opportunity to
program the Intel family of microprocessors. Operation of the programming environment
includes the linker, library, macros, DOS function, BIOS functions, and Visual C/C++ program
development. The inline assembler (C/C++) is illustrated for both the 16- and 32-bit programming environments of various versions of Visual C++. The text is written to use Visual C++
Express 2005 or 2008 as a development environment, but any version of Visual Studio can also
be used with almost no change.
This text also provides a thorough description of family members, memory systems, and
various I/O systems that include disk memory, ADC and DAC, 16550 UART, PIAs, timers, keyboard/display controllers, arithmetic coprocessors, and video display systems. Also discussed are

v

vi

PREFACE

the personal computer system buses (AGP, ISA, PCI, PCI Express, USB, serial ports, and parallel
port). Through these systems, a practical approach to microprocessor interfacing can be learned.

APPROACH
Because the Intel family of microprocessors is quite diverse, this text initially concentrates on
real mode programming, which is compatible with all versions of the Intel family of microprocessors. Instructions for each family member, which include the 80386, 80486, Pentium,
Pentium Pro, Pentium II, Pentium III, and Pentium 4 processors, are compared and contrasted
with those for the 8086/8088 microprocessors. This entire series of microprocessors is very similar, which allows more advanced versions and their instructions to be learned with the basic
8086/8088. Please note that the 8086/8088 are still used in embedded systems along with their
updated counterparts, the 80186/80188 and 80386EX embedded microprocessor.
This text also explains the programming and operation of the numeric coprocessor, MMX
extension, and the SIMD extension, which function in a system to provide access to floatingpoint calculations that are important in control systems, video graphics, and computer-aided
design (CAD) applications. The numeric coprocessor allows a program to access complex
arithmetic operations that are otherwise difficult to achieve with normal microprocessor programming. The MMX and SIMD instructions allow both integer and floating-point data to be
manipulated in parallel at very high speed.
This text also describes the pin-outs and function of the 8086–80486 and all versions of the
Pentium microprocessor. First, interfacing is explained using the 8086/8088 with some of the
more common peripheral components. After explaining the basics, a more advanced emphasis is
placed on the 80186/80188, 80386, 80486, and Pentium through Pentium 4 microprocessors.
Coverage of the 80286, because of its similarity to the 8086 and 80386, is minimized so the
80386, 80486, and Pentium versions can be covered in complete detail.
Through this approach, the operation of the microprocessor and programming with the
advanced family members, along with interfacing all family members, provides a working and
practical background of the Intel family of microprocessors. Upon completing a course using
this text, you will be able to:
1. Develop software to control an application interface microprocessor. Generally, the software
developed will also function on all versions of the microprocessor. This software also
includes DOS-based and Windows-based applications. The main emphasis is on developing
inline assembly and C++ mixed language programs in the Windows environment.
2. Program using MFC controls, handlers, and functions to use the keyboard, video display
system, and disk memory in assembly language and C++.
3. Develop software that uses macro sequences, procedures, conditional assembly, and flow
control assembler directives that are linked to a Visual C++ program.
4. Develop software for code conversions using lookup tables and algorithms.
5. Program the numeric coprocessor to solve complex equations.
6. Develop software for the MMX and SIMD extensions.
7. Explain the differences between the family members and highlight the features of each member.
8. Describe and use real and protected mode operation of the microprocessor.
9. Interface memory and I/O systems to the microprocessor.
10. Provide a detailed and comprehensive comparison of all family members and their software
and hardware interfaces.
11. Explain the function of the real-time operating system in an embedded application.
12. Explain the operation of disk and video systems.
13. Interface small systems to the ISA, PCI, serial ports, parallel port, and USB bus in a personal
computer system.

PREFACE

vii

CONTENT OVERVIEW
Chapter 1 introduces the Intel family of microprocessors with an emphasis on the microprocessorbased computer system: its history, operation, and the methods used to store data in a
microprocessor-based system. Number systems and conversions are also included. Chapter 2
explores the programming model of the microprocessor and system architecture. Both real and
protected mode operations are explained.
Once an understanding of the basic machine is grasped, Chapters 3 through 6 explain how
each instruction functions with the Intel family of microprocessors. As instructions are
explained, simple applications are presented to illustrate the operation of the instructions and
develop basic programming concepts.
Chapter 7 introduces the use of Visual C/C++ Express with the inline assembler and separate assembly language programming modules. It also explains how to configure Visual C++
Express for use with assembly language applications.
After the basis for programming is developed, Chapter 8 provides applications using the
Visual C++ Express with the inline assembler program. These applications include programming
using the keyboard and mouse through message handlers in the Windows environment. Disk
files are explained using the File class, as well as keyboard and video operations on a personal
computer system through Windows. This chapter provides the tools required to develop virtually
any program on a personal computer system through the Windows environment.
Chapter 9 introduces the 8086/8088 family as a basis for learning basic memory and I/O
interfacing, which follow in later chapters. This chapter shows the buffered system as well as the
system timing.
Chapter 10 explains memory interface using both integrated decoders and programmable
logic devices using VHDL. The 8-, 16-, 32-, and 64-bit memory systems are provided so the
8086–80486 and the Pentium through Pentium 4 microprocessors can be interfaced to memory.
Chapter 11 provides a detailed look at basic I/O interfacing, including PIAs, timers, the
16550 UART, and ADC/DAC. It also describes the interface of both DC and stepper motors.
Once these basic I/O components and their interface to the microprocessor are understood,
Chapters 12 and 13 provide detail on advanced I/O techniques that include interrupts and direct
memory access (DMA). Applications include a printer interface, real-time clock, disk memory,
and video systems.
Chapter 14 details the operation and programming for the 8087–Pentium 4 family of arithmetic coprocessors, as well as MMX and SIMD instructions. Today few applications function
efficiently without the power of the arithmetic coprocessor. Remember that all Intel microprocessors since the 80486 contain a coprocessor; since the Pentium, an MMX unit; and since
the Pentium II, an SIMD unit.
Chapter 15 shows how to interface small systems to the personal computer through the use
of the parallel port, serial ports, and the ISA, and PCI bus interfaces.
Chapters 16 and 17 cover the advanced 80186/80188–80486 microprocessors and explore
their differences with the 8086/8088, as well as their enhancements and features. Cache memory,
interleaved memory, and burst memory are described with the 80386 and 80486 microprocessors. Chapter 16 also covers real-time operating systems (RTOS), and Chapter 17 also describes
memory management and memory paging.
Chapter 18 details the Pentium and Pentium Pro microprocessors. These microprocessors
are based upon the original 8086/8088.
Chapter 19 introduces the Pentium II, Pentium III, Pentium 4, and Core2 microprocessors.
It covers some of the new features, package styles, and the instructions that are added to the original instruction set.
Appendices are included to enhance the text. Appendix A provides an abbreviated listing
of the DOS INT 21H function calls because the use of DOS has waned. It also details the use of

viii

PREFACE

the assembler program and the Windows Visual C++ interface. A complete listing of all
8086–Pentium 4 and Core2 instructions, including many example instructions and machine coding in hexadecimal as well as clock timing information, is found in Appendix B. Appendix C
provides a compact list of all the instructions that change the flag bits. Answers for the evennumbered questions and problems are provided in Appendix D.
To access supplementary materials online, instructors need to request an instructor access
code. Go to www.pearsonhighered.com/irc, where you can register for an instructor access
code. Within 48 hours after registering, you will receive a confirming e-mail, including an
instructor access code. Once you have received your code, go to the site and log on for full
instructions on downloading the materials you wish to use.

Acknowledgments
I greatly appreciate the feedback from the following reviewers:
James K. Archibald, Brigham Young University
William H. Murray III, Broome Community College.

STAY IN TOUCH
We can stay in touch through the Internet. My Internet site contains information about all of my
textbooks and many important links that are specific to the personal computer, microprocessors,
hardware, and software. Also available is a weekly lesson that details many of the aspects of the
personal computer. Of particular interest is the “Technical Section,” which presents many notes
on topics that are not covered in this text. Please feel free to contact me at bbrey@ee.net if you
need any type of assistance. I usually answer all of my e-mail within 24 hours.
My website is http://members.ee.net/brey

BRIEF CONTENTS

CHAPTER 1

INTRODUCTION TO THE MICROPROCESSOR AND COMPUTER

CHAPTER 2

THE MICROPROCESSOR AND ITS ARCHITECTURE

51

CHAPTER 3

ADDRESSING MODES

77

CHAPTER 4

DATA MOVEMENT INSTRUCTIONS

111

CHAPTER 5

ARITHMETIC AND LOGIC INSTRUCTIONS

156

CHAPTER 6

PROGRAM CONTROL INSTRUCTIONS

192

CHAPTER 7

USING ASSEMBLY LANGUAGE WITH C/C++

223

CHAPTER 8

PROGRAMMING THE MICROPROCESSOR

250

CHAPTER 9

8086/8088 HARDWARE SPECIFICATIONS

302

CHAPTER 10

MEMORY INTERFACE

328

CHAPTER 11

BASIC I/O INTERFACE

377

CHAPTER 12

INTERRUPTS

451

CHAPTER 13

DIRECT MEMORY ACCESS AND DMA-CONTROLLED I/O

490

CHAPTER 14

THE ARITHMETIC COPROCESSOR, MMX, AND SIMD TECHNOLOGIES

531

CHAPTER 15

BUS INTERFACE

592

CHAPTER 16

THE 80185, 80188, AND 80286 MICROPROCESSORS

627

1

ix

x

BRIEF CONTENTS

CHAPTER 17

THE 80386 AND 80486 MICROPROCESSORS

677

CHAPTER 18

THE PENTIUM AND PENTIUM PRO MICROPROCESSORS

729

CHAPTER 19

THE PENTIUM II, PENTIUM III, PENTIUM 4, AND CORE2 MICROPROCESSORS

759

CONTENTS

CHAPTER 1

INTRODUCTION TO THE MICROPROCESSOR AND COMPUTER

1

Introduction/Chapter Objectives 1
1–1 A Historical Background 2
The Mechanical Age 2; The Electrical Age 2; Programming Advancements 4;
The Microprocessor Age 5; The Modern Microprocessor 7
1–2 The Microprocessor-Based Personal Computer System 17
The Memory and I/O System 17; The Microprocessor 25
1–3 Number Systems 29
Digits 29; Positional Notation 30; Conversion to Decimal 31; Conversion from Decimal 32;
Binary-Coded Hexadecimal 33
1–4 Computer Data Formats 35
ASCII and Unicode Data 35; BCD (Binary-Coded Decimal) Data 37; Byte-Sized Data 38;
Word-Sized Data 40; Doubleword-Sized Data 41; Real Numbers 43
1–5 Summary 45
1–6 Questions and Problems 46

CHAPTER 2

THE MICROPROCESSOR AND ITS ARCHITECTURE

51

Introduction/Chapter Objectives 51
2–1 Internal Microprocessor Architecture 51
The Programming Model 52; Multipurpose Registers 54
2–2 Real Mode Memory Addressing 58
Segments and Offsets 58; Default Segment and Offset Registers 60;
Segment and Offset Addressing Scheme Allows Relocation 60
2–3 Introduction to Protected Mode Memory Addressing 63
Selectors and Descriptors 63; Program-Invisible Registers 67
2–4 Memory Paging 68
Paging Registers 69; The Page Directory and Page Table 70
2–5 Flat Mode Memory 72
2–6 Summary 73
2–7 Questions and Problems 74

CHAPTER 3

ADDRESSING MODES

77

Introduction/Chapter Objectives 77
3–1 Data-Addressing Modes 78
Register Addressing 81; Immediate Addressing 83; Direct Data Addressing 86;
Register Indirect Addressing 88; Base-Plus-Index Addressing 91;

xi

xii

CONTENTS

3–2

3–3
3–4
3–5

CHAPTER 4

Register Relative Addressing 93; Base Relative-Plus-Index Addressing 96;
Scaled-Index Addressing 98; RIP Relative Addressing 99; Data Structures 99
Program Memory-Addressing Modes 100
Direct Program Memory Addressing 100; Relative Program Memory Addressing 101;
Indirect Program Memory Addressing 101
Sta