The art of assembly language 2003

1.4K 192 0
The art of assembly language 2003

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

The Art of Assembly Language ISBN:1886411972 by Randall Hyde No Starch Press © 2003 (903 pages) Presenting assembly language from the high-level programmer's point of view, this guide explains how to edit, compile, and run an HLA program, convert high level control structures, translate arithmetic expressions, and more CD Content Table of Contents The Art of Assembly Language Hello, World of Assembly Chapter 1 Language Chapter 2 - Data Representation Memory Access and Chapter 3 Organization Constants, Variables, and Chapter 4 Data Types Chapter 5 - Procedures and Units Chapter 6 - Arithmetic Low Level Control Chapter 7 Structures Chapter 8 - Files Chapter 9 - Advanced Arithmetic Macros and the HLA Chapter 10 Compile Time Language Chapter 11 - BIT Manipulation Chapter 12 - The String Instructions Chapter 13 - The MMX Instruction Set Chapter 14 - Classes and Objects Mixed Language Chapter 15 Programming Appendix A - ASCII Character Set The 80 × 86 Instruction Appendix B Set Index List of Figures List of Tables List of Listings CD Content Back Cover Assembly language is easier than ever, thanks to modern development tools and The Art of Assembly Language After a decade of rigorous end-user testing of the online version, The Art of Assembly Language is an indispensable reference for using assembly to write powerful programs and solve real-world problems Hyde has updated his book to include the latest in 32bit x86 architecture, as well as the High Level Assembler (HLA), a revolutionary tool that leverages your knowledge of high level programming languages like C/C++ and Pascal/Delphi to streamline your learning process Learn how to: Edit, compile, and run a High Level Assembler (HLA) program Declare and use constants, scalar variables, integers, reals, data types, pointers, arrays, records/structures, unions, and namespaces Translate arithmetic expressions (integer and floating point) Convert high level control structures Interface with high level programming languages About the Author Randall Hyde has taught assembly language at the university level for over a decade, and has developed several commercial software systems His website, “Webster: The Place on the Net to Learn Assembly Language Programming,” is the premier destination for anyone learning assembly Hyde is the author of How to Program the Apple II Using 6502 Assembly Language and co-author of The Waite Group’s MASM 6.0 Bible The Art of Assembly Language Randall Hyde NO STARCH PRESS San Francisco Copyright © 2003 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 1 2 3 4 5 6 7 8 9 10 – 06 05 04 03 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 Publisher: William Pollock Managing Editor: Karol Jurado Cover and Interior Design: Octopod Studios Copyeditor: Kenyon Brown Proofreader: Stephanie Provines Compositor: Wedobooks Distributed to the book trade in the United States by Publishers Group West, 1700 Fourth Street, Berkeley, CA 94710; phone: 800-788-3123; fax: 510-658-1834 Distributed to the book trade in Canada by Jacqueline Gross & Associates, Inc., One Atlantic Avenue, Suite 105, Toronto, Ontario M6K 3E7 Canada; phone: 416-531-6737; fax 416-531 - 4259 For information on translations or book distributors outside the United States, please contact No Starch Press, Inc directly: No Starch Press, Inc 555 De Haro Street, Suite 250, San Francisco, CA 94107 phone: 415-863-9900; fax: 415-863-9950; info@nostarch.com; http://www.nostarch.com 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 Library of Congress Cataloguing-in-Publication Data Hyde, Randall The art of assembly language / Randall Hyde p cm 1-886411-97-2 Assembly language (Computer program language) 2 Programming languages (Electronic computers) I Title QA76.73.A8H97 2003 005.13′6–dc21 2003000471 ACKNOWLEDGMENTS This book has literally taken over a decade to create It started out as "How to Program the IBM PC, Using 8088 Assembly Language" way back in 1989 I originally wrote this book for the students in my assembly language course at Cal Poly Pomona and UC Riverside Over the years, hundreds of students have made small and large contributions (it's amazing how a little extra credit can motivate some students) I've also received thousands of comments via the Internet after placing an early, 16-bit edition of this book on my website at UC Riverside I owe everyone who has contributed to this effort my gratitude I would also like to specifically thank Mary Phillips, who spent several months helping me proofread much of the 16-bit edition upon which I've based this book Mary is a wonderful person and a great friend I also owe a deep debt of gratitude to William Pollock at No Starch Press, who rescued this book from obscurity He is the one responsible for convincing me to spend some time beating on this book to create a publishable entity from it I would also like to thank Karol Jurado for shepherding this project from its inception — it's been a long, hard road Thanks, Karol Chapter 1: Hello, World of Assembly Language Download CD Content 1.1 Chapter Overview This chapter is a "quick-start" chapter that lets you start writing basic assembly language programs as rapidly as possible This chapter: Presents the basic syntax of an HLA (High Level Assembly) program Introduces you to the Intel CPU architecture Provides a handful of data declarations, machine instructions, and high level control statements Describes some utility routines you can call in the HLA Standard Library Shows you how to write some simple assembly language programs By the conclusion of this chapter, you should understand the basic syntax of an HLA program and should understand the prerequisites that are needed to start learning new assembly language features in the chapters that follow 1.2 The Anatomy of an HLA Program A typical HLA program takes the form shown in Figure 1-1 Figure 1-1: Basic HLA Program pgmID in the template above is a user-defined program identifier You must pick an appropriate, descriptive name for your program In particular, pgmID would be a horrible choice for any real program If you are writing programs as part of a course assignment, your instructor will probably give you the name to use for your main program If you are writing your own HLA program, you will have to choose an appropriate name for your project Identifiers in HLA are very similar to identifiers in most high level languages HLA identifiers may begin with an underscore or an alphabetic character, and may be followed by zero or more alphanumeric or underscore characters HLA's identifiers are case neutral This means that the identifiers are case sensitive insofar as you must always spell an identifier exactly the same way in your program (even with respect to upper and lower case) However, unlike case sensitive languages like C/C++, you may not declare two identifiers in the program whose name differs only by alphabetic case A traditional first program people write, popularized by Kernighan and Ritchie's The C Programming Language is the Hello World program This program makes an excellent concrete example for someone who is learning a new language Listing 1-1 presents the HLA Hello World program Listing 1-1: The Hello World Program program helloWorld; Chapter 1: Hello, World of Assembly Language Listing 1-1: The Hello World Program Listing 1-2: Variable Declaration and Use Listing 1-3: Demonstration of MOV, ADD, and SUB Instructions Listing 1-4: Columnar Output Demonstration Using stdio.Puti32Size Listing 1-5: Demonstration of stdout.put Field Width Specification Listing 1-6: Demonstration of the stdin.getc() Routine Listing 1-7: stdin.getiX Example Code Listing 1-8: TRY ENDTRY Example Listing 1-9: Nested TRY ENDTRY Statements Listing 1-10: Improperly Exiting a TRY ENDTRY Statement Listing 1-11: The TRY ENDTRY UNPROTECTED Section Chapter 2: Data Representation Listing 2-1: Decimal to Hexadecimal Conversion Program Listing 2-2: Hexadecimal to Decimal Conversion Program Listing 2-3: Variable-less Hexadecimal to Decimal Converter Listing 2-4: Demonstration of stdin.getd and stdout.putd Listing 2-5: AND, OR, XOR, and NOT Example Listing 2-6: AND, OR, XOR, and NOT Example Listing 2-7: Unsigned I/O Listing 2-8: Sign Extension Instructions Listing 2-9: Packing and Unpacking Date Data Listing 2-10: Character Input Sample Listing 2-11: stdin.get Character Input Sample Listing 2-12: Testing for End of Line Using Stdin.eoln Chapter 3: Memory Access and Organization Listing 3-1: Demonstration of Address Expressions Chapter 4: Constants, Variables, and Data Types Listing 4-1: Demonstration of the BOUND Instruction Listing 4-2: Demonstration of the INTO Instruction Listing 4-3: Data Alignment Program Rewritten Using CONST Definitions Listing 4-4: Demonstration of VAL Redefinition Using "?" Operator Listing 4-5: Pointer Constant Expressions in an HLA Program Listing 4-6: Uninitialized Pointer Demonstration Listing 4-7: Type-Unsafe Pointer Access Example Listing 4-8: Accessing the Length and Maximum Length Fields of a String Listing 4-9: Correct Way to Access Length and MaxStrLen Fields of a String Listing 4-10: Reading a String from the User Listing 4-11: Corrected Program That Reads a String from the User Listing 4-12: Reading a String from the User with stdin.a_gets Listing 4-13: Problem with String Assignment by Copying Pointers Listing 4-14: Copying Strings Using str.cpy Listing 4-15: Copying Strings Using str.a_cpy Listing 4-16: Demonstration of str.cat and str.a_cat Routines Chapter 5: Procedures and Units Listing 5-1: Example of a Simple Procedure Listing 5-2: Program with an Unintended Infinite Loop Listing 5-3: Demonstration of Caller Register Preservation Listing 5-4: Demonstrating That Caller Preservation Need Not Save All Registers Listing 5-5: Demonstration of Global Scope Listing 5-6: Example of a Local Variable in a Procedure Listing 5-7: Local Variables Need Not Have Globally Unique Names Listing 5-8: Accessing Pass by Reference Parameters Listing 5-9: Recursive Quicksort Program Listing 5-10: Effect of Missing RET Instruction in a Procedure Listing 5-11: Effect of Popping Too Much Data off the Stack Listing 5-12: Print Procedure Implementation (Using Code Stream Parameters) Listing 5-13: Demonstration of Value Parameters Listing 5-14: Manually Passing Parameters on the Stack Listing 5-15: Passing the Result of Some Arithmetic Expression as a Parameter Listing 5-16: Accessing a Reference Parameter Listing 5-17: Passing an Array of Records by Referencing Listing 5-18: The stdlib.hhf Header File, as of 01/01/2000 Listing 5-19: Example of a Simple HLA Unit Listing 5-20: Main Program That References External Objects Listing 5-21: Modified Main Program with Extrenal Declarations Listing 5-22: Correct Number1 Unit with External Declarations Chapter 7: Low Level Control Structures Listing 7-1: Displaying the Address of Statement Labels in a Program Listing 7-2: Initializing DWORD Variables with the Address of Statement Labels Listing 7-3: Using Register Indirect JMP Instructions Listing 7-4: Using Memory Indirect JMP Instructions Chapter 8: Files Listing 8-1: A Simple File Output Program Listing 8-2: A Sample File Input Program Listing 8-3: Another Sample File Input Program Listing 8-4: Demonstration of the fileio.Append Routine Listing 8-5: fileio.eoln Demonstration Program Listing 8-6: Random Access File I/O Example Listing 8-7: Using fileio.truncate to Eliminate Old Data from a File Chapter 9: Advanced Arithmetic Listing 9-1: Extended Precision Multiplication Listing 9-2: Unsigned 128/32-Bit Extended Precision Division Listing 9-3: Extended Precision Division Listing 9-4: 128-Bit Extended Precision Decimal Output Routine Listing 9-5: Extended Precision Hexadecimal Input Listing 9-6: Extended Precision Unsigned Decimal Input Listing 9-7: Mixed Mode FPU Arithmetic Listing 9-8: An HLA Program That Generates a Table of Sines Chapter 10: Macros and the HLA Compile Time Language Listing 10-1: The CTL "Hello World" Program Listing 10-2: #WHILE #ENDWHILE Demonstration Listing 10-3: Program Equivalent to the Code in Listing 10-2 Listing 10-4: Simple Procedure Overloading Based on Operand Size Listing 10-5: Procedure Overloading Based on Operand Type Listing 10-6: Using the Number of Parameters to Resolve Overloaded Procedures Listing 10-7: Generating a SINE Look-up Table with the Compile Time Language Listing 10-8: Generating Case Conversion Tables with the Compile Time Language Chapter 13: The MMX Instruction Set Listing 13-1: HLA Standard Library cs.cpy Routine Listing 13-2: HLA Standard Library cs.difference Routine Listing 13-3: MMX Implementation of the HLA Standard Library str.upper Procedure Chapter 15: Mixed Language Programming Listing 15-1: Using the @StaticName Compile Time Function Listing 15-2: Using the @Offset Compile Time Function Listing 15-3: Main HLA Program to Link with a MASM Program Listing 15-4: Calling a MASM Procedure from an HLA Program: MASM Module Listing 15-5: CalledFromDelphi.HLA Module Containing the Assembly Code Listing 15-6: DelphiEx1: Delphi Source Code That Calls an Assembly Procedure Listing 15-7: DelphiEx2: Pascal Code for Assembly Return Results Example Listing 15-8: ReturnBoolean: Demonstrates Returning a Byte Value in AL Listing 15-9: ReturnWord: Demonstrates Returning a Word Value in AX Listing 15-10: ReturnDWord: Demonstrates Returning a Dword Value in EAX Listing 15-11: ReturnPtr: Demonstrates Returning a 32-Bit Address in EAX Listing 15-12: ReturnReal: Demonstrates Returning a Real Value in ST0 Listing 15-13: DelphiEx3: Sample Program That Demonstrates the Pascal Calling Convention Listing 15-14: UsesPascal: HLA Function the Previous Delphi/Kylix Code Will Call Listing 15-15: DelphiEx4: Using the register Calling Convention Listing 15-16: HLA Code to Support the DelphiEx4 Program Listing 15-17: DelphiEx5: Static Data and Delphi Public Symbols Demonstration Listing 15-18: HLA Code for DelphiEx5 Example Listing 15-19: Cex1: A Simple Example of a Call to an Assembly Function from C++ Listing 15-20: RetHW.hla: Assembly Code That Cex1 Calls CD Content Following are select files from this book's Companion CD-ROM These files are copyright protected by the publisher, author, and/or other third parties Unauthorized use, reproduction, or distribution is strictly prohibited Click on the link(s) below to download the files to your computer: File Description Size All CD Content Art of Assembly Language Chapter 1: Hello, World of Assembly Language 934,053 Chapter 2: Data Representation 629,318 Chapter 3: Memory Access and Organization 257,120 Chapter 4: Constants, Variables, and Data Types Chapter 5: Procedures and Units Chapter 6: Arithmetic 33,426 Chapter 7: Low Level Control Structures 19,082 Chapter 8: Files Chapter 9: Advanced Arithmetic 40,784 Chapter 10: Macros and the HLA Compile Time Language 19,343 Chapter 11: BIT Manipulation 17,434 Chapter 12: The String Instructions 868,552 Chapter 13: The MMX Instruction Set 150,608 Chapter 14: Classes and Objects Chapter 15: Mixed Language Programming Chapter 16 5,925,556 31,452 482,752 979,832 5,134 867,107 54,567 Chapter 17 6,605 Chapter 18 15,101 Chapter 19 36,104 Aoa_code_ev 2,033 Aoa16bits_code 348,953 Aoa16bits_coderpteditor 108,671 ... modern development tools and The Art of Assembly Language After a decade of rigorous end-user testing of the online version, The Art of Assembly Language is an indispensable reference for using assembly to write... disable[4], sign, zero, auxiliary carry, parity, and carry flags Figure 1-6 shows the layout of the flags within the lower 16 bits of the EFLAGS register Figure 1-6: Layout of the Flags Register (Lower 16 Bits of EFLAGS) Of the eight flags that are usable by application programmers, four flags... Language and co-author of The Waite Group’s MASM 6.0 Bible The Art of Assembly Language Randall Hyde NO STARCH PRESS San Francisco Copyright © 2003 Randall Hyde All rights reserved No part of this work may be reproduced or transmitted

Ngày đăng: 25/03/2019, 16:44

Từ khóa liên quan

Mục lục

  • Table of Contents

  • BackCover

  • The Art of Assembly Language

  • Chapter 1: Hello, World of Assembly Language

    • 1.2 The Anatomy of an HLA Program

    • 1.3 Running Your First HLA Program

    • 1.4 Some Basic HLA Data Declarations

    • 1.5 Boolean Values

    • 1.6 Character Values

    • 1.7 An Introduction to the Intel 80x86 CPU Family

    • 1.8 Some Basic Machine Instructions

    • 1.9 Some Basic HLA Control Structures

    • 1.10 Introduction to the HLA Standard Library

    • 1.11 Additional Details About TRY..ENDTRY

    • 1.12 High Level Assembly Language vs. Low Level Assembly

    • 1.13 For More Information

    • Chapter 2: Data Representation

      • 2.2 Numbering Systems

      • 2.3 The Hexadecimal Numbering System

      • 2.4 Data Organization

      • 2.5 Arithmetic Operations on Binary and Hexadecimal Numbers

      • 2.6 A Note About Numbers vs. Representation

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan