Raspberry Pi Operating System Assembly Language
Hands-on-Guide
Fourth Edition
Bruce Smith
eBook editions 1 ,2 3, Previously published as Raspberry Pi Assembly Language Raspbian ISBN 978-0-9923916-0-7
Fourth edition Revised and updated: March 2021 [0004]
ISBN: 978-0-6480987-4-4
Editor: Alan Ford Edits, Melanie Smith
Cover: Sumit Shringi, Graphic Designer (Book Cover-Design)
All Trademarks and Registered Trademarks are hereby acknowledged. Within this Hands On Guide the term BBC refers to the British Broadcasting Corporation. Raspberry Pi and the Raspberry Pi logos are registered trademarks of the Raspberry Pi Foundation.
Raspberry Pi OS Assembly Language: Hands On Guide is not endorsed by the Raspberry Pi Foundation.
All rights reserved. No part of this book (except brief passages quoted for critical purposes) or any of the computer programs to which it relates may be reproduced or translated in any form, by any means mechanical electronic or otherwise without the prior written consent of the copyright holder.
Disclaimer: Whilst every effort has been made to ensure that the information in this publication (and any programs and software) is correct and accurate, the author and publisher can accept no liability for any consequential loss or damage, however caused, arising as a result of the information printed in this book and on any associated websites. Because neither BSB nor the author have any control over the way in which the contents of this book is used, no warranty is given or should be implied as to the suitability of the advice or programs for any given application. No liability can be accepted for any consequential loss or damage, however caused, arising as a result of using the programs or advice printed in this book.
Source code and supplementary material referenced in this book is available to readers on the authors website at: www.brucesmith.info.
Published by BSB. www.brucesmith.info.
Using this eBook
I love eBooks! Loaded onto my Kindle Paperwhite I can take my favourite books with me, in my pocket, wherever I go and have immediate access to them when and where I want. An eBook copy of any Ken Follett book is much easier to manage than the oft 800-odd page hard-back equivalent.
As far as technical books go, it may sometimes not be as straightforward as when reading a novel. Because eBooks are a one size fits all entity, it makes formatting them for all possible instances difficult. In fact, it is a lot easier to format a print book than an eBook.
Long program listings, especially which contain copious comments can be unwieldly in an eBook. Thus, I would strongly advise downloading the source code for the programs and scrutinising these at the relevant point. There are several tables and figures, and in many cases, you can click on the highlighted corner to display the table full screen.
Figure . eBook open on Raspberry Pi Desktop, along with appropriate program.
Acknowledgements
Thanks go to Richard Khoury for his help with the C segments within this book and the finer art of using GCC and GDB. Thanks to Mike Ginns for the concepts of several programs listed here. Some listings originate from his book Archimedes Assembly Language which was first published by Dabs Press in 1988. (A key to how old the ARM is!) Also, I am grateful to Brian Scallan, Steve Cirelli and Tony Palmer for their feedback and updates. I am also indebted to the many readers who have written with suggestions to improve this book.
Dedication
Dedicated to all the health care workers, nurses, doctors and carers around the world. To the ones that gave their all in a time of need during the pandemic. Their memory will be embedded into our hearts for years to come. Thank you.
About the Author
Bruce Smith purchased his first computeran Acorn Atom in 1980. He was immediately hooked, becoming a regular contributor to the mainstream computer press including Computing Today and Personal Computer World. With the arrival of the BBC Micro his magazine work expanded into books and his 1982 title Interfacing Projects for the BBC Micro has become regarded as a classic of the time as the first book showing home users how to connect the computer to the outside world. He was one of the first to write about the ARM chip when it was released on the Acorn Archimedes in 1987. Bruce has written about all aspects of computer use. His friendly, lucid style of writing caused one reviewer to write, This is the first computer book I have read in bed for pleasure rather than to cure insomnia! Bruces books have been translated into many languages and sold across the world. His publishers have included BBC Books, Collins, Virgin Books and Rough Guides. Originally from Londons East End, he now lives in Sydney, NSW.
Table of Contents
1. Introduction
It didnt surprise me when, early in 2013, it was announced that the Raspberry Pi had sold one million units. And counting It took me back more years decades even than I care to remember when it was announced that the BBC Micro had done the same. Both came out of businesses based in Cambridge in the UK and there were even more links between the two than you might imagine.
Both systems fascinated me and literally millions of other people. The first system took every penny of my savings at the time, but the Raspberry Pi didnt even drain the cash in my wallet. But whist the ticket price for each was vastly different, pretty much everything else about them was so familiar. Not least their ability to run a wide range of software and educational tools and how easy it was to connect external devices and control the outside world. I would suspect that most people who own one Raspberry Pi, own several.
Figure 1a . An Original Raspberry Pi Model B.
For the first time since the BBC Micro there is an affordable and infinitely accessible system that just about anyone can use. Meanwhile, the PC and Mac have dominated the market and other more games-orientated boxes have been available. But none of these have impacted the technical home hobbyist user. The techsperts have had a variety of development boards to experiment and fiddle with, again mostly beyond the scope of the home hobbyist computer market. For the cost of a couple of CDs or new release DVD, the Raspberry Pi has changed all that.
The launch of the Raspberry Pi Zero in November 2015 took cheapness to a new level. A fully-fledged ARM-driven computer for just $5. Insane! And if that wasnt enough the December 2015 issue of MagPi (the official Raspberry Pi magazine) had it bound on the cover as a free give away. Could the Raspberry Pi be classed as the worlds first disposable computer?
At the time of updating this introduction for the fourth edition (December 2020) sales had surpassed 30 million across the various models available. Indeed, that figure was reported to have been passed by the start of 2020 with a variety of organisations using at the very heart of their infrastructure and development. Oracle hailed its cluster of 1,060 Raspberry Pi boards the worlds largest Pi supercomputer, sporting 4,240 cores. The Jet Propulsion Laboratory (JPL) also uses the boards for its Mars mission.
Imagination Unlimited
One reason for the birth of the Raspberry Pi was to make it easy for people to take up programming, with the aid of a competitively priced computer system whose use was limited only by the users imagination. I hope this book will help many of you reading it realise that dream. In fact, it isnt a dream. It is a probability if you continue your way through the pages that follow a first step on a rewarding and educational pastime. And, who knows, you may become part of a new generation of computer programmers working at the sharp end of what is possible.