Assembly Language Step-By-Step: Programming with DOS and Linux
Total Page:16
File Type:pdf, Size:1020Kb
Assembly Language Step-by-Step: Programming with DOS and Linux, Second Edition by Jeff Duntemann ISBN:0471375233 John Wiley & Sons © 2000 (613 pages) A “Lost World” journey into 16-bit assembler programming concepts and techniques. <?xml version="1.0" encoding="ISO-8859-1"?> Table of Contents Assembly Language Step-by-Step—Programming with DOS and Linux, Second Edition Foreword Introduction - "Why Would You Want to Do That?" Another Pleasant Valley Saturday Understanding What Computers Chapter 1 - Really Do Chapter 2 - Alien Bases Getting Your Arms around Binary and Hexadecimal Chapter 3 - Lifting the Hood Discovering What Computers Actually Are The Right to Assemble The Process of Making Assembly Language Chapter 4 - Programs NASM-IDE: A Place to Stand Give me a lever long enough, and a Chapter 5 - place to stand, and I will move the Earth. An Uneasy Alliance The x86 CPU and Its Segmented Memory Chapter 6 - System Following Your Instructions Meeting Machine Instructions up Close Chapter 7 - and Personal Chapter 8 - Our Object All Sublime Creating Programs that Work Dividing and Conquering Using Procedures and Macros to Battle Chapter 9 - Complexity Bits, Flags, Branches, and Tables Easing into Mainstream Chapter 10 - Assembly Programming Chapter 11 - Stringing Them Up Those Amazing String Instructions The Programmer's View of Linux Tools and Skills to Help You Write Chapter 12 - Assembly Code under a True 32-Bit OS Coding for Linux Applying What You've Learned to a True Chapter 13 - Protected Mode Operating System Conclusion - Not the End, But Only the Beginning Appendix A - Partial 8086/8088 Instruction Set Reference Appendix B - Segment Register Assumptions for Real Mode Segmented Model Appendix C - Web URLs for Assembly Programmers Appendix D - Segment Register Assumptions Appendix E - What's on the CD-ROM? Index List of Figures List of Tables Back Cover The bestselling guide to assembly language--now updated and expanded to include coverage of Linux. This new edition of the bestselling guide to assembly programming now covers DOS and Linux! The Second Edition begins with a highly accessible overview of the internal operations of the Intel-based PC and systematically covers all the steps involved in writing, testing, and debugging assembly programs. Expert author Jeff Duntemann then presents working example programs for both the DOS and Linux operating systems using the popular free assembler NASM. He also inlcudes valuable infomation on how to use procedures and macros, plus rare explanations of assembly-level coding for Linux, all of which combine to offer a comprehensive look at the complexitites of assembly programming for Intel processors. Providing you with the foundation to create executable assembly language programs, this book: Explains how to use NASM-IDE, a simple program editor and assembly-oriented development environment Details the most used elements of the 86-family instruction set Teaches about DEBUG, the single most useful tool you have as an assembly language programmer Examines the operations that machine instructions force the CPU to perform Discusses the process of memory addressing Covers coding for Linux About the Author Jeff Duntemann is the Editor-in-Chief of Visual Developer magazine, former editor of Turbo Technix and PC Techniques, the "Structured Programming" columnist for Dr. Dobb’s Journal, and has written and edited more than twenty programming books. Assembly Language Step-by-Step—Programming with DOS and Linux, Second Edition Jeff Duntemann Wiley Computer Publishing John Wiley & Sons, Inc. NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINGAPORE • TORONTO Publisher: Robert Ipsen Editor: Cary Sullivan Managing Editor: Micheline Frederick Text Design & Composition: North Market Street Graphics Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. Copyright © 2000 by Jeff Duntemann. All rights reserved. Published by John Wiley & Sons, Inc. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: <PERMREQ @ WILEY.COM>. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold with the understanding that the publisher is not engaged in professional services. If professional advice or other expert assistance is required, the services of a competent professional person should be sought. Library of Congress Cataloging-in-Publication Data: Duntemann, Jeff. Assembly language step-by-step : programming with DOS and Linux / Jeff Duntemann.—2nd ed. p. cm. Rev. ed. of: Assembly language, © 1992. ISBN 0-471-37523-3 (paper/CD-ROM : alk. paper) 1. Assembler language (Computer program language)I. Duntemann, Jeff. Assembly language.II. Title. QA76.73.A8 D88 2000 005.265—dc21 00-020611 10 9 8 7 6 5 4 3 2 1 To the eternal memory of Kathleen M. Duntemann, Godmother 1920–1999 who gave me books when all I could do was put teeth marks on them. There are no words for how much I owe you! Acknowledgments First of all, to the authors of the software that I am honored to provide by their permission on this book's CD-ROM: Robert Anderton, author of NASM-IDE: www.inglenook.co.uk/nasmide/ Anthony Williams, author of ALINK: http://alink.home.dhs.org/ And, of course, the NASM team: Julian "Jules" Hall, Simon Tatham, H. Peter Anvin, John Fine, Kendall Bennet, Gary Clark, and Andrew Crabtree: www.web-sites.co.uk/nasm/ Because of their generosity, there is "nothing else to buy." Everything you need to program in assembly is right here on the CD-ROM for this book. Abundant thanks also go to Bill Schindler, for teaching me the ways of the C library, and Michael Abrash, who has always has been the rock upon whom my knowledge of assembly language itself has been anchored. Finally, to Carol, as always, for the sacramental friendship that has challenged me, shaped me, and redeemed me every day of our 30 years together and 23 years as spouses. Foreword Time passes. It was exactly 10 years ago this summer, back in July 1989, when I turned in the manuscript of a book called Assembly Language from Square One. The book was well received, but its publisher went belly-up only a few months after its introduction. That may have been a blessing, because the book was too short, had a few more errors in it than it should have had, and was printed on horrible cheap paper that ripped with almost no provocation and is now turning sickly yellow. So, I leapt on the chance to do the book over and publish it with a real publisher, the most venerable John Wiley & Sons, who (as their T-shirts say) has been totally awesome since 1809. It was thoroughly rewritten and became a new book with a new title, and went on the shelves in September of 1992. Time passes, but in a world where the life of a computer book may well be eight months or less, Wiley kept the first edition of Assembly Language Step-by-Step in print for eight years, from 1992 to 2000. In that time it has probably sold more copies than any other single assembly language book, and I've received hundreds of letters of advice, corrections, suggestions, and simple, "Hey, this is cool!" compliments. Thanks to you all for taking the time to write. It means a lot to me. It's unclear how long this second edition will remain in print, but as long as people keep buying it (and telling me it's been useful to them), I suspect that either this edition or one to follow will remain available. Time passes. And before we get into the book proper, there's something else I wanted to relate. On July 8, 1999, my sister Gretchen Duntemann Roper found that Kathleen Duntemann had died peacefully in her sleep in Chicago, almost 10 years to the day since I had completed Assembly Language from Square One, which was also dedicated to her. She kept both books on her coffee table and would show them to anyone who came to visit, even though she never had a computer and probably never understood what assembly language was. She was my aunt and godmother, my father's sole sibling, who sang my ABCs to me and demanded that I be admitted to Adler Planetarium in Chicago when I was six, even though the rules at that time demanded that children be seven to attend the sky show. "Name the planets for the nice man," she told me, and I did, and when I had gone through all the planets I started in on the constellations. I got in, because she believed in me. And she was there through every other major milestone in my life: First Communion, Confirmation, wedding, my father's illness and death, years and years of Christmases and Thanksgivings and birthdays, always with treats for the dog and stories to tell, with a quick Irish wit and a generous heart-and truly I cannot and will not ever forget her.