Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Modern Assembly Language Programming with the ARM Processor
Modern Assembly Language Programming with the ARM Processor
Modern Assembly Language Programming with the ARM Processor
Ebook833 pages6 hours

Modern Assembly Language Programming with the ARM Processor

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Modern Assembly Language Programming with the ARM Processor is a tutorial-based book on assembly language programming using the ARM processor. It presents the concepts of assembly language programming in different ways, slowly building from simple examples towards complex programming on bare-metal embedded systems.

The ARM processor was chosen as it has fewer instructions and irregular addressing rules to learn than most other architectures, allowing more time to spend on teaching assembly language programming concepts and good programming practice. In this textbook, careful consideration is given to topics that students struggle to grasp, such as registers vs. memory and the relationship between pointers and addresses, recursion, and non-integral binary mathematics. A whole chapter is dedicated to structured programming principles. Concepts are illustrated and reinforced with a large number of tested and debugged assembly and C source listings. The book also covers advanced topics such as fixed and floating point mathematics, optimization, and the ARM VFP and NEONTM extensions. PowerPoint slides and a solutions manual are included.

This book will appeal to professional embedded systems engineers, as well as computer engineering students taking a course in assembly language using the ARM processor.

  • Concepts are illustrated and reinforced with a large number of tested and debugged assembly and C source listing
  • Intended for use on very low-cost platforms, such as the Raspberry Pi or pcDuino, but with the support of a full Linux operating system and development tools
  • Includes discussions of advanced topics, such as fixed and floating point mathematics, optimization, and the ARM VFP and NEON extensions
LanguageEnglish
Release dateMay 3, 2016
ISBN9780128037164
Modern Assembly Language Programming with the ARM Processor
Author

Larry D Pyeatt

Larry Pyeatt earned his doctorate in Computer Science, focusing on Artificial Intelligence, from Colorado State University in 1999. He spent 13 years as a professor at Texas Tech University before moving to the South Dakota School of Mines and Technology in 2012. He has programmed in over 15 assembly languages, from mainframes to 8-bit embedded systems, and teaches a variety of courses including assembly language, operating systems, computer architecture, and probabilistic artificial intelligence.

Related to Modern Assembly Language Programming with the ARM Processor

Related ebooks

Hardware For You

View More

Related articles

Reviews for Modern Assembly Language Programming with the ARM Processor

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Modern Assembly Language Programming with the ARM Processor - Larry D Pyeatt

    book.

    Part I

    Assembly as a Language

    Chapter 1

    Introduction

    Abstract

    This chapter first gives a very high-level description of the major components of function of a computer system. It then motivates the reader by giving reasons why learning assembly language is important for Computer Scientists and Computer Engineers. It then explains why the ARM processor is a good choice for a first assembly language. Next it explains binary data representations, including various integer formats, ASCII, and Unicode. Finally, it describes the memory sections for a typical program during execution. By the end of the chapter, the groundwork has been laid for learning to program in assembly language.

    Keywords

    Instruction; Instruction stream; Central processing unit; Memory; Input/output device; High-level language; Assembly language; ARM processor; Binary; Hexadecimal; Decimal; Radix or base system; Base conversion; Sign magnitude; Unsigned; Complement; Excess-n; ASCII; Unicode; UTF-8; Stack; Heap; Data section; Text section

    Chapter Outline

    1.1 Reasons to Learn Assembly   4

    1.2 The ARM Processor   8

    1.3 Computer Data   9

    1.3.1 Representing Natural Numbers   9

    1.3.2 Base Conversion   11

    1.3.3 Representing Integers   15

    1.3.4 Representing Characters   20

    1.4 Memory Layout of an Executing Program   28

    1.5 Chapter Summary   31

    An executable computer program is, ultimately, just a series of numbers that have very little or no meaning to a human being. We have developed a variety of human-friendly languages in which to express computer programs, but in order for the program to execute, it must eventually be reduced to a stream of numbers. Assembly language is one step above writing the stream of numbers. The stream of numbers is called the instruction stream. Each number in the instruction stream instructs the computer to perform one (usually small) operation. Although each instruction does very little, the ability of the programmer to specify any sequence of instructions and the ability of the computer to perform billions of these small operations every second makes modern computers very powerful and flexible tools. In assembly language, one line of code usually gets translated into one machine instruction. In high-level languages, a single line of code may generate many machine instructions.

    A simplified model of a computer system, as shown in Fig. 1.1, consists of memory, input/output devices, and a central processing unit (CPU), connected together by a system bus. The bus can be thought of as a roadway that allows data to travel between the components of the computer system. The CPU is the part of the system where most of the computation occurs, and the CPU controls the other devices in the system.

    Figure 1.1 Simplified representation of a computer system.

    Memory can be thought of as a series of mailboxes. Each mailbox can hold a single postcard with a number written on it, and each mailbox has a unique numeric identifier. The identifier, x is called the memory address, and the number stored in the mailbox is called the contents of address x. Some of the mailboxes contain data, and others contain instructions which control what actions are performed by the CPU.

    The CPU also contains a much smaller set of mailboxes, which we call registers. Data can be copied from cards stored in memory to cards stored in the CPU, or vice-versa. Once data has been copied into one of the CPU registers, it can be used in computation. For example, in order to add two numbers in memory, they must first be copied into registers on the CPU. The CPU can then add the numbers together and store the result in one of the CPU registers. The result of the addition can then be copied back into one of the mailboxes in the memory.

    Modern computers execute instructions sequentially. In other words, the next instruction to be executed is at the memory address immediately following the current instruction. One of the registers in the CPU, the program counter (PC), keeps track of the location from which the next instruction is to be fetched. The CPU follows a very simple sequence of actions. It fetches an instruction from memory, increments the PC, executes the instruction, and then repeats the process with the next instruction. However, some instructions may change the PC, so that the next instruction is fetched from a non-sequential address.

    1.1 Reasons to Learn Assembly

    There are many high-level programming languages, such as Java, Python, C, and C++ that have been designed to allow programmers to work at a high level of abstraction, so that they do not need to understand exactly what instructions are needed by a particular CPU. For compiled languages, such as C and C++, a compiler handles the task of translating the program, written in a high-level language, into assembly language for the particular CPU on the system. An assembler then converts the program from assembly language into the binary codes that the CPU reads as instructions.

    High-level languages can greatly enhance programmer productivity. However, there are some situations where writing assembly code directly is desirable or necessary. For example, assembly language may be the best choice when writing

    • the first steps in booting the computer,

    • code to handle interrupts,

    • low-level locking code for multi-threaded programs,

    • code for machines where no compiler exists,

    • code which needs to be optimized beyond the limits of the compiler,

    • on computers with very limited memory, and

    • code that requires low-level access to architectural and/or processor features.

    Aside from sheer necessity, there are several other reasons why it is still important for computer scientists to learn assembly language.

    One example where knowledge of assembly is indispensable is when designing and implementing compilers for high-level languages. As shown in Fig. 1.2, a typical compiler for a high-level language must generate assembly language as its output. Most compilers are designed to have multiple stages. In the input stage, the source language is read and converted into a graph representation. The graph may be optimized before being passed to the output, or code generation, stage where it is converted to assembly language. The assembly is then fed into the system’s assembler to generate an object file. The object file is linked with other object files (which are often combined into libraries) to create an executable program.

    Figure 1.2 Stages of a typical compilation sequence.

    The code generation stage of a compiler must traverse the graph and emit assembly code. The quality of the assembly code that is generated can have a profound influence on the performance of the executable program. Therefore, the programmer responsible for the code generation portion of the compiler must be well versed in assembly programming for the target CPU.

    Some people believe that a good optimizing compiler will generate better assembly code than a human programmer. This belief is not justified. Highly optimizing compilers have lots of clever algorithms, but like all programs, they are not perfect. Outside of the cases that they were designed for, they do not optimize well. Many newer CPUs have instructions which operate on multiple items of data at once. However, compilers rarely make use of these powerful single instruction multiple data ( SIMD) instructions. Instead, it is common for programmers to write functions in assembly language to take advantage of SIMD instructions. The assembly functions are assembled into object file(s), then linked with the object file(s) generated from the high-level language

    Enjoying the preview?
    Page 1 of 1