The Art of 64-Bit Assembly Volume 1
x86-64 Machine Organization and Programming
Randall Hyde
THE ART OF 64-BIT ASSEMBLY, VOLUME 1. Copyright 2022 by Randall Hyde.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13: 978-1-7185-0108-9 (print)
ISBN-13: 978-1-7185-0109-6 (ebook)
Publisher: William Pollock
Production Manager: Rachel Monaghan
Production Editors: Katrina Taylor and Miles Bond
Developmental Editors: Athabasca Witschi and Nathan Heidelberger
Cover Design: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Anthony Tribelli
Copyeditor: Sharon Wilkey
Compositor: Jeff Lytle, Happenstance Type-O-Rama
Proofreader: Sadie Barry
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1-415-863-9900; info@nostarch.com
www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Names: Hyde, Randall, author.
Title: The art of 64-bit assembly. Volume 1, x86-64 machine organization
and programming / Randall Hyde.
Description: San Francisco : No Starch Press Inc, 2022. | Includes
bibliographical references and index. |
Identifiers: LCCN 2021020214 (print) | LCCN 2021020215 (ebook) | ISBN
9781718501089 (print) | ISBN 9781718501096 (ebook)
Subjects: LCSH: Assembly languages (Electronic computers)
Classification: LCC QA76.73.A8 H969 2022 (print) | LCC QA76.73.A8 (ebook)
| DDC 005.13/6--dc23
LC record available at https://lccn.loc.gov/2021020214
LC ebook record available at https://lccn.loc.gov/2021020215
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
To my wife, Mandy. In the second edition of The Art of Assembly Language, I mentioned that it had been a great 30 years and I was looking forward to another 30. Now its been 40, so I get to look forward to at least another 20!
About the Author
Randall Hyde is the author of The Art of Assembly Language and Write Great Code, Volumes 1, 2, and 3 (all from No Starch Press), as well as Using 6502 Assembly Language and P-Source (Datamost). He is also the coauthor of Microsoft Macro Assembler 6.0 Bible (The Waite Group). Over the past 40 years, Hyde has worked as an embedded software/hardware engineer developing instrumentation for nuclear reactors, traffic control systems, and other consumer electronics devices. He has also taught computer science at California State Polytechnic University, Pomona, and at the University of California, Riverside. His website is http://www.randallhyde.com/.
About the Tech Reviewer
Tony Tribelli has more than 35 years of experience in software development. This experience ranges, among other things, from embedded device kernels to molecular modeling and visualization to video games. The latter includes ten years at Blizzard Entertainment. He is currently a software development consultant and privately develops applications utilizing computer vision.
Foreword
Assembly language programmers often hear the question, Why would you bother when there are so many other languages that are much easier to write and to understand? There has always been one answer: you write assembly language because you can.
Free of any other assumptions, free of artificial structuring, and free of the restrictions that so many other languages impose on you, you can create anything that is within the capacity of the operating system and the processor hardware. The full capacity of the x86 and later x64 hardware is available to the programmer. Within the boundaries of the operating system, any structure that is imposed, is imposed by the programmer in the code design and layout that they choose to use.
There have been many good assemblers over time, but the use of the Microsoft assembler, commonly known as MASM, has one great advantage: it has been around since the early 1980s, and while others come and go, MASM is updated on an as-needed basis for technology and operating system changes by the operating system vendor Microsoft.
From its origins as a real-mode 16-bit assembler, over time and technology changes it has been updated to a 32-bit version. With the introduction of 64-bit Windows, there is a 64-bit version of MASM as well that produces 64-bit object modules. The 32- and 64-bit versions are components in the Visual Studio suite of tools and can be used by both C and C++ as well as pure assembler executable files and dynamic link libraries.
Randall Hydes original The Art of Assembly Language has been a reference work for nearly 20 years, and with the authors long and extensive understanding of x86 hardware and assembly programming, a 64-bit version of the book is a welcome addition to the total knowledge base for future high-performance x64 programming.
Steve Hutchesson
https://www.masm32.com/
Acknowledgments
Several individuals at No Starch Press have contributed to the quality of this book and deserve appropriate kudos for all their effort:
- Bill Pollock, president
- Barbara Yien, executive editor
- Katrina Taylor, production editor
- Miles Bond, assistant production editor
- Athabasca Witschi, developmental editor
- Nathan Heidelberger, developmental editor
- Natalie Gleason, marketing manager
- Morgan Vega Gomez, marketing coordinator
- Sharon Wilkey, copyeditor
- Sadie Barry, proofreader
- Jeff Lytle, compositor
Randall Hyde
Introduction
This book is the culmination of 30 years work. The very earliest versions of this book were notes I copied for my students at Cal Poly Pomona and UC Riverside under the title How to Program the IBM PC Using 8088 Assembly Language. I had lots of input from students and a good friend of mine, Mary Philips, that softened the edges a bit. Bill Pollock rescued that early version from obscurity on the internet, and with the help of Karol Jurado, the first edition of The Art of Assembly Language became a reality in 2003.
Thousands of readers (and suggestions) later, along with input from Bill Pollock, Alison Peterson, Ansel Staton, Riley Hoffman, Megan Dunchak, Linda Recktenwald, Susan Glinert Stevens, and Nancy Bell at No Starch Press (and a technical review by Nathan Baker), the second edition of this book arrived in 2010.