文件名称:Professional Assembly Language
文件大小:1.93MB
文件格式:GZ
更新时间:2013-03-12 15:53:38
AT&T汇编
***请支持开源*** 汇编大师Richard Blum的经典AT&T汇编教程英文原版(没有中文版) 下面是书中的介绍 Introduction Assembly language is one of the most misunderstood programming languages in use. When the term assembly language is used, it often invokes the idea of low-level bit shuffling and poring over thousand- page instruction manuals looking for the proper instruction format. With the proliferation of fancy high- level language development tools, it is not uncommon to see the phrase “assembly language programming is dead” pop up among various programming newsgroups. However, assembly language programming is far from dead. Every high-level language program must be compiled into assembly language before it can be linked into an executable program. For the high- level language programmer, understanding how the compiler generates the assembly language code can be a great benefit, both for directly writing routines in assembly language and for understanding how the high-level language routines are converted to assembly language by the compiler. Who This Book Is For The primary purpose of this book is to teach high-level language programmers how their programs are converted to assembly language, and how the generated assembly language code can be tweaked. That said, the main audience for this book is programmers already familiar with a high-level language, such as C, C++, or even Java. This book does not spend much time teaching basic programming principles. It assumes that you are already familiar with the basics of computer programming, and are interested in learning assembly language to understand what is happening underneath the hood. However, if you are new to programming and are looking at assembly language programming as a place to start, this book does not totally ignore you. It is possible to follow along in the chapters from the start to the finish and obtain a basic knowledge of how assembly language programming (and programming in general) works. Each of the topics presented includes example code that demonstrates how the assem- bly language instructions work. If you are completely new to programming, I recommend that you also obtain a good introductory text to programming to round out your education on the topic. What This Book Covers The main purpose of this book is to familiarize C and C++ programmers with assembly language, show how compilers create assembly language routines from C and C++ programs, and show how the gener- ated assembly language routines can be spruced up to increase the performance of an application. All high-level language programs (such as C and C++) are converted to assembly language by the com- piler before being linked into an executable program. The compiler uses specific rules defined by the cre- ator of the compiler to determine exactly how the high-level language statements are converted. Many programmers just write their high-level language programs and assume the compiler is creating the proper executable code to implement the program. Introduction However, this is not always the case. When the compiler converts the high-level language code state- ments into assembly language code, quirks and oddities often pop up. In addition, the compiler is often written to follow the conversion rules so specifically that it does not recognize time-saving shortcuts that can be made in the final assembly language code, or it is unable to compensate for poorly written high- level routines. This is where knowledge of assembly language code can come in handy. This book shows that by examining the assembly language code generated by the compiler before link- ing it into an executable program, you can often find places where the code can be modified to increase performance or provide additional functionality. The book also helps you understand how your high- level language routines are affected by the compiler’s conversion process. How This Book Is Structured The book is divided into three sections. The first section covers the basics of the assembly language programming environment. Because assembly language programming differs among processors and assemblers, a common platform had to be chosen. This book uses the popular Linux operating system, running on the Intel family of processors. The Linux environment provides a wealth of program devel- oper tools, such as an optimizing compiler, an assembler, a linker, and a debugger, all at little or no charge. This wealth of development tools in the Linux environment makes it the perfect setting for dissecting C programs into assembly language code. The chapters in the first section are as follows: Chapter 1, “What Is Assembly Language?” starts the section off by ensuring that you understand exactly what assembly language is and how it fits into the programming model. It debunks some of the myths of assembly language, and provides a basis for understanding how to use assembly language with high- level languages. Chapter 2, “The IA-32 Platform,” provides a brief introduction to the Intel Pentium family of processors. When working with assembly language, it is important that you understand the underlying processor and how it handles programs. While this chapter is not intended to be an in-depth analysis of the opera- tion of the IA-32 platform, it does present the hardware and operations involved with programming for that platform. Chapter 3, “The Tools of the Trade,” presents the Linux open-source development tools that are used throughout the book. The GNU compiler, assembler, linker, and debugger are used in the book for com- piling, assembling, linking, and debugging the programs. Chapter 4, “A Sample Assembly Language Program,” demonstrates how to use the GNU tools on a Linux system to create, assemble, link, and debug a simple assembly language program. It also shows how to use C library functions within assembly language programs on Linux systems to add extra fea- tures to your assembly language applications. The second section of the book dives into the basics of assembly language programming. Before you can start to analyze the assembly language code generated by the compiler, you must understand the assem- bly language instructions. The chapters in this section are as follows: xxiv Introduction Chapter 5, “Moving Data,” shows how data elements are moved in assembly language programs. The concepts of registers, memory locations, and the stack are presented, and examples are shown for mov- ing data between them. Chapter 6, “Controlling Execution Flow,” describes the branching instructions used in assembly lan- guage programs. Possibly one of the most important features of programs, the ability to recognize branches and optimize branches is crucial to increasing the performance of an application. Chapter 7, “Using Numbers,” discusses how different number data types are used in assembly lan- guage. Being able to properly handle integers and floating-point values is important within the assembly language program. Chapter 8, “Basic Math Functions,” shows how assembly language instructions are used to perform the basic math functions such as addition, subtraction, multiplication, and division. While these are gener- ally straightforward functions, subtle tricks can often be used to increase performance in this area. Chapter 9, “Advanced Math Functions,” discusses the IA-32 Floating Point Unit (FPU), and how it is used to handle complex floating-point arithmetic. Floating-point arithmetic is often a crucial element to data processing programs, and knowing how it works greatly benefits high-level language programmers. Chapter 10, “Working with Strings,” presents the various assembly language string-handling instruc- tions. Character data is another important facet of high-level language programming. Understanding how the assembly language level handles strings can provide insights when working with strings in high-level languages. Chapter 11, “Using Functions,” begins the journey into the depths of assembly language programming. Creating assembly language functions to perform routines is at the core of assembly language optimiza- tion. It is good to know the basics of assembly language functions, as they are often used by the compiler when generating the assembly language code from high-level language code. Chapter 12, “Using Linux System Calls,” completes this section by showing how many high-level func- tions can be performed in assembly language using already created functions. The Linux system pro- vides many high-level functions, such as writing to the display. Often, you can utilize these functions within your assembly language program. The last section of the book presents more advanced assembly language topics. Because the main topic of this book is how to incorporate assembly language routines in your C or C++ code, the first few chapters show just how this is done. The remaining chapters present some more advanced topics to round out your education on assembly language programming. The chapters in this section include the following: Chapter 13, “Using Inline Assembly,” shows how to incorporate assembly language routines directly in your C or C++ language programs. Inline assembly language is often used for “hard-coding” quick rou- tines in the C program to ensure that the compiler generates the appropriate assembly language code for the routine. Chapter 14, “Calling Assembly Libraries,” demonstrates how assembly language functions can be com- bined into libraries that can be used in multiple applications (both assembly language and high-level language). It is a great time-saving feature to be able to combine frequently used functions into a single library that can be called by C or C++ programs. xxv Introduction Chapter 15, “Optimizing Routines,” discusses the heart of this book: modifying compiler-generated assembly language code to your taste. This chapter shows exactly how different types of C routines (such as if-then statements and for-next loops) are produced in assembly language code. Once you understand what the assembly language code is doing, you can add your own touches to it to customize the code for your specific environment. Chapter 16, “Using Files,” covers one of the most overlooked functions of assembly language program- ming. Almost every application requires some type of file access on the system. Assembly language pro- grams are no different. This chapter shows how to use the Linux file-handling system calls to read, write, and modify data in files on the system. Chapter 17, “Using Advanced IA-32 Features,” completes the book with a look at the advanced Intel Single Instruction Multiple Data (SIMD) technology. This technology provides a platform for program- mers to perform multiple arithmetic operations in a single instruction. This technology has become cru- cial in the world of audio and video data processing. What You Need to Use This Book All of the examples in this book are coded to be assembled and run on the Linux operating system, run- ning on an Intel processor platform. The Open Source GNU compiler (gcc), assembler (gas), linker (ld), and debugger (gdb) are used extensively throughout the book to demonstrate the assembly language features. Chapter 4, “A Sample Assembly Language Program,” discusses specifically how to use these tools on a Linux platform to create, assemble, link, and debug an assembly language program. If you do not have an installed Linux platform available, Chapter 4 demonstrates how to use a Linux distribution that can be booted directly from CD, without modifying the workstation hard drive. All of the GNU development tools used in this book are available without installing Linux on the workstation.
【文件预览】:
Professional_Assembly_Language.pdf