Computer Science and Engineering Hohl Hinds “Assembly language programming is still the best way to learn about the A internals of processors and this is one of a very few books that teaches that R skill for ARM® processors. It covers the necessary material in a well-organized manner. Updated for newer versions of ARM processors, it adds good material M on floating-point arithmetic that was missing from the first edition.” —Ronald W. Mehler, California State University, Northridge, USA A “This text retains the ease of using the ARM7TDMI while moving the F student [or reader] into the more capable Cortex-M4. …The addition of the uS Cortex-M4 makes this a much stronger text.” n S —Ralph Tanner, Western Michigan University, Kalamazoo, USA d a E m Delivering a solid introduction to assembly language and embedded eM systems, ARM Assembly Language: Fundamentals and Techniques, Second n Edition continues to support the popular ARM7TDMI, but also addresses the t latest architectures from ARM, including Cortex™-A, Cortex-R, and Cortex-M aB l s processors—all of which have slightly different instruction sets, programmer’s aL models, and exception handling. nY d Featuring three brand-new chapters, a new appendix, and expanded T L coverage of the ARM7™, this edition: e cA h • Discusses IEEE 754 floating-point arithmetic and explains how to n program with the IEEE standard notation iN q u • Contains step-by-step directions for the use of Keil™ MDK-ARM and eG Texas Instruments (TI) Code Composer Studio™ s U • Provides a resource to be used alongside a variety of hardware evaluation modules, such as TI’s Tiva Launchpad, STMicroelectronics’ A iNemo and Discovery, and NXP Semiconductors’ Xplorer boards G Written by experienced ARM processor designers, ARM Assembly E Language: Fundamentals and Techniques, Second Edition covers the topics essential to writing meaningful assembly programs, making it an ideal textbook and professional reference. SECOND EDITION K22631 ISBN: 978-1-4822-2985-1 90000 9 781482229851 K22631_COVER_final.indd 1 9/12/14 3:07 PM S E C O N D E D I T I O N ARM ASSEMBLY LANGUAGE Fundamentals and Techniques S E C O N D E D I T I O N ARM ASSEMBLY LANGUAGE Fundamentals and Techniques William Hohl Christopher Hinds ARM, Inc., Austin, Texas Boca Raton London New York CRC Press is an imprint of the Taylor & Francis Group, an informa business CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2015 by William Hohl and Christopher Hinds CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Version Date: 20140915 International Standard Book Number-13: 978-1-4822-2986-8 (eBook - PDF) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmit- ted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright. com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com To our families Contents Preface......................................................................................................................xv Acknowledgments ...................................................................................................xxi Authors .................................................................................................................xxiii Chapter 1 An Overview of Computing Systems ...................................................1 1.1 Introduction ...............................................................................1 1.2 History of RISC .........................................................................3 1.2.1 ARM Begins ................................................................5 1.2.2 The Creation of ARM Ltd. ...........................................7 1.2.3 ARM Today ..................................................................9 1.2.4 The Cortex Family .....................................................10 1.2.4.1 The Cortex-A and Cortex-R Families .........10 1.2.4.2 The Cortex-M Family .................................11 1.3 The Computing Device ............................................................12 1.4 Number Systems ......................................................................15 1.5 Representations of Numbers and Characters ..........................18 1.5.1 Integer Representations ..............................................18 1.5.2 Floating-Point Representations ..................................21 1.5.3 Character Representations ..........................................23 1.6 Translating Bits to Commands ................................................24 1.7 The Tools .................................................................................25 1.7.1 Open Source Tools .....................................................27 1.7.2 Keil (ARM) ................................................................27 1.7.3 Code Composer Studio ...............................................28 1.7.4 Useful Documentation ................................................30 1.8 Exercises ..................................................................................30 Chapter 2 The Programmer’s Model ..................................................................33 2.1 Introduction .............................................................................33 2.2 Data Types ...............................................................................33 2.3 ARM7TDMI ...........................................................................34 2.3.1 Processor Modes ........................................................34 2.3.2 Registers .....................................................................35 2.3.3 The Vector Table ........................................................38 2.4 Cortex-M4 ................................................................................39 2.4.1 Processor Modes ........................................................40 2.4.2 Registers .....................................................................40 2.4.3 The Vector Table ........................................................42 2.5 Exercises ..................................................................................43 vii viii Contents Chapter 3 Introduction to Instruction Sets: v4T and v7-M .................................45 3.1 Introduction .............................................................................45 3.2 ARM, Thumb, and Thumb-2 Instructions ..............................46 3.3 Program 1: Shifting Data.........................................................46 3.3.1 Running the Code .......................................................47 3.3.2 Examining Register and Memory Contents ...............49 3.4 Program 2: Factorial Calculation ............................................51 3.5 Program 3: Swapping Register Contents .................................53 3.6 Program 4: Playing with Floating-Point Numbers ..................54 3.7 Program 5: Moving Values between Integer and Floating- Point Registers .........................................................................55 3.8 Programming Guidelines ........................................................56 3.9 Exercises ..................................................................................57 Chapter 4 Assembler Rules and Directives .........................................................59 4.1 Introduction .............................................................................59 4.2 Structure of Assembly Language Modules .............................59 4.3 Predefined Register Names .....................................................63 4.4 Frequently Used Directives .....................................................63 4.4.1 Defining a Block of Data or Code ..............................63 4.4.1.1 Keil Tools ....................................................64 4.4.1.2 Code Composer Studio Tools .....................65 4.4.2 Register Name Definition ...........................................66 4.4.2.1 Keil Tools ....................................................66 4.4.2.2 Code Composer Studio ...............................66 4.4.3 Equating a Symbol to a Numeric Constant ................66 4.4.3.1 Keil Tools ....................................................67 4.4.3.2 Code Composer Studio ...............................67 4.4.4 Declaring an Entry Point ............................................67 4.4.5 Allocating Memory and Specifying Contents ...........68 4.4.5.1 Keil Tools ....................................................68 4.4.5.2 Code Composer Studio ...............................69 4.4.6 Aligning Data or Code to Appropriate Boundaries ......70 4.4.6.1 Keil Tools ....................................................70 4.4.6.2 Code Composer Studio ...............................71 4.4.7 Reserving a Block of Memory ...................................71 4.4.7.1 Keil Tools ....................................................71 4.4.7.2 Code Composer Studio ...............................71 4.4.8 Assigning Literal Pool Origins ..................................72 4.4.9 Ending a Source File ..................................................72 4.5 Macros .....................................................................................73 4.6 Miscellaneous Assembler Features .........................................74 4.6.1 Assembler Operators ..................................................74 4.6.2 Math Functions in CCS ..............................................76 4.7 Exercises ..................................................................................77
Description: