Skip to main content
\(\newcommand{\doubler}[1]{2#1} \newcommand{\binary}{\mathtt} \newcommand{\hex}{\mathtt} \newcommand{\octal}{\mathtt} \newcommand{\prog}{\mathtt} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Chapter1Introduction

Unlike most assembly language books, this one does not emphasize writing applications in assembly language. Higher level languages, e.g., C, C++, Java, are much better for creating applications. You should avoid writing in assembly language whenever possible. This book guides you through writing lots of programs, but they are intended to illustrate programming concepts, not applications.

You may wonder why you should study assembly language at all. The usual reasons given are:

  • Assembly language is more efficient. This does not always hold. Modern compilers are excellent at optimizing the machine code that is generated. Only a very good assembly language programmer can do better, and only in some situations. Assembly language programming is very tedious, even for the best programmers. Hence, it is very expensive. The possible gains in efficiency are seldom worth the added expense.

  • Assembly language is required in some situations. This is more difficult to evaluate. How do you know whether it is required or not?

Both these reasons presuppose that you know the assembly language equivalent of the translation that your compiler does. Otherwise, you would have no way of deciding whether you can write a more efficient program in assembly language, and you would not know the machine level limitations of your higher level language. So this book begins with the fundamental high-level language concepts and “looks under the hood” to see how they are implemented at the assembly language level.

There is a more important reason for reading this book. The interface to the hardware from a programmer's view is the instruction set architecture (ISA). This book is a description of the ISA of the ARM architecture as it is used by the C/C++ programming languages. Higher level languages tend to hide the ISA from the programmer, but good programmers need to understand it. This understanding is bound to make you a better programmer, even if you never write a single assembly language statement after reading this book.

Some of you will enjoy assembly language programming and wish to carry on. If your interests take you into systems programming, e.g., writing parts of an operating system, writing a compiler, or even designing another higher level language, an understanding of assembly language is required. There are many challenging opportunities in programming embedded systems, and much of the work in this area demands at least an understanding of the ISA. This book serves as an introduction to assembly language programming and prepares you to move on to the intermediate and advanced levels.

In his book The Design and Evolution of C++[15] Bjarne Stroustrup nicely lists the purposes of a programming language:

  1. a tool for instructing machines

  2. a means of communicating between programmers

  3. a vehicle for expressing high-level designs

  4. a notation for algorithms

  5. a way of expressing relationships between concepts

  6. a tool for experimentation

  7. a means of controlling computerized devices

It is assumed that you have had at least an introduction to programming that covered the first five items on the list. This book focuses on the first item—instructing machines—by studying assembly language programming of an ARM architecture computer. We will use C as an example higher level language and study how it instructs the computer at the assembly language level. Since there is a one-to-one correspondence between assembly language and machine language, this amounts to a study of how C is used to instruct a computer.

You have already learned that a compiler (or interpreter) translates a program written in a higher level language into machine language, which the computer can execute. But what does this mean? For example, you might wonder:

  • How is an integer stored in memory?

  • How is a computer instructed to implement an if-else construct?

  • What happens when one function calls another function?

  • How does the computer know how to return to the statement following the function call statement?

  • How is a computer instructed to display a simple character string—for example, “Hello, world”—on the screen?

It is the goal of this book to answer these and many other questions.

The specific higher level programming language concepts that are addressed in this book are listed in Table 1.0.1.

General Concept Implementation
Program organization Functions, variables, literals
Primitive data types Integers, characters, floats
Simple arithmetic and logical operators +, -, *, /, %, &, |
Boolean operators !, &&, ||
Data organization constructs Arrays, structs, classes
Passing data to/from named procedures Function parameter lists; return values
Object operations Invoking a member function
Table1.0.1Programming language concepts covered in this book.