Table Of ContentARM Assembly Language
Programming & Architecture
Muhammad Ali Mazidi
Sarmad Naimi
Sepehr Naimi
Janice Mazidi
Copyright © 2013 Mazidis and Naimis
All rights reserved
(A portion of this book was taken from “The 80x86 IBM PC & Compatible
Computers Vol 1 &2: 4th edition” and was previously published by Pearson Education,
Inc.)
“Regard man as a mine rich in gems of inestimable value.
Education can, alone, cause it to reveal its treasures, and enable
mankind to benefit therefrom.”
Baha’u’llah
Dedication
To the faculty, staff, and students of BIHE university for their dedication and
steadfastness.
Preface
The ARM processor is becoming the dominant CPU architecture in the computer
industry. It is already the leading architecture in cell phones and tablet computers. With
such a large number of companies producing ARM chips, it is certain that the architecture
will move to the laptop, desktop and high-performance computers currently dominated by
x86 architecture from Intel and AMD. Currently the PIC and AVR microcontrollers
dominate the 8-bit microcontroller market. The ARM architecture will have a major
impact in this area too as designers become more familiar with its architecture. This book
is intended as an introduction to ARM assembly language programming and architecture.
We assume no prior background in assembly language programming with other CPUs.
However, we urge you to study Chapter 0 covering the fundamentals of digital systems
such as hexadecimal numbers, various types of memory, memory and I/O interfacing, and
memory address decoding. Chapter 0 is available free of charge on our website
http://www.MicroDigitalEd.com/ARM/ARM_books.htm
Universities and colleges
This book is intended for both academic and industry readers. The answers to
review questions at end of each section are provided at end of the chapter. If you are using
this book for a university course there are end-of-chapter problems that can be found on
www.MicroDigitalEd.com/ARM/ARM_books.htm
Our upcoming books in the ARM series
This book covers the Assembly language programming of the ARM chip. The ARM
Assembly language is standard regardless of who makes the chip. The ARM licensees are
free to implement the on-chip peripheral (ADC, Timers, I/O, …) as they choose. Since
the ARM peripherals are not standard among the various vendors, we have dedicated a
separate book to each vendor. The following books are planned in this series:
TI ARM Peripheral Programming and Interfacing
Freescale ARM Peripheral Programming and Interfacing
NXP ARM Peripheral Programming and Interfacing
Atmel ARM Peripheral Programming and Interfacing
The above books use C language to program the peripherals.
Finally, we would like to thank professors Shujen Chen, Rabah Aoufi, and Clyde
Knight for their reading of the book before publication. We sincerely appreciate their
insights and inputs. We would also like to thank Fada Mahmoudi, Mozhde Amiri, Keyvan
Roshani, Azalia Yaghini, Arash Zamani, Parham Fazlali, and Ashkan Farivar for sharing
their comments on the prepublication version of this e-book.
Contact us at the following email address:
mdebooks@yahoo.com
and please place ARM book in subject line of your email.
Table of Contents
Chapter 1: The History of ARM and Microcontrollers
Section 1.1: Introduction to Microcontrollers
Section 1.2: The ARM Family History
Problems
Answers to Review Questions
Chapter 2: ARM Architecture and Assembly Language Programming
Section 2.1: The General Purpose Registers in the ARM
Section 2.2: The ARM Memory Map
Section 2.3: Load and Store Instructions in ARM
Section 2.4: ARM CPSR (Current Program Status Register)
Section 2.5: ARM Data Format and Directives
Section 2.6: Introduction to ARM Assembly Programming
Section 2.7: Assembling an ARM Program
Section 2.8: The Program Counter and Program ROM Space in the ARM
Section 2.9: Some ARM Addressing Modes
Section 2.10: RISC Architecture in ARM
Section 2.11: Viewing Registers and Memory with ARM Keil IDE
Problems
Answers to Review Questions
Chapter 3: Arithmetic and Logic Instructions and Programs
Section 3.1: Arithmetic Instructions
Section 3.2: Logic Instructions
Section 3.3: Rotate and Barrel Shifter
Section 3.4: Shift and Rotate Instructions in ARM Cortex (Case Study)
Section 3.5: BCD and ASCII Conversion
Problems
Answers to Review Questions
Chapter 4: Branch, Call, and Looping in ARM
Section 4.1: Looping and Branch Instructions
Section 4.2: Calling Subroutine with BL
Section 4.3: ARM Time Delay and Instruction Pipeline
Section 4.4: Conditional Execution
Problems
Answers to Review Questions
Chapter 5: Signed Numbers and IEEE 754 Floating Point
Section 5.1: Signed Numbers Concept
Section 5.2: Signed Number Instructions and Operations
Section 5.3: IEEE 754 Floating-Point Standards
Problems:
Answers to Review Questions
Chapter 6: ARM Memory Map, Memory Access, and Stack
Section 6.1: ARM Memory Map and Memory Access
Section 6.2: Stack and Stack Usage in ARM
Section 6.3: ARM Bit-Addressable Memory Region
Section 6.4: Advanced Indexed Addressing Mode
Section 6.5: ADR, LDR, and PC Relative Addressing
Problems
Answers to Review Questions
Chapter 7: ARM Pipeline and CPU Evolution
Section 7.1: ARM Pipeline Evolution
Section 7.2: Other CPU Enhancements
Problems
Answers to Review Questions
Appendix A: ARM Cortex-M3 Instruction Description
Section A.1: List of ARM Cortex-M3 Instructions
Section A.2: ARM Cortex-M3 Instruction Description
Appendix B: ARM Assembler Directives
Section B.1: List of ARM Assembler Directives
Section B.2: Description of ARM Assembler Directives
Appendix C: Macros
What is a macro and how is it used?
Macros vs. subroutines
Appendix D: Flowcharts and Pseudocode
Flowcharts
Pseudocode
Appendix E: Passing Arguments into Functions
E.1: Passing arguments through registers
E.2: Passing through memory using references
E.3: Passing arguments through stack
E.4: AAPCS (ARM Application Procedure Call Standard)
Appendix F: ASCII Codes