Stephen Smith
Programming with 64-Bit ARM Assembly Language
Single Board Computer Development for Raspberry Pi and Mobile Devices
Stephen Smith
Gibsons, BC, Canada
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-5880-4 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5880-4 e-ISBN 978-1-4842-5881-1
https://doi.org/10.1007/978-1-4842-5881-1
Stephen Smith 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
This book is dedicated to my beloved wife and editor Cathalynn Labont-Smith.
Introduction
Everyone seems to carry a smartphone and/or a tablet. Nearly all of these devices have one thing in common; they use an ARM central processing unit (CPU). All of these devices are computers just like your laptop or business desktop. The difference is that they need to use less power, in order to function for at least a day on one battery charge, therefore the popularity of the ARM CPU.
At the basic level, how are these computers programmed? What provides the magical foundation for all the great applications (apps) that run on them, yet use far less power than a laptop computer? This book delves into how these are programmed at the bare metal level and provides insight into their architecture.
Assembly Language is the native lowest level way to program a computer. Each processing chip has its own Assembly Language. This book covers programming the ARM 64-bit processor. If you really want to learn how a computer works, learning Assembly Language is a great way to get into the nitty-gritty details. The popularity and low cost of single board computers (SBCs) like the Raspberry Pi and NVidia Jetson Nano provide ideal platforms to learn advanced concepts in computing.
Even though all these devices are low powered and compact, theyre still sophisticated computers with a multicore processor, floating-point coprocessor, and a NEON parallel processing unit. What you learn about any one of these is directly relevant to any device with an ARM processor, which by volume is the number one processor on the market today.
In this book, we cover how to program all these devices at the lowest level, operating as close to the hardware as possible. You will learn the following:
The format of the instructions and how to put them together into programs, as well as details on the binary data formats they operate on
How to program the floating-point processor, as well as the NEON parallel processor
About devices running Googles Android, Apples iOS, and Linux
How to program the hardware directly using the Raspberry Pis GPIO ports
The simplest way to learn this is with a Raspberry Pi running a 64-bit flavor of Linux such as Kali Linux. This provides all the tools you need to learn Assembly programming. Theres optional material that requires an Apple Mac and iPhone or iPad, as well as optional material that requires an Intel-based computer and an Android device.
This book contains many working programs that you can play with, use as a starting point, or study. The only way to learn programming is by doing, so dont be afraid to experiment, as it is the only way you will learn.
Even if you dont use Assembly programming in your day-to-day life, knowing how the processor works at the Assembly level and knowing the low-level binary data structures will make you a better programmer in all other areas. Knowing how the processor works will let you write more efficient C code and can even help you with your Python programming.
The book is designed to be followed in sequence, but there are chapters that can be skipped or skimmed, for example, if you arent interested in interfacing to hardware, you can skip Chapter, Floating-Point Operations, if you will never do numerical computing.
I hope you enjoy your introduction to Assembly Language. Learning it for one processor family will help you with any other processor architectures you encounter through your career.
Source Code Location
The source code for the example code in the book is located on the Apress GitHub site at the following URL:
https://github.com/Apress/Programming-with-64-Bit-ARM-Assembly-Language
The code is organized by chapter and includes some answers to the programming exercises.
Acknowledgments
No book is ever written in isolation. I want to especially thank my wife, Cathalynn Labont-Smith, for her support, encouragement, and expert editing.
I want to thank all the good folk at Apress who made the whole process easy and enjoyable. A special shout-out to Jessica Vakili, my coordinating editor, who kept the whole project moving quickly and smoothly. Thanks to Aaron Black, senior editor, who recruited me and got the project started. Thanks to Stewart Watkiss, my technical reviewer, who helped make this a far better book.
Table of Contents
About the Author
Stephen Smith
is also the author of the Apress titleRaspberry Pi Assembly Language Programming. He is a retired Software Architect, located in Gibsons, BC, Canada. Hes been developing software since high school, or way too many years to record. He was the Chief Architect for the Sage 300 line of accounting products for 23 years. Since retiring, he has pursued artificial intelligence, earned his Advanced HAM Radio License, and enjoys mountain biking, hiking, and nature photography. He continues to write his popular technology blog at smist08.wordpress.com and has written two science fiction novels in the