After obtaining his PhD in electrical engineering from UC Berkeley, Bob Plantz took a position in a physiology research lab at UC San Francisco where he programmed a Data General minicomputer. Following that, he spent several years in industry where he wrote assembly language on half a dozen different architectures at the software/hardware interface level. He then transitioned into a 21-year university teaching career in computer science.
Dr. William Young is Associate Professor of Instruction in the Department of Computer Science at the University of Texas at Austin. Prior to joining the UT faculty in 2001, he had 20 years of experience in industry. He specializes in formal methods and computer security, but often teaches computer architecture, among other courses.
Mike Lyle got his start designing computers for Hughes Aircraft (which only built one plane) to control radar and sonar systems, and then with Sperry-Univac designing operating systems for telecommunication computers. He then taught computer design at UC Berkeley for seven years, and at Sonoma State University for 15 years.
Preface
This book introduces the concepts of how computer hardware works from a programmers point of view. The hardware is controlled by a set of machine instructions. The way in which these instructions control the hardware is called the instruction set architecture (ISA). A programmers job is to design a sequence of these instructions that will cause the hardware to perform operations to solve a problem.
Nearly all computer programs are written in a high-level language. Some of these languages are general purpose, and others are geared toward a specific type of application. But they are all intended to provide a programmer with a set of programming constructs more suitable for solving problems in human terms than working directly with the instruction set architecture and the details of the hardware.
Who This Book Is For
Have you ever wondered whats going on under the hood when you write a program in a high-level language? You know that computers can be programmed to make decisions, but how do they do that? You probably know that data is stored in bits, but what does that mean when storing a decimal number? My goal in this book is to answer these and many other questions about how computers work. Well be looking at both the hardware components and the machine-level instructions used to control the hardware.
Im assuming that you know the basics of how to program in a high-level language, but you dont need to be an expert programmer. After discussing the hardware components, well look at and write lots of programs in assembly language, the language that translates directly into the machine instructions.
Unlike most assembly language books, we wont emphasize writing applications in assembly language. Higher-level languageslike C++, Java, and Pythonare much more efficient for creating applications. Writing in assembly language is a tedious, error-prone, time-consuming process, so it should be avoided whenever possible. Our goal here is to study programming concepts, not to create applications.
About This Book
The guidelines I followed in creating this book are as follows:
- Learning is easier if it builds on concepts you already know.
- Real-world hardware and software make a more interesting platform for learning theoretical concepts.
- The tools used for learning should be inexpensive and readily available.
The Programming in the Book
This book is based on the x86-64 instruction set architecture, which is the 64-bit version of the x86 (32-bit) instruction set architecture. It is also known by the names AMD64, x86_64, x64, and Intel 64. All the programming in the book was done using the GNU programming environment running under the Ubuntu Linux operating system. The programs should work with most common Linux distributions with few, if any, modifications.
Were using C as our high-level language, with some C++ in a later chapter. Dont worry if you dont know C/C++. All our C/C++ programming will be very simple, and Ill explain what you need to know as we go.
An important issue that arises when learning assembly language is using the keyboard and terminal screen in an application. Programming input from a keyboard and output to a screen is complex, well beyond the expertise of a beginner. The GNU programming environment includes the C standard library. Keeping with the real-world criterion of this book, well use the functions in that library, which are easily called from assembly language, for using the keyboard and screen in our applications.
The x86-64 instruction set architecture includes some 1,500 instructions. The exact number depends on what you consider to be a different instruction, but there are far too many to memorize. Some assembly language books deal with this issue by inventing an idealized instruction set architecture to illustrate the concepts. Again, keeping with the real-world nature of this book, well use the standard x86-64 instruction set but only a small subset of the instructions that will be sufficient to illustrate the basic concepts.