100% found this document useful (2 votes)
190 views

Programming With 64bit Arm Assembly Language Single Board Computer Development For Raspberry Pi And Mobile Devices Stephen Smith download

The document is about 'Programming with 64-Bit ARM Assembly Language' by Stephen Smith, focusing on single board computer development for Raspberry Pi and mobile devices. It covers essential topics such as assembly instructions, memory management, and program flow control. The book includes practical exercises and examples to aid in understanding ARM assembly programming.

Uploaded by

usinareska9d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
190 views

Programming With 64bit Arm Assembly Language Single Board Computer Development For Raspberry Pi And Mobile Devices Stephen Smith download

The document is about 'Programming with 64-Bit ARM Assembly Language' by Stephen Smith, focusing on single board computer development for Raspberry Pi and mobile devices. It covers essential topics such as assembly instructions, memory management, and program flow control. The book includes practical exercises and examples to aid in understanding ARM assembly programming.

Uploaded by

usinareska9d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

Programming With 64bit Arm Assembly Language

Single Board Computer Development For Raspberry


Pi And Mobile Devices Stephen Smith download

https://ebookbell.com/product/programming-with-64bit-arm-
assembly-language-single-board-computer-development-for-
raspberry-pi-and-mobile-devices-stephen-smith-11144382

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

The Intel Microprocessors 80868088 8018680188 80286 80386 80486


Pentium Pentium Pro Processor Pentium Ii Pentium Iii Pentium 4 And
Core2 With 64bit Extensions Architecture Programming And Interfacing
8th Ed Barry B Brey
https://ebookbell.com/product/the-intel-
microprocessors-80868088-8018680188-80286-80386-80486-pentium-pentium-
pro-processor-pentium-ii-pentium-iii-pentium-4-and-core2-with-64bit-
extensions-architecture-programming-and-interfacing-8th-ed-barry-b-
brey-22041436

Programming With Openscad A Beginners Guide To Coding 3dprintable


Objects 1st Edition Justin Gohde

https://ebookbell.com/product/programming-with-openscad-a-beginners-
guide-to-coding-3dprintable-objects-1st-edition-justin-gohde-46410140

Programming With Python And Its Applications To Physical Systems M


Shubhakanta Singh

https://ebookbell.com/product/programming-with-python-and-its-
applications-to-physical-systems-m-shubhakanta-singh-50637024

Programming With Microsoft Visual Basic 2012 6th Edition Zak

https://ebookbell.com/product/programming-with-microsoft-visual-
basic-2012-6th-edition-zak-55132386
Programming With Microsoft Visual Basic 2010 Vbnet Programming 5th
Edition Zak

https://ebookbell.com/product/programming-with-microsoft-visual-
basic-2010-vbnet-programming-5th-edition-zak-55139980

Programming With Java Edet Theophilus

https://ebookbell.com/product/programming-with-java-edet-
theophilus-55229942

Programming With Rust Donis Marshall

https://ebookbell.com/product/programming-with-rust-donis-
marshall-55709862

Programming With C20 Concepts Coroutines Ranges And More Updated 2024
2nd Edition Andreas Fertig

https://ebookbell.com/product/programming-with-c20-concepts-
coroutines-ranges-and-more-updated-2024-2nd-edition-andreas-
fertig-56812174

Programming With Tensorflow Kolla Bhanu Prakash G R


Kanagachidambaresan

https://ebookbell.com/product/programming-with-tensorflow-kolla-bhanu-
prakash-g-r-kanagachidambaresan-22736720
TECHNOLOGY IN AC TION™

Programming
with 64-Bit
ARM Assembly
Language
Single Board Computer Development
for Raspberry Pi and Mobile Devices

Stephen Smith
Programming with
64-Bit ARM Assembly
Language
Single Board Computer
Development for Raspberry Pi
and Mobile Devices

Stephen Smith
Programming with 64-Bit ARM Assembly Language: Single Board
Computer Development for Raspberry Pi and Mobile Devices
Stephen Smith
Gibsons, BC, Canada

ISBN-13 (pbk): 978-1-4842-5880-4 ISBN-13 (electronic): 978-1-4842-5881-1


https://doi.org/10.1007/978-1-4842-5881-1

Copyright © 2020 by Stephen Smith


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.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Aaron Black
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
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.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.
com/rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our
Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book’s product page, located at www.apress.com/
978-1-4842-5880-4. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
This book is dedicated to my beloved wife and
editor Cathalynn Labonté-Smith.
Table of Contents
About the Author������������������������������������������������������������������������������xvii

About the Technical Reviewer�����������������������������������������������������������xix


Acknowledgments�����������������������������������������������������������������������������xxi
Introduction�������������������������������������������������������������������������������������xxiii

Chapter 1: Getting Started��������������������������������������������������������������������1


The Surprise Birth of the 64-Bit ARM��������������������������������������������������������������������2
What You Will Learn����������������������������������������������������������������������������������������������3
Why Use Assembly������������������������������������������������������������������������������������������������3
Tools You Need������������������������������������������������������������������������������������������������������6
Raspberry Pi 4 or NVidia Jetson Nano�������������������������������������������������������������6
Text Editor��������������������������������������������������������������������������������������������������������7
Specialty Programs�����������������������������������������������������������������������������������������7
Computers and Numbers��������������������������������������������������������������������������������������8
ARM Assembly Instructions��������������������������������������������������������������������������������11
CPU Registers������������������������������������������������������������������������������������������������12
ARM Instruction Format���������������������������������������������������������������������������������13
Computer Memory�����������������������������������������������������������������������������������������16
About the GCC Assembler�����������������������������������������������������������������������������������17
Hello World����������������������������������������������������������������������������������������������������������18
About Comments�������������������������������������������������������������������������������������������20
Where to Start�����������������������������������������������������������������������������������������������21

v
Table of Contents

Assembly Instructions�����������������������������������������������������������������������������������22
Data���������������������������������������������������������������������������������������������������������������22
Calling Linux��������������������������������������������������������������������������������������������������23
Reverse Engineering Our Program����������������������������������������������������������������24
Summary������������������������������������������������������������������������������������������������������������26
Exercises�������������������������������������������������������������������������������������������������������������27

Chapter 2: Loading and Adding����������������������������������������������������������29


Negative Numbers����������������������������������������������������������������������������������������������29
About Two’s Complement������������������������������������������������������������������������������29
About Gnome Programmer’s Calculator��������������������������������������������������������31
About One’s Complement������������������������������������������������������������������������������32
Big vs. Little Endian��������������������������������������������������������������������������������������������33
About Bi-endian���������������������������������������������������������������������������������������������34
Pros of Little Endian��������������������������������������������������������������������������������������34
Shifting and Rotating������������������������������������������������������������������������������������������35
About Carry Flag��������������������������������������������������������������������������������������������36
About the Barrel Shifter���������������������������������������������������������������������������������36
Basics of Shifting and Rotating���������������������������������������������������������������������37
Loading Registers�����������������������������������������������������������������������������������������������38
Instruction Aliases�����������������������������������������������������������������������������������������39
MOV/MOVK/MOVN������������������������������������������������������������������������������������������40
About Operand2���������������������������������������������������������������������������������������������42
MOVN�������������������������������������������������������������������������������������������������������������45
MOV Examples�����������������������������������������������������������������������������������������������46
ADD/ADC�������������������������������������������������������������������������������������������������������������50
Add with Carry�����������������������������������������������������������������������������������������������52
SUB/SBC�������������������������������������������������������������������������������������������������������������55

vi
Table of Contents

Summary������������������������������������������������������������������������������������������������������������56
Exercises�������������������������������������������������������������������������������������������������������������56

Chapter 3: Tooling Up�������������������������������������������������������������������������59


GNU Make�����������������������������������������������������������������������������������������������������������59
Rebuilding a File��������������������������������������������������������������������������������������������60
A Rule for Building .s Files����������������������������������������������������������������������������61
Defining Variables������������������������������������������������������������������������������������������61
GDB���������������������������������������������������������������������������������������������������������������������62
Preparing to Debug����������������������������������������������������������������������������������������63
Beginning GDB�����������������������������������������������������������������������������������������������65
Cross-Compiling��������������������������������������������������������������������������������������������������70
Emulation������������������������������������������������������������������������������������������������������72
Android NDK��������������������������������������������������������������������������������������������������������72
Apple XCode��������������������������������������������������������������������������������������������������������77
Source Control and Build Servers�����������������������������������������������������������������������82
Git������������������������������������������������������������������������������������������������������������������82
Jenkins����������������������������������������������������������������������������������������������������������83
Summary������������������������������������������������������������������������������������������������������������84
Exercises�������������������������������������������������������������������������������������������������������������84

Chapter 4: Controlling Program Flow�������������������������������������������������87


Unconditional Branch������������������������������������������������������������������������������������������87
About Condition Flags�����������������������������������������������������������������������������������������88
Branch on Condition��������������������������������������������������������������������������������������������90
About the CMP Instruction����������������������������������������������������������������������������������90
Loops������������������������������������������������������������������������������������������������������������������92
FOR Loops�����������������������������������������������������������������������������������������������������92
While Loops���������������������������������������������������������������������������������������������������93

vii
Table of Contents

If/Then/Else���������������������������������������������������������������������������������������������������������94
Logical Operators������������������������������������������������������������������������������������������������95
AND����������������������������������������������������������������������������������������������������������������96
EOR����������������������������������������������������������������������������������������������������������������96
ORR����������������������������������������������������������������������������������������������������������������96
BIC�����������������������������������������������������������������������������������������������������������������97
Design Patterns���������������������������������������������������������������������������������������������������97
Converting Integers to ASCII�������������������������������������������������������������������������������98
Using Expressions in Immediate Constants������������������������������������������������102
Storing a Register to Memory����������������������������������������������������������������������103
Why Not Print in Decimal?���������������������������������������������������������������������������103
Performance of Branch Instructions�����������������������������������������������������������������104
More Comparison Instructions��������������������������������������������������������������������������105
Summary����������������������������������������������������������������������������������������������������������106
Exercises�����������������������������������������������������������������������������������������������������������106

Chapter 5: Thanks for the Memories������������������������������������������������109


Defining Memory Contents�������������������������������������������������������������������������������110
Aligning Data�����������������������������������������������������������������������������������������������114
Loading a Register with an Address�����������������������������������������������������������������114
PC Relative Addressing��������������������������������������������������������������������������������115
Loading Data from Memory������������������������������������������������������������������������������117
Indexing Through Memory���������������������������������������������������������������������������119
Storing a Register���������������������������������������������������������������������������������������������131
Double Registers�����������������������������������������������������������������������������������������������131
Summary����������������������������������������������������������������������������������������������������������132
Exercises�����������������������������������������������������������������������������������������������������������133

viii
Table of Contents

Chapter 6: Functions and the Stack�������������������������������������������������135


Stacks on Linux�������������������������������������������������������������������������������������������������136
Branch with Link�����������������������������������������������������������������������������������������������138
Nesting Function Calls��������������������������������������������������������������������������������������139
Function Parameters and Return Values�����������������������������������������������������������141
Managing the Registers������������������������������������������������������������������������������������142
Summary of the Function Call Algorithm����������������������������������������������������������143
Upper-Case Revisited����������������������������������������������������������������������������������������144
Stack Frames����������������������������������������������������������������������������������������������������148
Stack Frame Example����������������������������������������������������������������������������������150
Macros��������������������������������������������������������������������������������������������������������������151
Include Directive������������������������������������������������������������������������������������������154
Macro Definition������������������������������������������������������������������������������������������155
Labels����������������������������������������������������������������������������������������������������������155
Why Macros?�����������������������������������������������������������������������������������������������156
Macros to Improve Code������������������������������������������������������������������������������157
Summary����������������������������������������������������������������������������������������������������������158
Exercises�����������������������������������������������������������������������������������������������������������158

Chapter 7: Linux Operating System Services�����������������������������������161


So Many Services���������������������������������������������������������������������������������������������161
Calling Convention��������������������������������������������������������������������������������������������162
Linux System Call Numbers�������������������������������������������������������������������������163
Return Codes�����������������������������������������������������������������������������������������������163
Structures����������������������������������������������������������������������������������������������������164
Wrappers�����������������������������������������������������������������������������������������������������������165
Converting a File to Upper-Case�����������������������������������������������������������������������166

ix
Table of Contents

Building .S Files�������������������������������������������������������������������������������������������170
Opening a File����������������������������������������������������������������������������������������������172
Error Checking���������������������������������������������������������������������������������������������172
Looping��������������������������������������������������������������������������������������������������������174
Summary����������������������������������������������������������������������������������������������������������175
Exercises�����������������������������������������������������������������������������������������������������������176

Chapter 8: Programming GPIO Pins��������������������������������������������������177


GPIO Overview��������������������������������������������������������������������������������������������������177
In Linux, Everything Is a File�����������������������������������������������������������������������������178
Flashing LEDs���������������������������������������������������������������������������������������������������179
Moving Closer to the Metal�������������������������������������������������������������������������������185
Virtual Memory��������������������������������������������������������������������������������������������������185
In Devices, Everything Is Memory���������������������������������������������������������������������186
Registers in Bits������������������������������������������������������������������������������������������������188
GPIO Function Select Registers�������������������������������������������������������������������189
GPIO Output Set and Clear Registers�����������������������������������������������������������190
More Flashing LEDs������������������������������������������������������������������������������������������191
Root Access�������������������������������������������������������������������������������������������������197
Table Driven�������������������������������������������������������������������������������������������������197
Setting Pin Direction������������������������������������������������������������������������������������198
Setting and Clearing Pins����������������������������������������������������������������������������199
Summary����������������������������������������������������������������������������������������������������������200
Exercises�����������������������������������������������������������������������������������������������������������201

Chapter 9: Interacting with C and Python����������������������������������������203


Calling C Routines���������������������������������������������������������������������������������������������203
Printing Debug Information�������������������������������������������������������������������������204
Adding with Carry Revisited������������������������������������������������������������������������209

x
Table of Contents

Calling Assembly Routines from C��������������������������������������������������������������������211


Packaging Our Code������������������������������������������������������������������������������������������213
Static Library�����������������������������������������������������������������������������������������������214
Shared Library���������������������������������������������������������������������������������������������215
Embedding Assembly Code Inside C Code��������������������������������������������������������218
Calling Assembly from Python��������������������������������������������������������������������������221
Summary����������������������������������������������������������������������������������������������������������223
Exercises�����������������������������������������������������������������������������������������������������������224

Chapter 10: Interfacing with Kotlin and Swift����������������������������������225


About Kotlin, Swift, and Java����������������������������������������������������������������������������225
Creating an Android App�����������������������������������������������������������������������������������226
Create the Project����������������������������������������������������������������������������������������227
XML Screen Definition���������������������������������������������������������������������������������230
Kotlin Main Program������������������������������������������������������������������������������������233
The C++ Wrapper����������������������������������������������������������������������������������������235
Building the Project�������������������������������������������������������������������������������������236
Creating an iOS App������������������������������������������������������������������������������������������239
Create the Project����������������������������������������������������������������������������������������240
Adding Elements to the Main Storyboard����������������������������������������������������240
Adding Swift Code���������������������������������������������������������������������������������������241
Adding our Assembly Language Routine�����������������������������������������������������244
Creating the Bridge��������������������������������������������������������������������������������������245
Building and Running the Project����������������������������������������������������������������246
Tips for Optimizing Apps�����������������������������������������������������������������������������������247
Summary����������������������������������������������������������������������������������������������������������248
Exercises�����������������������������������������������������������������������������������������������������������248

xi
Table of Contents

Chapter 11: Multiply, Divide, and Accumulate����������������������������������249


Multiplication����������������������������������������������������������������������������������������������������249
Examples�����������������������������������������������������������������������������������������������������251
Division�������������������������������������������������������������������������������������������������������������255
Example�������������������������������������������������������������������������������������������������������256
Multiply and Accumulate����������������������������������������������������������������������������������258
Vectors and Matrices�����������������������������������������������������������������������������������258
Accumulate Instructions������������������������������������������������������������������������������260
Example 1����������������������������������������������������������������������������������������������������261
Summary����������������������������������������������������������������������������������������������������������266
Exercises�����������������������������������������������������������������������������������������������������������267

Chapter 12: Floating-Point Operations���������������������������������������������269


About Floating-Point Numbers��������������������������������������������������������������������������269
About Normalization and NaNs��������������������������������������������������������������������271
Recognizing Rounding Errors����������������������������������������������������������������������271
Defining Floating-Point Numbers����������������������������������������������������������������������272
About FPU Registers�����������������������������������������������������������������������������������������273
Defining the Function Call Protocol�������������������������������������������������������������������274
Loading and Saving FPU Registers�������������������������������������������������������������������274
Performing Basic Arithmetic�����������������������������������������������������������������������������276
Calculating Distance Between Points���������������������������������������������������������������277
Performing Floating-Point Conversions������������������������������������������������������������281
Comparing Floating-Point Numbers������������������������������������������������������������������282
Example�������������������������������������������������������������������������������������������������������283
Summary����������������������������������������������������������������������������������������������������������288
Exercises�����������������������������������������������������������������������������������������������������������288

xii
Table of Contents

Chapter 13: Neon Coprocessor���������������������������������������������������������291


About the NEON Registers��������������������������������������������������������������������������������291
Stay in Your Lane����������������������������������������������������������������������������������������������292
Performing Arithmetic Operations���������������������������������������������������������������������294
Calculating 4D Vector Distance�������������������������������������������������������������������������295
Optimizing 3x3 Matrix Multiplication����������������������������������������������������������������300
Summary����������������������������������������������������������������������������������������������������������305
Exercises�����������������������������������������������������������������������������������������������������������306

Chapter 14: Optimizing Code������������������������������������������������������������307


Optimizing the Upper-Case Routine������������������������������������������������������������������307
Simplifying the Range Comparison�������������������������������������������������������������308
Using a Conditional Instruction��������������������������������������������������������������������311
Restricting the Problem Domain������������������������������������������������������������������314
Using Parallelism with SIMD�����������������������������������������������������������������������317
Tips for Optimizing Code�����������������������������������������������������������������������������������321
Avoiding Branch Instructions�����������������������������������������������������������������������321
Avoiding Expensive Instructions������������������������������������������������������������������322
Don’t Be Afraid of Macros����������������������������������������������������������������������������323
Loop Unrolling���������������������������������������������������������������������������������������������323
Keeping Data Small�������������������������������������������������������������������������������������323
Beware of Overheating��������������������������������������������������������������������������������323
Summary����������������������������������������������������������������������������������������������������������324
Exercises�����������������������������������������������������������������������������������������������������������324

xiii
Table of Contents

Chapter 15: Reading and Understanding Code���������������������������������327


Browsing Linux and GCC Code��������������������������������������������������������������������������328
Copying a Page of Memory��������������������������������������������������������������������������329
Code Created by GCC����������������������������������������������������������������������������������������335
Using the CBNZ and CBZ Instructions����������������������������������������������������������340
Reverse Engineering and Ghidra�����������������������������������������������������������������������340
Summary����������������������������������������������������������������������������������������������������������345
Exercises�����������������������������������������������������������������������������������������������������������346

Chapter 16: Hacking Code����������������������������������������������������������������347


Buffer Overrun Hack�����������������������������������������������������������������������������������������347
Causes of Buffer Overrun����������������������������������������������������������������������������������347
Stealing Credit Card Numbers���������������������������������������������������������������������������348
Stepping Through the Stack������������������������������������������������������������������������351
Mitigating Buffer Overrun Vulnerabilities����������������������������������������������������������354
Don’t Use strcpy������������������������������������������������������������������������������������������355
PIE Is Good���������������������������������������������������������������������������������������������������357
Poor Stack Canaries Are the First to Go�������������������������������������������������������358
Preventing Code Running on the Stack�������������������������������������������������������362
Trade-offs of Buffer Overflow Mitigation Techniques����������������������������������������362
Summary����������������������������������������������������������������������������������������������������������364
Exercises�����������������������������������������������������������������������������������������������������������365

Appendix A: The ARM Instruction Set�����������������������������������������������367


ARM 64-Bit Core Instructions����������������������������������������������������������������������������367
ARM 64-Bit NEON and FPU Instructions������������������������������������������������������������386

xiv
Table of Contents

Appendix B: Binary Formats�������������������������������������������������������������401


Integers�������������������������������������������������������������������������������������������������������������401
Floating Point����������������������������������������������������������������������������������������������������402
Addresses���������������������������������������������������������������������������������������������������������403

Appendix C: Assembler Directives����������������������������������������������������405

Appendix D: ASCII Character Set������������������������������������������������������407

Answers to Exercises�����������������������������������������������������������������������419
Chapter 1����������������������������������������������������������������������������������������������������������419
Chapter 2����������������������������������������������������������������������������������������������������������419
Chapter 5����������������������������������������������������������������������������������������������������������420
Chapter 6����������������������������������������������������������������������������������������������������������420
Chapter 8����������������������������������������������������������������������������������������������������������420
Chapter 14��������������������������������������������������������������������������������������������������������421

Index�������������������������������������������������������������������������������������������������423

xv
About the Author
Stephen Smith is also the author of the
Apress title Raspberry Pi Assembly Language
Programming. He is a retired Software
Architect, located in Gibsons, BC, Canada.
He’s 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 Influence series available on
Amazon.com.

xvii
About the Technical Reviewer
Stewart Watkiss is a keen maker and
programmer. He has a master’s degree in
electronic engineering from the University
of Hull and a master’s degree in computer
science from Georgia Institute of Technology.
He has over 20 years of experience in the
IT industry, working in computer networking,
Linux system administration, technical
support, and cyber security. While working
toward Linux certification, he created the web
site www.penguintutor.com. The web site originally provided information
for those studying toward certification but has since added information on
electronics, projects, and learning computer programming.
Stewart often gives talks and runs workshops at local Raspberry Pi
events. He is also a STEM Ambassador and Code Club volunteer helping to
support teachers and children learning programming.

xix
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.

xxi
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, they’re
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.

xxiii
Introduction

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 Google’s Android, Apple’s iOS,


and Linux

• How to program the hardware directly using the


Raspberry Pi’s 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. There’s 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 don’t be afraid to experiment, as it is the only way you will learn.
Even if you don’t 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
aren’t interested in interfacing to hardware, you can skip Chapter 8,
“Programming GPIO Pins,” or Chapter 12, “Floating-Point Operations,” if
you will never do numerical computing.

xxiv
Introduction

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.

xxv
CHAPTER 1

Getting Started
The ARM processor was originally developed by Acorn Computers in
Great Britain, who wanted to build a successor to the BBC Microcomputer
used for educational purposes. The BBC Microcomputer used the 6502
processor, which was a simple processor with a simple instruction set. The
problem was there was no successor to the 6502. The engineers working
on the Acorn computer weren’t happy with the microprocessors available
at the time, since they were much more complicated than the 6502, and
they didn’t want to make just another IBM PC clone. They took the bold
move to design their own and founded Advanced RISC Machines Ltd.
to do it. They developed the Acorn computer and tried to position it as
the successor to the BBC Microcomputer. The idea was to use reduced
instruction set computer (RISC) technology as opposed to complex
instruction set computer (CISC) as championed by Intel and Motorola.
We will talk at length about what these terms mean later.
Developing silicon chips is costly, and without high volumes,
manufacturing them is expensive. The ARM processor probably wouldn’t
have gone anywhere except that Apple came calling. They were looking
for a processor for a new device under development—the iPod. The key
selling point for Apple was that as the ARM processor was RISC, it used
less silicon than CISC processors and as a result used far less power. This
meant it was possible to build a device that ran for a long time on a single
battery charge.

© Stephen Smith 2020 1


S. Smith, Programming with 64-Bit ARM Assembly Language,
https://doi.org/10.1007/978-1-4842-5881-1_1
Chapter 1 Getting Started

The Surprise Birth of the 64-Bit ARM


The early iPhones and Android phones were all based on 32-bit ARM
processors. At that time, even though most server and desktop operating
systems moved to 64 bits, it was believed that there was no need in the mobile
world for 64 bits. Then in 2013, Apple shocked the ARM world by introducing
the 64-bit capable A7 chip and started the migration of all iOS programs to
64 bits. The performance gains astonished everyone and caught all their
competitors flat footed. Now, all newer ARM processors support 64-bit
processing, and all the major ARM operating systems have moved to 64 bits.
Two benefits of ARM 64-bit programming are that ARM cleaned up
their instruction set and simplified Assembly Language programming.
They also adapted the code, so that it will run more efficiently on modern
processors with larger execution pipelines. There are still a lot of details
and complexities to master, but if you have experience in 32-bit ARM, you
will find 64-bit programming simpler and more consistent.
However, there is still a need for 32-bit processing, for instance,
Raspbian, the default operating system for the Raspberry Pi, is 32 bits,
along with several real-time and embedded systems. If you have 1GB of
memory or less, 32 bits is better, but once you have more than 1GB of RAM,
then the benefits of 64-bit programming become hard to ignore.
Unlike Intel, ARM doesn’t manufacture chips; it just licenses the
designs for others to optimize and manufacture. With Apple onboard,
suddenly there was a lot of interest in ARM, and several big manufacturers
started producing chips. With the advent of smartphones, the ARM chip
really took off and now is used in pretty much every phone and tablet. ARM
processors power some Chromebooks and even Microsoft’s Surface Pro X.
The ARM processor is the number one processor in the computer
market. Each year the ARM processors powering the leading-edge phones
become more and more powerful. We are starting to see ARM-based
servers used in datacenters, including Amazon’s AWS. There are several
ARM-based laptops and desktop computers in the works.

2
Chapter 1 Getting Started

What You Will Learn


You will learn Assembly Language programming for the ARM running in
64-bit mode. Everything you will learn is directly applicable to all ARM
devices running in 64-bit mode. Learning Assembly Language for one
processor gives you the tools to learn it for another processor, perhaps, the
forthcoming RISC-V, a new open source RISC processor that originated from
Berkeley University. The RISC-V architecture promises high functionality
and speed for less power and cost than an equivalent ARM processor.
In all devices, the ARM processor isn’t just a CPU; it’s a system on
a chip. This means that most of the computer is all on one chip. When
a company is designing a device, they can select various modular
components to include on their chip. Typically, this contains an ARM
processor with multiple cores, meaning that it can process instructions for
multiple programs running at once. It likely contains several coprocessors
for things like floating-point calculations, a graphics processing unit
(GPU), and specialized multimedia support. There are extensions available
for cryptography, advanced virtualization, and security monitoring.

Why Use Assembly


Most programmers write in a high-level programming language like
Python, C#, Java, JavaScript, Go, Julia, Scratch, Ruby, Swift, or C. These
highly productive languages are used to write major programs from
the Linux operating system to web sites like Facebook, to productivity
software like LibreOffice. If you learn to be a good programmer in a couple
of these, you can find a well-paying interesting job and write some great
programs. If you create a program in one of these languages, you can
easily get it working on numerous operating systems on multiple hardware
architectures. You never have to learn the details of all the bits and bytes,
and these can remain safely under the covers.

3
Chapter 1 Getting Started

When you program in Assembly Language, you are tightly coupled to


a given CPU, and moving your program to another requires a complete
rewrite of your program. Each Assembly Language instruction does only
a fraction of the amount of work, so to do anything takes a lot of Assembly
statements. Therefore, to do the same work as, say, a Python program,
takes an order of magnitude larger amount of effort, for the programmer.
Writing in Assembly is harder, as you must solve problems with memory
addressing and CPU registers that is all handled transparently by high-­
level languages. So why would you want to learn Assembly Language
programming? Here are ten reasons people learn and use Assembly
Language:

1. To write more efficient code: Even if you don’t


write Assembly Language code, knowing how the
computer works internally allows you to write
more streamlined code. You can make your data
structures easier to access and write code in a
style that allows the compiler to generate more
effective code. You can make better use of computer
resources, like coprocessors, and use the given
computer to its fullest potential.

2. To write your own operating system: The core of


the operating system that initializes the CPU and
handles hardware security and multithreading/
multitasking requires Assembly code.

3. To create a new programming language: If it is


a compiled language, then you need to generate
the Assembly code to execute. The quality and
speed of your language is largely dependent on the
quality and speed of the Assembly Language code it
generates.

4
Chapter 1 Getting Started

4. To make your computer run faster: The best way to


make Linux faster is to improve the GNU C compiler.
If you improve the ARM 64-bit Assembly code
produced by GNU C, then every program compiled
by GCC benefits.

5. To interface your computer to a hardware


device: When interfacing your computer through
USB or GPIO ports, the speed of data transfer is
highly sensitive as to how fast your program can
process the data. Perhaps, there are a lot of bit
level manipulations that are easier to program in
Assembly.

6. To do faster machine learning or three-


dimensional (3D) graphics programming: Both
applications rely on fast matrix mathematics. If you
can make this faster with Assembly and/or using
the coprocessors, then you can make your AI-based
robot or video game that much better.

7. To boost performance: Most large programs


have components written in different languages.
If your program is 99% C++, the other 1% could
be Assembly, perhaps giving your program a
performance boost or some other competitive
advantage.

8. To manage single board computer competitors


to the Raspberry Pi: These boards have some
Assembly Language code to manage peripherals
included with the board. This code is usually called
a BIOS (basic input/output system).

5
Chapter 1 Getting Started

9. To look for security vulnerabilities in a program


or piece of hardware: Look at the Assembly code to
do this; otherwise you may not know what is really
going on and hence where holes might exist.
10. To look for Easter eggs in programs: These are
hidden messages, images, or inside jokes that
programmers hide in their programs. They are
usually triggered by finding a secret keyboard
combination to pop them up. Finding them requires
reverse engineering the program and reading
Assembly Language.

T ools You Need


The best way to learn programming is by doing. The easiest way to play
with 64-bit ARM Assembly Language is with an inexpensive single board
computer (SBC) like the Raspberry Pi or NVidia Jetson Nano. We will
cover developing for Android and iOS, but these sections are optional.
In addition to a computer, you will need

• A text editor

• Some optional specialty programs

Raspberry Pi 4 or NVidia Jetson Nano


The Raspberry Pi 4 with 4GB of RAM is an excellent computer to run 64-bit
Linux. If you use a Raspberry Pi 4, then you need to download and install
a 64-bit version of Linux. These are available from Kali, Ubuntu, Gentoo,
Manjaro, and others. I find Kali Linux works very well and will be using
it to test all the programs in this book. You can find the Kali Linux
downloads here: www.offensive-security.com/kali-linux-arm-images/.

6
Chapter 1 Getting Started

Although you can run 64-bit Linux on a Raspberry Pi 3 or a Raspberry Pi


4 with 1GB of RAM, I find these slow and bog down if you run too many
programs. I wouldn’t recommend these, but you can use them in a pinch.
The NVidia Jetson Nano uses 64-bit Ubuntu Linux. This is an excellent
platform for learning ARM 64-bit Assembly Language. The Jetson Nano
also has 128 CUDA graphics processing cores that you can play with.
One of the great things about the Linux operating system is that
it is intended to be used for programming and as a result has many
programming tools preinstalled, including

• GNU Compiler Collection (GCC) that we will use to


build our Assembly Language programs. We will use
GCC for compiling C programs in later chapters.

• GNU Make to build our programs.

• GNU Debugger (GDB) to find and solve problems in


our programs.

Text Editor
You will need a text editor to create the source program files. Any text
editor can be used. Linux usually includes several by default, both
command line and via the GUI. Usually, you learn Assembly Language
after you’ve already mastered a high-level language like C or Java. So,
chances are you already have a favorite editor and can continue to use it.

Specialty Programs
We will mention other helpful programs throughout the book that you can
optionally use, but aren’t required, for example:

• The Android SDK

• Apple’s XCode IDE

7
Chapter 1 Getting Started

• A better code analysis tool, like Ghidra, which we will


discuss in Chapter 15, “Reading and Understanding Code”

All of these are either open source or free, but there may be some
restrictions on where you can install them.
Now we will switch gears to how computers represent numbers. We
always hear that computers only deal in zeros and ones; now we’ll look at
how they put them together to represent larger numbers.

C
 omputers and Numbers
We typically represent numbers using base 10. The common theory is we
do this, because we have ten fingers to count with. This means a number
like 387 is really a representation for

387 = 3 * 102 + 8 * 101 + 7 * 100


    = 3 * 100 + 8 * 10 + 7
    = 300 + 80 + 7

There is nothing special about using 10 as our base, and a fun exercise in
math class is to do arithmetic using other bases. In fact, the Mayan culture
used base 20, perhaps because we have 20 digits: ten fingers and ten toes.
Computers don’t have fingers and toes; rather, everything is a switch
that is either on or off. As a result, computers are programmed to use base
2 arithmetic. Thus, a computer recognizes a number like 1011 as

1011 = 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20
     = 1 * 8 + 0 * 4 + 1 * 2 + 1
     = 8 + 0 + 2 + 1
     = 11 (decimal)

This is extremely efficient for computers, but we are using four digits
for the decimal number 11 rather than two digits. The big disadvantage for
humans is that writing, or even keyboarding, binary numbers is tiring.

8
Chapter 1 Getting Started

Computers are incredibly structured, with their numbers being the


same size in storage used. When designing computers, it doesn’t make
sense to have different sized numbers, so a few common sizes have taken
hold and become standard.
A byte is 8 binary bits or digits. In our preceding example with 4 bits,
there are 16 possible combinations of 0s and 1s. This means 4 bits can
represent the numbers 0 to 15. This means it can be represented by one
base 16 digit. Base 16 digits are represented by the numbers 0–9 and then
the letters A–F for 10–15. We can then represent a byte (8 bits) as two base
16 digits. We refer to base 16 numbers as hexadecimal (Figure 1-1).

Figure 1-1. Representing hexadecimal digits

Since a byte holds 8 bits, it can represent 28 (256) numbers. Thus, the
byte e6 represents

e6 = e * 161 + 6 * 160
   = 14 * 16 + 6
   = 230 (decimal)
   = 1110 0110 (binary)

We call a 32-bit quantity a word and it is represented by 4 bytes. You


might see a string like B6 A4 44 04 as a representation of 32 bits of memory,
or one word of memory, or the contents of one register. Even though we
are running 64 bits, the ARM reference documentation refers to a word as
32 bits, a halfword is 16 bits, and a doubleword is 64 bits. We will see this
terminology throughout this book and the ARM documentation.
If this is confusing or scary, don’t worry. The tools will do all the
conversions for you. It’s just a matter of understanding what is presented to
you on screen. Also, if you need to specify an exact binary number, usually
you do so in hexadecimal, although all the tools accept all the formats.

9
Chapter 1 Getting Started

A handy tool is the Linux Gnome calculator (Figure 1-2). The Gnome
calculator has a nice programming mode which shows a number’s
representation in multiple bases at once. This calculator is installed in
Ubuntu Linux, if you are running the Gnome desktop. However, if you
don’t have it, it is easy to add. If you are running a Debian-derived Linux
like Ubuntu or Kali, to install it, use the command line:

sudo apt-get install gnome-calculator

Run it from the Accessories menu. If you put it in “Programmer Mode,”


you can do the conversions, and it shows you numbers in several formats
at once.

Figure 1-2. The Gnome calculator

10
Chapter 1 Getting Started

This is how we represent computer memory. There is a bit more


complexity in how signed integers are represented and how arithmetic
works. We’ll cover this in Chapter 2, “Loading and Adding.”
In the Assembler we represent hexadecimal numbers (hex for short)
with a 0x in front, so 0x1B is how to specify the hex number 1B.

ARM Assembly Instructions


In this section, we introduce some basic architectural elements of the ARM
processor and start to look at the form of its machine code instructions.
The ARM is what is called a RISC computer, which theoretically will make
learning Assembly easier. There are fewer instructions and each one is
simple, so the processor can execute each instruction quickly.
In the first few chapters of this book, we will cover the 64-bit standard
ARM Assembly instructions. This means that the following topics are
deferred to later chapters where they can be covered in detail without
introducing too much confusion:

• Interacting with other programming languages

• Accessing hardware devices

• Instructions for the floating-point processor

• Instructions for the NEON processor

In technical computer topics, there are often chicken and egg


problems in presenting the material. The purpose of this section is
to introduce all the terms and ideas we will use later. Hopefully, this
introduces all the terms, so they are familiar when we cover them in full
detail.

11
Chapter 1 Getting Started

CPU Registers
In all computers, data is not operated in the computer’s memory; instead
it’s loaded into a CPU register, then the data processing or arithmetic
operation is performed in the registers. The registers are part of the
CPU circuitry allowing instant access, whereas memory is a separate
component and there is a transfer time for the CPU to access it.
The ARM processor is based on a load-store architecture where there
are two basic types of instructions:

1. Instructions that either load memory into registers


or instructions that store data from registers into
memory

2. Instructions that perform arithmetical or logical


operations between two registers

If you want to add two numbers, you might do the following:

1. Load one into one register and the other into


another register.

2. Perform the add operation putting the result into a


third register.

3. Copy the answer from the results register into


memory.

As you can see, it takes quite a few instructions to perform simple


operations.
A 64-bit program on an ARM processor in user mode has access to 31
general-purpose registers, a program counter (PC), and a combination
zero register/stack pointer:

• X0–X30: These 31 registers are general purpose; you


can use them for anything you like, though some have
standard agreed-upon usage that we will cover later.

12
Chapter 1 Getting Started

• SP, XZR: The stack pointer or zero register depending


on the context.

• X30, LR: The link register. If you call a function, this


register will be used to hold the return address. As this
is a common operation, you should avoid using this
register for other things.

• PC: The program counter. The memory address of the


currently executing instruction.

We don’t always need the full 64 bits of data in a register. Often 32 bits
is fine. All the X registers can be operated on as 32-bit registers by referring
to them as W0–W30 and WZR. When we do this, the instruction will use
the lower 32 bits of the register and set the upper 32 bits to zero. Using 32
bits saves memory, since you only use 4 bytes rather than 8 bytes for each
quantity saved. Most loop counters and other common variables used in
programming easily fit in 4 bytes, so this is made easy by the processor.
There are a large set of registers for the coprocessors, but we’ll cover
these when we get to programming these coprocessors in Chapter 12,
“Floating-Point Operations,” and Chapter 13, “Neon Coprocessor.”

ARM Instruction Format


Each ARM binary instruction is 32 bits long. Fitting all the information
for an instruction into 32 bits is quite an accomplishment requiring using
every bit to tell the processor what to do. There are quite a few instruction
formats, and it can be helpful to know how the bits for each instruction are
packed into 32 bits. Since there are 32 registers (the 31 general-purpose
registers plus the stack pointer (SP)/zero register (XZR)), it takes 5 bits to
specify a register. Thus, if you need three registers, then 15 bits is taken up
specifying these.

13
Chapter 1 Getting Started

Having small fixed length instructions allows the ARM processor to


load multiple instructions quickly. It doesn’t need to start decoding an
instruction to know how long it is and hence where the next instruction
starts. This is a key feature to allowing processing parallelism and
efficiency.
Each instruction that takes registers can either use the 32-bit W version
or the 64-bit Z version. To specify which is the case, the high bit of each
instruction specifies how we are viewing the registers.

Note All the registers in a single instruction need to be the same—


you can’t mix W and Z registers.

To give you an idea for data processing instructions, let’s consider the
format for a common class of instructions that we’ll deal with early on.
Figure 1-3 shows the format of the instruction and what the bits specify.

Figure 1-3. Instruction format for data processing instructions

Let’s look at each of these fields:

• Bits: If this bit is zero, then any registers are interpreted


as the 32-bit W version. If this bit is one, then they are
the full 64-bit X version of the register.

• Opcode: Which instruction are we performing, like


ADD or MUL.

• Shift: These two bits specify shifting operations that


could be applied to the data.

14
Chapter 1 Getting Started

• Set condition code: This is a single bit indicating if


this instruction should update any condition flags. If
we don’t want the result of this instruction to affect
following branch instructions, we would set it to 0.
• Rm, Rn: Operand registers to use as input.

• Rd (destination register): Where to put the result of


whatever this instruction does.

• Imm6: An immediate operand which is usually a


small bit of data that you can specify directly in the
instruction. So, if you want to add 1 to a register, you
could have this as 1, rather than putting 1 in another
register and adding the two registers. These are usually
the bits left over after everything else is specified.

When things are running well, each instruction executes in one clock
cycle. An instruction in isolation takes three clock cycles, namely, one to
load the instruction from memory, one to decode the instruction, and
then one to execute the instruction. The ARM is smart and works on three
instructions at a time, each at a different step in the process, called the
instruction pipeline. If you have a linear block of instructions, they all
execute on average taking one clock cycle.
In modern ARM processors, the execution pipeline is much more
sophisticated and can be working on more than three instructions at
a time. Some instructions like integer division take longer, and if the
following instructions don’t rely on the result, then these instructions can
execute in parallel to the division process. Other instructions might stall,
for instance, when waiting for memory to be loaded, again the process
can perform other instructions that don’t depend on the result while
the memory controller fetches the memory—this is called out-of-order
execution.

15
Chapter 1 Getting Started

Computer Memory
Programs are loaded from the computer’s disk drive device into memory
and executed. The memory holds the program, along with any data or
variables associated with it. This memory isn’t as fast as the CPU registers,
but it’s much faster than accessing data stored on an SSD drive or CF card.
We’ve talked a lot about 64-bit mode, but what is it? What 64-bit mode
really means is

• Memory addresses are specified using 64 bits.

• The CPU registers are each 64 bits wide and perform


64-bit integer arithmetic.

Instructions are 32 bits in size. The intent is to keep these as small as


possible, so the ARM processor can execute them quickly and efficiently.
This is true when the ARM processor runs in either 32-bit or 64-bit mode.
If we want to load a register from a known 64-bit memory address,
for example, a variable we will use in a computation, how do we do this?
The instruction is only 32 bits in size, and we’ve already used 8 bits for the
opcode. We need 5 bits to specify one register, so we have left 19 bits for the
memory address (14 bits if we needed to list two registers).
This is a problem that we’ll come back to several times, since there are
multiple ways to address it. In a CISC computer, this isn’t a problem since
instructions are typically quite large and variable in length.
You can load from memory by using a register to specify the address to
load. This is called indirect memory access. But all we’ve done is move the
problem, since we don’t have a way to put the value into that register (in a
single instruction).
You could load several registers, each with part of the address,
then shift the parts around, and then add them together. This is a lot of
instructions to load an address, which seems rather inefficient.

16
Chapter 1 Getting Started

The quick way to load memory that isn’t too far away from the program
counter (PC) register is to use the load instruction via the PC, since it
allows a 12-bit offset from the register. This looks like you can efficiently
access memory within 4096 words of the PC. Yuck, how would you write
such code? This is where the GNU Assembler comes in. It lets you specify
the location symbolically and will figure out the offset for you.
In Chapter 2, “Loading and Adding,” we will look at the immediate
operand in more detail. We will cover many more ways to specify memory
addresses in future chapters, like asking Linux to give us a block of
memory, returning the address in a register for us. For now, using the PC
with an offset meets our needs.

About the GCC Assembler


Writing Assembler code in binary as 32-bit instructions would be painfully
tedious. Enter GNU Assembler which gives you the power to specify
everything that the ARM CPU can do but takes care of getting all the bits in
the right place for you. The general way you specify Assembly instructions is

label:     opcode    operands

The label: part is optional and only required if you want the instruction
to be the target of a branch instruction.
There are quite a few opcodes; each one is a short mnemonic that is
human readable and easy for the Assembler to process. They include

• ADD for addition

• LDR for load a register

• B for branch
There are quite a few different formats for the operands. We will cover
those as we cover the instructions that use them.

17
Chapter 1 Getting Started

H
 ello World
In almost every programming book, the first program is a simple program
to output the string “Hello World.” We will do the same with Assembly to
demonstrate some of the concepts we’ve been talking about. In our favorite
text editor, let’s create a file “HelloWorld.s” containing the code in Listing 1-1.

Listing 1-1. The Hello World program

//
// Assembler program to print "Hello World!"
// to stdout.
//
// X0-X2 - parameters to Linux function services
// X8 - Linux function number
//

.global _start // Provide program starting address

// Setup the parameters to print hello world


// and then call Linux to do it.
_start: mov     X0, #1     // 1 = StdOut
     ldr   X1, =helloworld // string to print
     mov   X2, #13         // length of our string
     mov   X8, #64         // Linux write system call
     svc   0               // Call Linux to output the string

// Setup the parameters to exit the program


// and then call Linux to do it.
     mov     X0, #0    // Use 0 return code
     mov     X8, #93   // Service code 93 terminates
     svc     0      // Call Linux to terminate

.data
helloworld:      .ascii  "Hello World!\n"

18
Chapter 1 Getting Started

This is our first look at a complete Assembly Language program, so there


are a few things to talk about. But, first, let’s compile and run this program.
In our text editor, create a file called “build” that contains

as -o HelloWorld.o HelloWorld.s
ld -o HelloWorld HelloWorld.o

These are the commands to compile our program. First, we must make
this file executable using the terminal command:

chmod +x build

Now, we can run it by typing ./build. If the files are correct, we can
execute our program by typing ./HelloWorld. In Figure 1-4, I used bash -x
(debug mode), so you can see the commands being executed.

Figure 1-4. Building and executing HelloWorld

19
Chapter 1 Getting Started

If we run “ls -l”, then the output is

-rw-r--r-- 1 smist08 smist08   62 qad 18 17:31 build


-rwxr-xr-x 1 smist08 smist08 1104 kax 10 16:49 HelloWorld
-rw-r--r-- 1 smist08 smist08  936 kax 10 16:49 HelloWorld.o
-rw-r--r-- 1 smist08 smist08  826 kax  5 22:32 HelloWorld.s

Notice how small these files are. The executable is only 1104 bytes, about
1 kilobyte. This is because there is no runtime, or any other libraries required
to run this program; it is entirely complete in itself. If you want to create very
small executables, Assembly Language programming is the way to go.
The format for this program is a common convention for Assembly
Language programs where each line is divided into these four columns:

• Optional statement label

• Opcode

• Operands

• Comment

These are all separated by tabs, so they line up nicely.


Yay, our first working Assembly Language program. Now, let’s talk
about all the parts.

About Comments
We start the program with a comment that states what it does. We also
document the registers used. Keeping track of which registers are doing
what becomes important as our programs get bigger.

• Whenever you see double slashes //, then everything


after the “//” is a comment. That means it is there for
documentation and is discarded by the GNU Assembler
when it processes the file.

20
Chapter 1 Getting Started

• Assembly Language is cryptic, so it’s important to


document what you are doing. Otherwise, you will
return to the program after a couple of weeks and have
no idea what the program does.
• Each section of the program has a comment stating
what it does and then each line of the program has a
comment at the end stating what it does. Everything
between a /∗ and ∗/ is also a comment and will be
ignored.

• This is the same as comments in C/C++ code. This


allows us to share some tools between C and Assembly
Language.

Where to Start
Next, we specify the starting point of our program:

• We need to define this as a global symbol, so that the


linker (the ld command in our build file) has access
to it. The Assembler marks the statement containing
_start as the program entry point; then the linker can
find it because it has been defined as a global variable.
All our programs will contain this somewhere.

• Our program can consist of multiple .s files, but only


one file can contain _start.

21
Chapter 1 Getting Started

Assembly Instructions
We only use three different Assembly Language statements in this
example:

1. MOV, which moves data into a register. In this case


we use an immediate operand, which starts with
the “#” sign. So “MOV X2, #13” means move the
number 13 into X2. In this case, the 13 is part of
the instruction and not stored somewhere else in
memory. In the source file, the operands can be
upper- or lower-case. I tend to prefer lower-­case in
my program listings.

2. “LDR X1, =helloworld” statement that loads register


X1 with the address of the string we want to print.

3. SVC 0 command that executes software interrupt


number 0. This branches to the interrupt handler in
the Linux kernel, which interprets the parameters
we’ve set in various registers and does the actual work.

Data
Next, we have .data that indicates the following instructions in the data
section of the program:

• In this we have a label “helloworld” followed by an


.ascii statement, then the string we want to print.

• The .ascii statement tells the Assembler just to put


our string in the data section; then we can access it
via the label as we do in the LDR statement. We’ll talk
later about how text is represented as numbers, the
encoding scheme here being called ASCII.

22
Chapter 1 Getting Started

• The last “\n” character is how we represent a new line.


If we don’t include this, you must press Return to see
the text in the terminal window.

C
 alling Linux
This program makes two Linux system calls to do its work. The first is the
Linux write to file command (#64). Normally, we would have to open a file
first before using this command, but when Linux runs a program, it opens
three files for it:

1. stdout (output to the screen)

2. stdin (input from the keyboard)

3. stderr (also output to the screen)

The Linux shell will redirect these when you use >, <, and | in your
commands. For any Linux system call, you put the parameters in registers
X0–X7 depending on how many parameters are needed. Then a return
code is placed in X0 (we should check this to see if an error occurred, but
we are bad and don’t do any error checking). Each system call is specified
by putting its function number in X8.
The reason we do a software interrupt rather than a branch or
subroutine call is so we can call Linux without needing to know where this
routine is in memory. This is rather clever and means we don’t need to
change any addresses in our program as Linux is updated and its routines
move around in memory. The software interrupt has another benefit of
providing a standard mechanism to switch privilege levels. We’ll discuss
Linux system calls later in Chapter 7, “Linux Operating System Services.”

23
Chapter 1 Getting Started

Reverse Engineering Our Program


We talked about how each Assembly instruction is compiled into a 32-bit
word. The Assembler did this for us, but can we see what it did? One way is
to use the objdump command line program:

objdump -s -d HellowWorld.o

which produces Listing 1-2.

Listing 1-2. Disassembly of Hello World

HelloWorld.o:     file format elf64-littleaarch64

Contents of section .text:


0000 200080d2 e1000058 a20180d2 080880d2   ......X........
0010 010000d4 000080d2 a80b80d2 010000d4  ................
0020 00000000 00000000                    ........
Contents of section .data:
0000 48656c6c 6f20576f 726c6421 0a        Hello World!.

Disassembly of section .text:

0000000000000000 <_start>:
   0:  d2800020     mov   x0, #0x1                   // #1
   4:  580000e1     ldr   x1, 20 <_start+0x20>
   8:  d28001a2     mov   x2, #0xd                   // #13
   c:  d2800808     mov   x8, #0x40                  // #64
  10:  d4000001     svc   #0x0
  14:  d2800000     mov   x0, #0x0                   // #0
  18:  d2800ba8     mov   x8, #0x5d                  // #93
  1c:  d4000001     svc   #0x0

24
Chapter 1 Getting Started

The top part of the output shows the raw data in the file including our
eight instructions, then our string to print in the .data section. The second
part is a disassembly of the executable .text section.
Let’s look at the first MOV instruction which compiled to 0xd2800020
(Figure 1-5).

Figure 1-5. Binary representation of the first MOV instruction

• The first bit is 1, meaning use the 64-bit version of the


registers, in this case X0 rather than W0.

• The third bit is 0, which means that this instruction


doesn’t set any flags that would affect conditional
instructions.

• The second bit combined with the fourth to ninth bits


make up the opcode for this MOV instruction. This is
move wide immediate, meaning it contains a 16-bit
immediate value.

• The next 2 bits of 0 indicate there is no shift operation


involved.

• The next 16 bits are the immediate value which is 1.

• The last 5 bits are the register to load. These are 0 since
we are loading register X0.

Look at the LDR instruction; it changed from

ldr   X1, =helloworld

to

ldr   x1, 20 <_start+0x20>

25
Chapter 1 Getting Started

This is the Assembler helping you with the ARM processor’s obscure
mechanism of addressing memory. It lets you specify a symbolic address,
namely, “helloworld,” and translate that into an offset from the program
counter. Here the disassembler is trying to be helpful to indicate which
memory address will be loaded, rather than the exact Assembly code.
The details are a bit more complicated, and we’ll cover them in detail in
Chapter 5, “Thanks for the Memories.”
You might notice that the raw instructions in the top part of the output
have their bytes reversed, compared to those listed in the disassembly
listing. This is because we are using a little-endian encoding, which we will
cover in the next chapter.

S
 ummary
In this chapter, we introduced the ARM processor and Assembly Language
programming along with why we want to use Assembly. We covered the
tools we will be using. We also saw how computers represent positive
integers.
We then looked at in more detail how the ARM CPU represents
Assembly instructions along with the registers it contains for processing
data. We introduced both the computer’s memory and the GNU Assembler
that will assist us in writing our Assembly Language programs.
Finally, we created a simple complete program to print “Hello World!”
in our terminal window.
In Chapter 2, “Loading and Adding,” we will look at loading data into
the CPU registers and performing basic addition. We’ll see how negative
numbers are represented and learn new techniques for manipulating
binary bits.

26
Chapter 1 Getting Started

Exercises
1. Convert the decimal number 1234 to both binary
and hexadecimal.

2. Download the source code for this book from the


GitHub site and compile the HelloWorld program
on your ARM system.

3. Change the string in HelloWorld, but remember to


change the length loaded into X2.

4. In the HelloWorld program, change the return code


loaded into X0 before the second SVC call and see
what happens.

5. Since HelloWorld is a standard Linux program


using standard Linux conventions, you can use it
with other shell commands. Try redirecting the
output to a file with “./HelloWorld > myfile.txt” and
piping the output to another Linux command such
as “./HelloWorld | grep -I wor”.

6. Estimate how many Assembly Language commands


are in a 32K executable. The Linux kernel is about
5.1MB in size. If the Linux kernel was written in
Assembly Language, how many instructions would
that be?

27
CHAPTER 2

Loading and Adding


In this chapter, we will go slowly through the MOV and ADD instructions
to lay the groundwork on how they work, especially in the way they handle
parameters (operands), so that, in the following chapters, we can proceed
at a faster pace as we encounter the rest of the ARM instruction set.
Before getting into the MOV and ADD instructions, we will discuss
the representation of negative numbers and the concepts of shifting and
rotating bits.

N
 egative Numbers
In the previous chapter, we discussed how computers represent positive
integers as binary numbers, called unsigned integers, but what about
negative numbers? Our first thought might be to make one bit represent
whether the number is positive or negative. This is simple, but it turns out
it requires extra logic to implement, since now the CPU must look at the
sign bits, then decide whether to add or subtract and in which order.
It turns out there is a simple representation of negative numbers that
works without any special cases or special logic; it is called two’s complement.

About Two’s Complement


The great mathematician John von Neumann, of the Manhattan Project,
came up with the idea of the two’s complement representation for
negative numbers, in 1945, when working on the Electronic Discrete

© Stephen Smith 2020 29


S. Smith, Programming with 64-Bit ARM Assembly Language,
https://doi.org/10.1007/978-1-4842-5881-1_2
Chapter 2 Loading and Adding

Variable Automatic Computer (EDVAC) computer—one of the earliest


electronic computers.
Two’s complement came about by observing how addition overflows.
Consider a 1-byte hexadecimal number like 01. If we add

0x01 + 0xFF = 0x100

(all binary ones) we get 0x100.


However, if we are limited to 1-byte numbers, then the 1 is lost and we
are left with 00:

0x01 + 0xFF = 0x00

The mathematical definition of a number’s negative is a number that


when added to it makes zero; therefore, mathematically, FF is -1. You can
get the two’s complement form for any number by taking

2N - number

where N is the number of bits in our integer. In our example, the two’s
complement of 1 is

28 - 1 = 256 - 1 = 255 = 0xFF

This is why it’s called two’s complement. An easier way to calculate the
two’s complement is to change all the 1s to 0s and all the 0s to 1s and then
add 1. If we do that to 1, we get

0xFE + 1 = 0xFF

Two’s complement is an interesting mathematical oddity for integers,


which are limited to having a maximum value of one less than a power of
two (which is all computer representations of integers).
Why would we want to represent negative integers this way on
computers? As it turns out, this makes addition simple for the computer
to execute. Adding signed integers is the same as adding unsigned
integers. There are no special cases, all you do is discard the overflow, and

30
Other documents randomly have
different content
whole of New Zealand what it is as yet only in parts. Those parts are
rich farm lands, with swiftly scouting motor-cars used by great
capitalist-farmers who have more than one station to look after. It is
a strange phenomenon of New Zealand life that the small farm
towns are generally much more alert and progressive than the big
cities. The New Zealanders build houses that look like transplanted
suburbs from around New York, and bring to their villages some of
the love of plant life that the city-dweller is soon too sophisticated to
share. They draw out to themselves the moving-picture theaters,
which are now the all-possessing rage in the Dominion as elsewhere,
and read the latest periodicals with the interest of the townsman.
There are over a thousand newspapers in the Dominion, which for a
population of a million is a goodly number, though one cannot
regard this as too great an indication of the intellectual advancement
of the people. Yet literacy is the possession of the farmer as much as
and frequently more than the city-dweller in New Zealand. His
children go to school even if they have to use the trains to get there;
free railway passes on these are accorded by the Government. And
on the whole the farmer's life in New Zealand is richer than that of
most rural communities. But the struggle is still great. I have seen
some who do not feel that the promise is worth it.

Post Card. J. B. Series No. 205

THE FIORDS AND SOUNDS OF NEW


ZEALAND
The pride of the Dominion
LAKE WANAKA, NEW ZEALAND

Though each of the big cities in the Dominion has its own special
characteristics, they are all considerably alike. The three chief ones
are all port cities of about 80,000 inhabitants each, and except for
the fact that Dunedin in the far south is essentially Scotch and
somewhat more stolid than the rest, and Wellington in the center is
the capital of the Dominion and therefore suspicious, one may go up
and down their steep hills without any change in one's social gears.
The colonial atmosphere is at once charming and chilling. There is a
certain sobriety throughout which makes up for lack of the luxuries
of modern life. But one cannot escape the conviction that regularity
is not all that man needs. Everything moves along at the pace of a
river at low level,—broad, spacious, serene, but without hidden
places to explore or sparkling peaks of human achievement to
emulate. One paddles down the stream of New Zealand life without
the prospect of thrills. One might be transported from Auckland in
the north to Wellington or Dunedin in the south during sleep, and
after waking set about one's tasks without realizing that a change
had been made.
Every city is well lighted; good trams (trolley-cars) convey one in
all directions, but at an excessively high fare; the water and
sewerage systems are never complained of; the theaters are good
and the shops full of things from England and America. There are
even many fine motor-cars. But there are few signs of great wealth,
though comparatively big fortunes are not unknown. It is rumored
that ostentation is never indulged in, as the attitude of the people as
a whole is averse to it.
On the other hand, neither are there any signs of extreme
poverty, though it exists; and slums to harbor it. While the usual
evils of social life obtain, the small community life makes it
impossible for them to become rampant. Every one knows every one
else and that which is taboo, if indulged in, must be carried out with
such extreme secrecy as to make it impossible for any blemish to
appear upon the face of things.
In these circumstances, one is immediately classified and
accepted or rejected, according as one is or is not acceptable.
Having recognized certain outstanding features of the gentleman in
you, the New Zealander is Briton enough to accept you without
further ado. There is in a sense a certain naïveté in his measurement
of the stranger. He is frank in questioning your position and your
integrity, but shrinks from carrying his suspicions too far. He will ask
you bluntly: "Are you what you say you are?" "Of course I am," you
say. "Then come along, mate." But he does not take you very far,
not because he is niggardly, but because he is thrifty.
As a result of this New Zealand spirit I found myself befriended
from one end of New Zealand to the other by a single family, the
elder brother having given me letters of introduction to every one of
his kin,—in Hamilton, Palmerston North, Wellington, Christchurch,
and Dunedin. And with but two or three exceptions I have always
found New Zealanders generous and open-hearted. Wherever I
went, once I broke through a certain shyness and reserve, I found
myself part of the group, though generally I did not remain long,
because I felt that new sensations could not be expected.
My one great difficulty was in keeping from falling in love with
the New Zealand girls. Rosy-cheeked, sturdy, silently game and
rebellious, they know what it is to be flirtatious. For them there is
seldom any other way out of their loneliness. Only here and there do
parents think it necessary to give their daughters any social life
outside the home. In these days of the movies, New Zealand girls
are breaking away from knitting and home ties. But even then few
girls care to preside at representations of others' love-affairs without
the opportunity of going home and practising, themselves. Hence
the streets are filled with flirtatious maidens strolling four abreast,
hoping for a chance to break into the couples and quartets of young
men who choose their own manly society in preference to that of
expensive girls. I have seen these groups pass one another, up and
down the streets, frequent the tea-houses and soda fountains, carry
on their flirtations from separate tables, pay for their own
refreshments or their own theater tickets; but real commingling of
the sexes in public life is not pronounced.
At the beaches! That is different. There the dunes and bracken
are alive with couples all hours of the day or night during the holiday
and summer seasons. Thence emerge engagements and hasty
marriages, nor can parental watchfulness guard against it.

The most difficult thing in all my New Zealand experiences was to


reconcile the latent conservatism of the people with their
outstanding progressiveness. It would be easy to assert without
much fear of contradiction that notwithstanding all the talk of
radicalism in the matter of labor legislation there is little of it in
practice in the Dominion. The reason for this is twofold. First, New
Zealand, unlike Australia and America, was not a rebellious offshoot
of England, not a protest against Old-World curtailment. Quite the
contrary, it was made in the image of the mother country, and
natural selection for the time being was dormant. Furthermore, it
was simple for labor to dominate in a country where labor was to be
had only at that premium.
Nowhere in the whole Dominion did I come across concrete
evidence of awakened consciousness on the part of the masses to
their opportunities. None of that feverish haste to raise monuments
of achievement to accompany the legislative enactments which have
given New Zealand an illustrious place among the nations. True, the
country is young; true, there are not enough people there to pile
creation on creation. But that is not it. It is that they are not keyed
up to any great notions of what they ought to expect of themselves,
but are content with what freedom and leisure of life they possess.
Throughout the length and breadth of the two islands, islands
more than two thirds the size of Japan, there isn't an outstanding
structure of any great architectural value; there isn't a statue or a
monument of artistic importance; there is hardly a painting of
exceptional quality; nor, with all the remarkable beauty of nature
which is New Zealand's, is there any poetic outpouring of love of
nature that one would expect from a people heirs to some of the
finest poetry in the world. Even British India has its Kipling and its
Tagore. With all the excellence of their efforts to solve the problem
of the welfare of the masses, New Zealanders show no excessive
largeness of heart in the sort of welcome they extend to labor of
other lands. Here, it would seem, is a land where the world may well
be reborn, where there is every opportunity for the correction of
age-long wrongs that have become too much a part of Europe for
Europeans to resent them too heartily. Yet what is New Zealand
doing and what has it done in seventy-five years to approximate
Utopia?
This is not meant as a criticism of New Zealand; rather is it
meant to let New Zealand know that the eyes of the world are upon
it and expect much from it. Possession may be nine points of the
law; but the utilization of opportunity which possession entails is the
tenth point toward the retention of that which one has.
Babies are cared for better in New Zealand than any other place
in the world, yet boys and girls still receive that antiquated form of
correction, corporal punishment, and thought of letting the youth
find his own salvation, with guidance only, not coercion, is still alien
to the New Zealand pedagogic mind. Women have had the vote for
over twenty-five years, but the freedom of woman to seek her own
development, to become a factor in the social life of the community
apart from the man's, is still a neglected dream. And young women
are dying of ennui because they aren't given enough to do. The
country is fairly rich, with its enormous droves of sheep, great
pastures full of cattle, its coöperative capitalistic farming-schemes;
but the human genius for beauty and self-expression must find
opportunity in Britain or America. And even the old romance of
pioneer life is virtually of the past. In all my wanderings I came
across only one home that made me throw out my emotional chest
to contain the spirit of the pioneer life of which we all love to hear. It
was a house as rough as it was old, laden with shelving and hung
with guns, horns, and lithographs, and cheered by a blazing open
fire,—an early virility New Zealand has now completely outgrown.
The house must have been fifty years old, to judge from the
Scotsman living there. He was keen, alert, and quick, a most
interesting opponent in discussion, most firm in his beliefs without
being offensive. Here, in the very heart of one of the earliest of New
Zealand's settlement districts in the South Island, he lived with his
family; and something of the old sweetness of life, the atmosphere
of successful conquest, obtained. And ever as I dug down into New
Zealand's past, I found it charming. The present is too steeped in
cheap machine processes to be either durable or really satisfying.
Discouraging as this may sound, he who has lived in the little
Dominion and has learned to love its people and their ways, hastens
to contradict his own charges. For in time, as one becomes better
acquainted, one finds a healthy discontent brewing beneath that
apathetic exterior. Just as the Chinese will do anything to "save face"
so the Briton will do anything not to "lose face." He loses much of
his latent charm in so restricting himself, but when assured that a
new convention is afoot and that it is safe for him to venture forth
with it, he will do so with a zest that is itself worth much.
Furthermore, there is in the atmosphere of staid New Zealand life
a passion for the out-of-doors which is worth more than all the
Greenwich Village sentiment twice over. Girls are always just as
happy in the open and more interesting than when indulging in
cigarettes and exposing shapely legs in intellectual parlors. Given
twenty million people instead of one New Zealand would blossom
forth into one of the loveliest flowers of the Pacific.

In the Auckland (New Zealand) Art Gallery hangs a picture


representing the coming of the Maories to New Zealand. Their long
canoe is filled with emaciated people vividly suggesting the suffering
and privation they must have undergone in coming across the
mainland some four hundred years ago. Venturing without sail or
compass, these daring Polynesians must have possessed intrepid
and courageous natures.
Yet at the time I was in that gallery the place was full of stifled
boyish laughter. A half-dozen little tots, with spectacles and school-
bags, one with blazing red hair, had come to see the pictures. They
were not Maori children, but the offspring of the white race, which
less than a hundred years ago came in their sailing-vessels and
steamers, with powder and lead, and took with comparative ease a
land won by such daring travail.
I had heard much of these natives,—idyllic tales of their charm
and the lure of their maidens. Those lovely Maori girls! I expected to
see them crowding the streets of Auckland. But they were
conspicuous by their absence. Occasionally a few could be seen
squatting on the sidewalks, more strangers to the city than I, more
outstanding from the display of color and manner which thronged
Queens Street than any American could be in so ultra a British
community as dominates New Zealand. Where are the Maories? I
wondered. Upon their "reservations" like our own Amerinds, or lost
to their own costumes and even to their own blood and color?
I had returned to Auckland from a visit with a friend whose wife
was Maori, in the company of her nephew. He carried with him a
basket of eels as a gift to his mother, and walked up the street with
me. At a corner he was hailed by a dark-skinned man in a well-cut
business suit, and said, "There is my father. I must leave you." In
another moment he was in a large touring car and was whizzed
away by his Maori father at the wheel. No wonder I hadn't been able
to see any Maories.
I visited a school where Maori boys are being encouraged to
artificial exercises,—sports, hurdle-jumping, running. I watched them
make ready, eager for the petty prizes offered. Off went their shoes,
out went their chests, expanded with ancestral joy. In their bare
feet, still as tough as in former days before they were induced to
buy cowhides, they skipped over the ground, filled for the moment
with the glory of being alive. Their faces broke out in fantastic,
native grimaces and contortions as though an imaginary enemy
confronted them. But alas, they were seeking him in the wrong
direction! The enemy comes with no spears, and no clang, but he is
more deadly. He is not without but within. He makes them cough.
They fall behind.
"They do not last long," said the Briton who was instructing
them. "They are dying rapidly of consumption. As long as we keep
them here in school they are all right. Finer specimens of human
physique could not be found anywhere. But as soon as they return
to their pas, and live in the squalor of the native villages, they return
to all the old methods of life and soon go under."
I set out on my tramp through New Zealand. At Bombey, a few
days' jaunt from Auckland, I met an old settler, whose accounts of
the great and last war of the redcoats with the fierce fighters of
Maoriland dated back to our own Civil War, 1861-64. Until that time
both Maories and Britons said, with few exceptions, "Our races
cannot mix. One or the other of us must give away." Naturally, the
Maories had the prior claim, but they finally yielded, surrendering
their lands to the aliens at Ngaruawahia, "The Meeting of the
Waters," that little hamlet lying in the crotch between the beautiful
Waikato River and one of its tributaries. And henceforward, the two
races were constrained to meet, and rush down together into that
green sea of human commonalty, albeit one of them contributes the
dominant volume.
Maori legend has it that the Maories are the descendants of the
great Rangatira (chief) who was the offspring of a similarly great
Tanewa (shark). He was born in the dark southern caves of the
Tongariro Mountains, and the spirits of their ancestors have always
dwelt along the broad Waikato. Along this river I wandered for many
days, but I found few of the Rangatira's descendants. If one is quiet
and alone the voice of the great Tanewa will call softly through the
marsh rushes from out of the heart of the quivering flax. It is
peaceful and encompassing, modest and almost afraid. I heard it
and I am sure those Maories hear it who are not too engrossed in
the scramble after foreign trinkets. It said: "The last mortal or man
descendant of mine will be the offspring of a Pakeha-Maori (a white
man who lives among the Maories) who will live in the cities and
rush about in motor-cars, but I shall remain in the marshes, the
calm rivers, and near the glittering leaves of flax."
A few miles farther on I came to Huntley, and hearing that there
was a native village across the Waikato River, I turned thither by way
of the bridge. I overtook two wahines, slovenly, indolent, careless in
their manners. They spoke to me flippantly. They wanted to know if
I was bound for the missionaries' place. This led to questions from
me: Why were they turning Mormon? Which sect did they prefer?
But I could obtain answers only by innuendo. I left these two
women behind and found three others chasing a pig in an open
field, three boys bathing a horse in the deep river. All about the
village was strewn refuse; vicious dogs slunk hungrily about,—
neglect, neglect, on every hand. But instead of flimsy native huts
there were wooden shacks with corrugated iron roofs, the longer to
remain unregenerate, breeders of disease and wasters of human
energy.
But the more elaborate native village at Rotorua, at the other end
of the island, where visitors are frequent, was more up-to-date and
cleaner. And on a little knoll was a model of an old Maori pah, such
as was used in the days before guns made it possible to fight in
ambush and in the valleys, and brought the sturdy savages down
not only from their more wholesome heights but from their position
of vantage as a race.
Here I met an odd sort of article in the way of human ware. Only
seventeen, he was twice my size, and lazy and pliable in proportion.
He would come into my room and just stay. With a steady, piercing,
yet stolid and almost epileptic stare, cunning, yet not shrewd, not
steady, nor guided by any evident train of thought, he would watch
me write. I was a mystery to him, and he frankly doubted the truth
of things I told him.
First he said I had the build of a prize-fighter; then, perhaps on
thinking it over, he doubted that I had ever done any hard work in
my life. As to himself, he said he loved to break in wild horses. His
father, according to one tale, was wealthy; two of his brothers were
engineers on boats. But he hated study. He was altogether lacking in
any notion of time, but he was not lazy. He was even ready to do
work that was not his to do.
One afternoon he was in a most jovial mood. He was about to
have a tent raised in which he would spend the summer, instead of
the hotel room allotted to the help. He was full of glee at the
prospect. Primitive instincts seemed to waken in him. But there was
a sudden reaction,—whimsical. We had stepped upon the lawn
which afforded an open view across Lake Rotorua.
"Strange, isn't it," he said without any preamble, "how money
goes from one man to another, from here to Auckland and to
Sydney? So much money." He became reminiscent: "Maories didn't
know a thing about money. They were rich. See, across this lake,—
that little island,—the whole was once a battle-field. The Maories
went out in their canoes and fought with their battle-axes. What for?
Oh, to gain lands. But now they are poor. Things are so dead here
now. Nothing doing." A moment later he was called and
disappeared. It was the only time he was ever communicative. The
tent had roused in him racial regrets.
One evening he came up to my door and told me there was a
dance at the hall, and that he was going to it. Again that strange
revival of racial memories, but these of hope and prospect, came
into his face, "I'm going to take my 'tart' (girl) with me," he
announced. And later in the evening, as I sat alone, watching the
moon rise over the lake, the laughter of those Maories rang out
across the hills.
Though I wandered for many miles, running into the hundreds,
the number of Maori villages and people I came across were few and
far between. Yet records show that once these regions were alive
with more than a hundred thousand fighting natives. At Rotorua, the
hot-springs district in the North Island, the pah was in exceptionally
good condition, but it was so largely because the New Zealand
Government has made of the place one of its most attractive tourist
resorts and the natives are permitted to exact a tax from every
visitor who wishes to see the geysers. Elsewhere the villages are
dull, dreary, and neglected: the farther away from civilization, the
worse they get. The consequence is not surprising.
According to the census of 1896, there were 39,854 people of
the Maori race: 21,673 males, 18,181 females, of which 3,503 were
half-castes who lived as Maories, and 229 Maori women married to
Europeans. The Maori population fell from 41,993 in 1891 to 39,854
in 1896, a decrease in five years of 2,139. But in 1901 it had risen to
43,143, going steadily up to 49,844 in 1911, and dropping to 49,776
in 1916 on account of the European war.
There was considerable discussion in the New Zealand Parliament
on the question of whether the Maories should be included in the
Draft Act, most white men declaring that a race which was dying,
despite this seeming increase, should not be taxed for its sturdiest
young men in a war that was in truth none of its concern. But the
Maories—that is, their representatives—objected, saying they did not
wish to be discriminated against. Among the young men, however, I
found not a few who were inclined to reason otherwise. So it was
that while I was talking to the young fellows who were washing their
horse in the Waikato, one of them said to me:
"Yes. Years ago the white men came to us with guns and cannon
and powder and compelled us to give up our warfare, which kept us
in good condition individually and as a race. We put aside our
weapons. Now they come to us and tell us we must go to Europe
and fight for them." And he became silent and thoughtful.
As I came back into Huntly from my visit to the pah I passed the
little court-house, before which was a crowd of Maories. Some of the
wahines sat with shawls over their heads smoking their pipes as
though they were in trousers, not skirts. I chatted with the British
Bobby who stood at the door, asking him what was bestirring
Maoriland so much.
"Oh, that bally old king of theirs has been subpoenaed to answer
for his brother. The blighter has been keeping him out of sight so
that he won't be taken in the draft."
"But," I protested—democrat though I was, my heart went out to
the old "monarch"—"can't the king get his brother, the archduke and
possible successor to the throne, out of performing a task that might
hazard the foundation of the imperial line?"
"King be damned! Wait till we get the blighter in here," said the
servant of the law, pressing his heels into the soft, oozy tar
pavement as he turned scornfully from me.
5

A few days later I was cutting my way through a luxuriant


mountain forest above Te Horoto in the North Island, listening to the
melodious tui, the bell-bird, and to the song of the parson-bird in his
black frock of feathers with a small tuft of white under his beak, like
the reversed collar of a cleric. No sound of bird in any of the many
countries I have been to has ever filled me with greater rapture than
did this. There are thousands of skylarks in New Zealand, brought
from England, but had Shelley heard the tui he might have written
an ode more beautiful even than that to the "blithe spirit" he has
immortalized. Yet, like the human natives, these feathery folk have
vastly decreased since the coming of the white man. No wonder Pehi
Hetan Turoa, great chief of a far country on the other side of the
island, in complaining of the decay of his race, said: "Formerly, when
we went into a forest, and stood under a tree, we could not hear
ourselves speak for the noise of the birds—every tree was full of
them.... Now, many of the birds have died out."
Enraptured with the loveliness of the native bush and the clear,
sweet air, I pressed up the mountain side with great strides.
Presently I passed a simple Maori habitation. It was about noon.
Seeing smoke rise out of an opening in the roof, indicating that the
owners were at home, I entered the yard. My eyes, full of the bright,
clear sunlight, could not discern any living thing as I poked my head
in at the door, but I could hear a voice bidding me enter. I stepped
into a sort of antechamber, a large section of the hut with a floor of
beaten earth and a single pillar slightly off the center supporting the
roof. Gradually, as my eyes became accustomed to the subdued
light, I saw an aged couple within a small alcove on the farther side.
An open fire crackled in the center of its floor. The old woman sitting
on her bed-space, was bending over the flame, fanning it to life. The
old man, who was very tall, lay on a mat-bed to the right, his legs
stretched in my direction. The two beds, the fire, and the old couple
took up the entire space of the alcove,—a sort of kitchenette-
bedroom affair like our modern "studio" apartments.
"Where are you from?" asked the old man, after I had seated
myself before the fire. "America," I said. My reply evoked no great
surprise in him.
"The village is quiet," I said. "Where are the people?"
"Oh, down in the valley, working in the fields."
"Don't you go out, too?" I asked.
"Oh, I'm too old now. My legs ache with rheumatism. I go no
more. Let the young fellows work. Stay and have tea with us," he
urged.
I looked at their stock. They did not seem to have any too much
themselves, and the old woman seemed a little worried. I knew that
the heart of the hostess was the same the world over, so I assured
them I had had my meal, and only wished to rest a while away from
the sun. The old woman showed relief.
We chatted as cordially as it is possible where tongues cannot
fully make themselves understood. I learned that the man was an
old chief. He could not fall in with the times, acknowledged his
inability to direct the affairs of this strange world, and only asked for
rest and quiet, and the respect due one of his position. He did not
expect to live long, nor did he much care. "These are not days for
me," he said with a smile. He did not speak of the former glories of
his race. Doubtless he could not exactly make up his mind whether
to look before or after: if there were great chiefs before, are there
not big M.P.'s now?
The fire was burning low, and I knew that the old woman would
have to go for more wood unless she hurried with the preparation of
her meal, and that as long as I was there I was delaying her. So I
rose to go. The old man excused himself for not rising by pointing to
his lame legs. She saw me to the gate, and as I struck down the
road she waved her hand after me in farewell, and remained behind
the screen of trees round which I veered.
Down in the valley lying almost precipitately below me were a
number of natives working in their fields; but my road led me on to
the cities, and it is there that the future of this race hangs in the
balance.
Some months later, while I was living in Dunedin in the far south
of the South Island, the newspapers came out in a way almost
American, so exciting was the bit of news. The editorial world forgot
all decorum and dignity and pulled out the largest type it had on
hand. It was announced that the Maori priest, Rua, was caught.
Several persons were wounded and one, I believe, was killed in the
process. The priest was treated with no respect and little
consideration and thrown into prison,—all because he believed in
having several wives as his men-folk always had, if they were chiefs
and priests, and was trying to put a little life into his race, trying to
stir it up to casting out these "foreign devils." He had built himself a
temple that was an interesting work of art, but it holds worshipers
no more, even though the priest has since been released. His efforts
to rouse his people failed. Such efforts are only the reflex action of a
dying race.

CHAPTER VII

ASTRIDE THE EQUATOR


The Second Side of The Triangle

Dark is the way of the Eternal as mirrored in this world of Time:


God's way is in the sea, and His path in the great deep.—Carlyle.
1

More than a year went by before I began drawing in the radial


thread that held me suspended from the North Star under the
Southern Cross,—a year replete with lone wanderings and searching
reflections. During all those months not a single day had passed
without my surveying in my mind's eye the reaches of the Pacific
that lay between me and the Orient. Roundabout New Zealand I had
become familiar with the Tasman Sea looking toward Australia, on
the shores of which I had spent some of the most mysterious nights
of my life; on Hawkes Bay looking out toward South America; and
across the surging waters of Otago Harbor at Dunedin, looking in the
direction of the frozen reaches of Antarctica.

THE S. S. AURORA
Just arrived at Port Chalmers, N. Z., from
the South Pole
MOUNT COOK OF THE NEW ZEALAND
ALPS IN SUMMER

Once staid Dunedin was thrilled by a wireless S.O.S. from the


direction of the South Pole. The Aurora, Shackleton's ship which had
gone down to the polar regions, was calling for help. She had
snapped the cables which tied her to land when the ice-packs gave
way and had drifted out to sea. Fortunately, most of the officers and
crew were at the moment on board, but sixteen men were left
marooned. To add to the prospect of tragedy, the ice smashed the
rudder, and a jury-rudder, worked by hand from the stern deck, had
to be improvised. With these handicaps the vessel made her way
slowly till within five hundred miles of New Zealand, the reach of her
wireless. Here she was rescued by a Dunedin tug and brought to
Port Chalmers.

CIRCULAR QUAY, SYDNEY, AUSTRALIA


A whirl of pleasure-seeking and business
MONUMENT TO CAPTAIN COOK
At Botany Bay, Australia

I made friends with the mate and the chief engineer and gained
access to their superb collection of Emperor Penguin skins and an
unusual number of photographs. Months afterward they wanted four
men to complete the crew necessary for another journey south and I
was tempted to join them, but tallow and bladder and a repressed
pen were the negatives, while China and Japan were the positives.
So I sailed away with the rising sun in the direction of the great
West that is the Far East. Crisp and clear in the bright morning air
shone the towering peaks of the New Zealand Alps as I sailed
toward Australia and to Botany Bay,—not, however, without being
nearly wrecked in the fog which had gathered in Foveaux Strait,
which separates Steward Island from the South Island in New
Zealand. Bluff, the last little town in New Zealand, is said to have the
most southerly hotel in the world. I saw it.

Four days from Bluff to Melbourne on a sea that seemed on the


verge of congealing into ice. It was not cold, yet autumn-like. And
the passengers seemed the fallen leaves. The stewards maintained
the reputation for impudence and unmannerliness of the Union
Steamship Company crews, but I had grown used to that, and
thanked my stars that this was the last coupon in the ticket I had
purchased in Honolulu more than a year before. Of human incidents
there was therefore none to relate.
But chill and melancholy as that Southern sea was, there hovered
over it a creature whose call upon one's interest was more than
compensating. Swooping with giant wings in careless ease, the
albatross followed us day in and day out. Always on the wing, awake
or asleep, in sunshine or in storm, the air his home as the water is to
fish, and earth to mammal. Even the ship was no lure for him by
way of support. He followed it, accepted whatever was thrown from
it, but as for dependence upon it,—no such weakness, you may be
sure. His sixteen feet of wing-spread moved like a ship upon the
waves, like a combination of a ship and sails. Swift, huge, glorious,
unconsciously majestic, he is indeed a bird of good omen. How he
floats with never a sign of effort! How he glides atop the waves,
skims them, yet is never reached by their flame-like leapings;
simulates their motion without the exhaustion into which they sink
incessantly.
The albatross had left us, and now the swarming is his artistry,
so refined his "table manners." He does not gorge himself as does
the sea-gull, nor is he ever heard to screech that selfish, hungry,
insatiable screech. Silent, sadly voiceless, rhythmic and symbolic
without being restrained by pride of art, he exemplifies right living.
He is our link between shores, the one dream of reality on an ocean
of opiate loveliness wherein there is little of earth's confusion and
pain. For the traveler he keeps the balance between the deadly
stability of land life and the dream-like mystery of the sea. But for
him it were impossible to come so easily out of an experience of a
long voyage. Away down there he is the only reminder of reality.
Which explains the reverence sailors have for him and their
superstitious dread of killing him. It is like the dread of the physician
that his knife may too sharply stir the numbed senses of his patient
under anæsthesia.
Land may be said to begin where the albatross is seen to depart.
He knows, and off he swoops, ship or no ship to follow and to guide;
back over the thousand miles of watery waste, to measure the
infinite with his sixteen-foot wings, glide by glide, with the speed of
a twin-screw turbine. Only when the female enters the breeding
season does she seek out a lost island to rear her young.
Independent of the sea, these birds are utterly confined to it, a
mystery floating within mystery.
The albatross have left us, and now the swarming gulls abound.
Why they are dignified with the Christian name "Sea" when they are
such homely land-lubbers, is a question that I cannot answer. Pilots,
rather, they come to see us into the harbor, or, with their harsh
screeching, to frighten us away.
But something within me would not know Australia, nor any
lands, just then. Perhaps it was that my unconscious self was still
with the albatross; for strange as it may seem I could not sense any
forward direction at all that day, but only one that pointed backward,
—toward home. Try as I would to realize myself on my way to
Australia, still my mind persisted in pointing toward America. Not
until we got the first sight of land ahead was my soul set right. Then
it was the Sister Islands, Wilson's Promontory, the Bass Straits, with
Tasmania barely in sight, Cape Liptrap, and finally Port Phillip. And
Australia was on all fours, veiled in blue,—a thin rind of earth
steeped in summer splendor.
Flag signals were exchanged with the lonely pilot-ship that hung
about the entrance. All being well, we passed on, crossing that point
at the entrance where five strong water-currents meet and vanquish
one another, turning into a smooth, glassy coat of treachery. The
Wimmera hugged the right shore of the largest harbor I have ever
seen. In places the other shore could not be seen with the naked
eye. But it is very shallow and innumerable lights float in double file
to guard all ships from being stranded.
Just as we entered, the sun set. A stream of color unconstrained
obliterated all detail as it poured over the point of the harbor, filling
the spacious port. Clots of amber and orange gathered and were
dissipated, softened, diffused, till slowly all died down and were
gone. Darkness and the blinking lights of the buoys remained.
Two big ships, brilliantly lighted, flinging their manes of smoke to
the winds, passed, one on its way to Sydney, the other to Tasmania
and Adelaide in the south. Far in the distance ahead we could see
the string of shore lights at Port Williamson. It took us three hours to
overtake them, and we arrived too late to receive pratique. For half
an hour the captain and the customs carried on a conversation with
blinking lights. The winches suddenly began their rasping sound, and
the anchor dropped to the bottom. We did not debark that night.

I spent nearly six months in Melbourne and Sydney, those two


eastern eyes of that wild old continent, and for the first time in a
twelvemonth the sense of security from the sea obtained. For a
fortnight I occupied a little shack on Manly Beach, near Sydney, but
oh, how different it was there from the sand-dunes on the shores at
Dunedin, in New Zealand! In the Dominion one had to hide within
the interior to get away from the sea: on the beach one felt about to
slip into Neptune's maw. But at Manly, Bondi, Botany Bay, the sea
might hammer away for another eternity without putting a
landlubber off his ease.
But we shall return to Australia in another section. The sea is still
much in the blood, there is still a vast length that lies close to Asia
and marks off another line of our imaginary triangle. Here are no
landless reaches, but all the way to Japan one passes strip after
strip, as though some giant earthquake had shattered part of the
main.
Months afterward I took passage once more, this time on the
Eastern, bound for Japan.
There was no mistaking the side of the world I was on and the
direction of my journey from the moment I stepped upon the pier to
which the Eastern was made fast. Hundreds of Chinese, with
thousands of boxes and bundles, scurried to and fro in an ant-like
attention to little details. Then as the steamer was about to depart,
mobilization for the counting of noses took place, and veritable
regiments of emaciated yellow men lined the decks. Here and there
a fat, successful-looking Chinese moved round the crowd, an
altogether different-looking species, more as one who lives on them
than as one who lives with them. On the dock stood several groups
waiting to wave farewell to their Oriental kin. One of these groups
was composed of a stout white woman with two very pretty Eurasian
daughters,—as handsome a pair of girls as I saw in Australia. Their
father was a well-to-do Chinese merchant taking one of his regular
trips to China. In Australian fashion they were ready for a mild
flirtation, spoke Australian English with Australian slang, and, aside
from their pater, they were native to all intents and purposes. And in
Australia they remained.
Of those who departed, the major number likewise remained
native—though to China—despite years and years of residence in
Australia. It is a one-sided argument to maintain that because of
that the Chinese are unassimilable. There is no ground for such a
deduction, because they arrived mainly after maturity, and the
Chinese could challenge any white man to become one of them after
he has fully acquired his habits and prejudices. But we had not been
many minutes at sea before it was our misfortune to find that we
had among us a Chinese boy who was born and brought up in New
Zealand and was just then going to China for the first time. Here I
had ample opportunity of observing the assimilability of the Oriental.
And here I bow before the inevitable.
He had assimilated every obnoxious characteristic of our
civilization, the passion for slang, the impertinence, the false pride,
the bluff which is the basis of Western crowd psychology. He was
not a Chinese,—that he denied most vehemently,—he was a New
Zealander, and by virtue of his birth he assumed the right to impose
his boyish larrikinism upon all the ship's unfortunate passengers. He
banged the piano morning, noon, and night; he affected long,
straight black hair, which was constantly getting in his way and being
brushed carefully back over his head; and he took great pains to
make himself as generally obnoxious as possible. He was not that
serious, struggling Chinese student who comes to America afire with
hope for the regeneration of his race. He was a New Zealander,
knew no other affiliations, had no aspirations, and lorded it over
"those Chinese" who occupied every bit of available space on the
steamer.
In his way he was also a Don Juan, for he hovered over the
young half-Australian wife of a middle-aged Chinese merchant who
was taking her back to China for her confinement. She was morose,
sullen, as unhappy a spirit as I have seen in an Oriental body.
Obviously, China held few fine prospects for her. She was seldom
seen in her husband's company, for he was generally below playing
fan-tan or gambling in some other fashion. And the Australian half of
her was longing for home. It seemed to devolve upon our young
Don Juan to court this unhappy creature, and court her he did. But
she had no resilience, no flash, her Chinese half-self offering him as
little reward for his pains as a cow would offer the sun for a brilliant
setting.
I expected any hour of the day to see that woman throw herself
into the sea, or that husband stick a knife into the bold, bad boy, but
nothing happened; the husband and the wife were seemingly
oblivious of the love-making, and all went well.
Besides the Chinese crew and passengers there were perhaps a
dozen white people, including the officers. An old English army
captain whose passport confirmed his declaration that he was
seventy-three years old, was taking a little run up to Japan. His only
reason was that Japan was an ally, hence he wanted to see it. Such
is the nature of British provincialism. Otherwise, there were but two
or three young Australians bound for Townsville, and the stewardess.
Somewhere along the coast we picked up a Russian peasant, who
with his wife had been induced to emigrate to Australia, but who
was now going home to enlist. As though there weren't already
enough men in Russia armed with sticks and stones! At still another
port we commandeered a veritable regiment of Australian children,
colloquially called larrikins. These were bound for the Philippines,
where their father had preceded them some months before. Their
exploits deserve an exclusive paragraph.
Suddenly, out of a clear sky, there would be a shriek like the howl
of a dingo on the Australian plains. There would be a rush to the
defenses by an excited female,—the mother. There would follow
such a slapping as would delight the English Corporal Correction
League, except that it wasn't done cold-bloodedly enough. And
thereafter for half an hour there was bedlam all around. After
exhaustion, a new series of pranks set in. This time they were
playing a "back-blocks" game which entailed a hanging. One of them
needs must be hanged, and was rescued just in time by an ever-
swooping mother. After hours of hunger-stimulating escapades on
deck, the dinner-bell sent them scurrying down into the saloon.
Before any of us had time to be seated all the fruit on the table was
divided according to the best principles of individual enterprise.
Beginning with the first thing on the menu, they went down the
sheet, leaving nothing untasted; nor did it matter much whether it
was breakfast or dinner,—steak enough for a meal in itself comprised
the entrée. And the littlest kept pace with the biggest. Nor did
afternoon and morning tea escape them. Fully stoked up, they were
ready for another beating and another hanging on deck.
In contrast were the little Chinese children,—quiet, shy, never
spanked; and though they put away enough within their Oriental
bread-baskets, one never saw that same wild struggle for existence
which told the tale of life on an Australian station better than
anything I wot of.
We had now reached Brisbane, 519 miles from Sydney, a
distance which took the Eastern from noon of the 8th to sunrise of
the 10th of October to negotiate. And from the outer channel to the
docks on the Brisbane River we steamed till half-past one in the
afternoon. Here we were "beached" in the mud when the tide went
out and had to wait twenty-four hours before floating out again. In
the meantime we picked up two more gems,—mature larrikin this
time. One of them was so drunk he couldn't see straight, the other
was sober enough to bring him on board. Unfortunately for me, they
were placed in my cabin, and from then on, after the youngsters had
turned the day into chaos, these two would come in to sleep, and
the cursing, the spitting, the reference to women with which they
consoled their souls, would have shocked the most hardened beach-
comber, I am sure.
To avoid annoyances I explored every nook and corner of the
vessel. At last I discovered a sanctuary on the roof of the unused
hospital. It could not be called a model of order and comfort, for
various air-tanks and stores of sprouting potatoes belittered it. But it
was like the holy of holies to me, for there I might just as well have
been on a lone craft of my own. No sound reached me from any
living thing,—except an occasional extra-loud shriek from the
youngsters. Above and about me there was nothing to obstruct my
view, and within, absolute peace.
On the following day we were on the Great Barrier Reef, grayish
green in color, languid in temperament, shallow and therefore
dangerous in make-up. Numerous islands, neutral in color and sterile
of vegetation, seemed to stare at us and at one another in mute
indifference. For the first time the storied reality of being stranded
on a desolate island came home to me. As I sat watching this filmy
show, I became conscious of a familiar something in the world about
me, be it warmth or color, a something which immediately brought
the picture of Santa Anna Valley in California back to mind.
Sometimes we come across a face we feel certain we have seen
before: that was the case with the atmosphere along the Great
Barrier Reef. The setting is that of the island home of Paul and
Virginia. Near and far, lowly and majestic, in generous succession on
each side, were islands and continent,—an avenue wide, spacious,
and clear. Occasional peaks along the mainland recalled old-
fashioned etchings,—dense clouds, heaven-reaching streaks and
shafts of twice-blended astral blue; rain-driven mountain fiords.
Early one day, an hour before dawn, the Eastern moored before
Magneta Isle with her stern toward Townsville, as though ready for
instant flight, if necessary. With an early-morning shower of filthy
words, one of my cabin-mates pulled himself together and dressed.
Shortly afterward he slipped over the side of the ship into a tossing
and pitching launch and was rushed to Townsville. His rousing me at
that hour was the only thing I had reason to be grateful to him for in
our short acquaintance.
For the world was exquisitely beautiful in its delicate gown of
night. Dawn was but waking. Four-o'clock stupor superintended the
easy activities. A few lights in a corner, a bolder and more purposeful
flash from a search-light, and all set in twilight. A ring of islands—
the Palm Isles—stones set in a placid bay. That was all I saw of
Townsville.
And perhaps it is just as well. It may have been "ordained" that
my ignorance obtain, be the city's virtues and its right to fame what
they may. What if I had gathered closer impressions, added
meaningless statistics or announced the prevalence of diphtheria
throughout Queensland, or discovered the leading citizen of
Townsville to an apathetic world? But it may be of interest to hear
that Townsville claims one distinction. It is the Episcopal See of
Australia and the seat of the Anglican Bishop and possesses a
cathedral.

4
On the afternoon of the following day a heavy wind or squall
came up. This time the ship did not defy it. No foolhardy resistance
here. The reefs are too near and they stretch for thirty miles
seaward. Again we anchored. The horizon contracted like a noose of
mist; it stifled one. The ship seemed to crouch beneath the winds.
An hour, and the anchor was heard being lifted and the propellers
were slowly revived to action. A little later we anchored again. A
light was hoisted to the stern mast and twilight lowered on a calm
gray sea. Distant little flat islands loomed through the mist. Two
sailing-vessels at anchor, moored in companionship, rested within an
inlet. A gentle swish, a murmur of human voices, and our little world
was swaying gently upon a curious world. And there we remained all
night.
As the sun gave notice of day, we moved off, and all day the sea
was so still that but for the vibration of the screws it would have
been hard to realize that the ship was in motion. Here we came to
where the jagged coastline has run down. Tiny islets, flat and low,
most of them but a landing-place for a few tropical trees. Summer
calm, with barely a ripple of the sea. That night we anchored again,
having come, it was said, to the most dangerous pass on the reefs.
Ten days after having left Sydney we arrived at the last port in
Australia, Thursday Island. A cloudy morning had turned clear for us,
but on ahead to the northwest hung heavy mists. Because of these,
I was later told by two soldiers on guard atop the mountain
fortification, they could not see us coming. They saw our smoke, but
the steamer was hidden from them by mist. Then suddenly we shot
into view. All the while we had been in the clearest sunshine, the sea
glassy and the flying-fish darting about. It was no place for speed.
We moved just fast enough to leave the scene undisturbed. And
thus we stole into Torres Straits.
Of all the numerous harbors I have entered in the Pacific, none,
with the exception of the Inland Sea in Japan, is more picturesque
than that at Thursday Island. Shelter, space, and depth, and
stillness! One's eyes sweep round this pearly promise with greed for
its beauty. Seventy-five sail-boats, their sailless masts swaying with
the swells, are anchored on the reefs. It is Sunday and they are at
rest, but what enchantment lies hid in those folded sails! I wish for
the power to utter some word which could put them to flight; but
that remains for Monday, when "the word" is spoken.
And on Monday, too, immediately upon leaving port at ten
o'clock, the ship's time was returned to standard time, leaving
Australia and its "bunkum" daylight-saving time behind. Thence we
lived again by "dinkum" time. The ship about-faced and left the
channel the same way it had entered, and shortly afterward we
struck across the Arafua Sea.

From that day until I reached Japan it was all I could do to keep
track of the seas we passed through,—Arafua, Banda, Molucca,
Celebes, Sulu, China, and the Inland Sea.
As we neared the equator again, there was nothing to disturb the
peaceful splendor of life, except the little hoodlums on board. About
sixty miles south of it a tiny creature, like a turtle, sailed along the
still surface; the flying-fish blistered the water, the scars broadened
and healed again just as the sportive amphibians pierced it and
disappeared. What a contrast to the albatross!
Then the miracle occurred. From the west, hidden from me by
the ship, the sun reached to the eastern clouds, dashing them with
pink and bronze and blue. I could not tell where the horizon went to,
and was roused to curiosity as to what kind of sunset could effect
such lovely tints. It wasn't a sunset, but a sunfall, a revelation.
Where suggestion through imitation glistened on the eastern side,
daring prodigality of color swept away emotion on the western side.
It was neither saddening nor joyous. It was a vision of a
consciousness in nature as full of character, as definitely meaningful
and emotional as a human face. There was something almost
terrifying in the expression of that sunset face. One could read into it
what one felt in one's own soul. And a little later a crescent moon
peeped over the horizon.
At about midnight of the seventeenth day after leaving Sydney
we crawled over the equator, and no home-coming ever meant more
to me than seeing the dipper again and the Northern stars. During
all those days nothing wildly exciting had happened at sea; but just
after we left the equator we passed a series of water-spouts—six in
all—which formed a semi-circle east, south, and west. The spout to
the east seemed to me to be at least two or three hundred feet
high, and tremendous in circumference. It drew a solid column of
water from the sea far into a heavy black cloud. On the sea beneath
it rose a flutter of water fully fifty feet high, black as the smoke
produced by a magician's wand. Weird and illusive, the giants
beggared description as they stalked away to the southeast, like
animated sky-scrapers.
Then we reached Zamboanga, the little town on the island of
Mindanao of the Philippines. From there, for twelve hours, we crept
long the coast till we entered Manila Harbor.
There remained but two days' voyage before I would reach Asia,
the object of my interest for years, and of all my efforts for two. But
it was not so easy as all that, for two days upon the China Sea are
worth a year upon the Atlantic. Riding a cyclone would be riding a
hobby-horse or a camel compared with the Yellow Sea, and though I
was the only passenger who missed only one meal during the whole
period, I was beaten by the seventy-three-year-old English captain,
—who managed all but half a meal. The sea would roll skyward as
though it were striving to stand on end and for a moment the ship
would lurch downward as though on a loop-the-loop. Sometimes it
seemed as though the world were turning completely over. Yet I was
told this was only normal, and that typhoons visit it with stated
regularity. The China Sea is "the very metropolis of typhoons."
A month had well-nigh gone before we reached Hong-Kong, the
British portal to Cathay, a month of dreamy weather. Only one thing
more,—a thing more like a scene in the Arabian Nights. Toward the
end of the journey I discovered where the five hundred Chinese
whose noses had been counted when we left Sydney had gone.
Going forward, I looked over into an open hatchway, down into the
hold, and there was a sight I shall never forget. These hundreds of
deck passengers were all in a muddle amid cargo, parcels, hundreds
of birds in cages, parrots, a kangaroo,—yet oblivious of everything.
For the entire voyage nothing that I tell of could possibly have come
within their ken, as during those days their minds were bent on one
thing and one alone,—on playing fan-tan. There in the bottom of the
hold hundreds of gold sovereigns passed from hand to hand in a
game of chance. And at last they were to be released, to spread, a
handful of sand thrown back upon the beach.
As for myself, with my arrival at Hong-Kong and a visit to
Shanghai ended the longest continuous voyage I had made upon the
Pacific, and the second side of that great Pacific Triangle was drawn.
But meanwhile let me review in detail the outposts of the white man
in the far Pacific—the lands I had passed on the white man's side of
the triangle, ending in Hong-Kong, where white man and Oriental
meet.

CHAPTER VIII

THE AUSTRALIAN OUTLANDS

1
In the normal course of human variation, there should have been
virtually no change of experience for me in going from New Zealand
to Australia, notwithstanding the twelve hundred miles of sea that
separate them. And though the sea is hardly responsible, there was
a difference between these two offshoots of the "same" race for
which distance offers little explanation. To me it seemed that
regardless of the pride of race which encourages people to vaunt
their homogeneity, the way these two counterparts of Britain have
developed proves that homogeneity exists in wish more than in fact.
It seems to me that the New Zealander has developed as though he
were more closely related to the insular Anglo-Saxon, and the
Australian as though he were the continental strain in the
Englishman cropping out in a new and vast continent. However, this
is sheer conjecture. All I can do is to offer in the form of my own
observations reasons for the faith that is in me.
From the moment that I set foot in Australia I felt once again on
a continent. Melbourne is low, flat, and gave me the impression of
roominess which New Zealand cities never gave. They, with the
exception of Christchurch on the Canterbury plains, always
clambered up bare brown hills and hardly kept from slipping down
into the sea. But in Australia I felt certain that if I set out in any
direction except east I could walk until my hair grew gray without
ever coming across a mountain. It was a great satisfaction to me
that first day, for it was intensely hot and I had a heavy coat on my
arm and two cameras and no helmet. Added to my difficulties was
the cordiality of an Australian fellow-passenger who was determined
that I should share with him his delight at home-coming. He was a
short, stout, olive-skinned young man of about twenty-three who
had a slightly German swing in his gait and accentuated his every
statement with a diagonal cut outward of his right hand, palm down.
ONE OF THE OLDEST AUSTRALIAN
RESIDENCES IS NOW A PUBLIC DOMAIN

THE INTERIOR OF A WEALTHY SHEEP


STATION OWNER'S HOME IN
MELBOURNE

He lured me from one end of Melbourne to the other, made me


lunch with him at a vegetarian restaurant,—which is a very popular
resort in Melbourne,—introduced me to Cole's Book Arcade, to the
Blue-bird Tea Rooms, where fine orchestral music flavors one's
refreshments, to the latest bank building and even to the station of
the railway, which "carries the largest suburban passenger traffic of
any in the world." "Meet me under the clock," is the Melbournian
motto. How they can all do so is beyond me, for the half-dozen
stone steps that lead to the narrow doors at the corner of the station
could not, I am sure, afford a rendezvous for more than thirty
people at one time; yet the old clock ticks away in patience,—the
most popular and most persistent thing in Melbourne.
I had so much trouble keeping pace with this Australian, who
seemed to grow more energetic the hotter it became, that I was
grateful when he said he would have to leave me, and I was alone
again. Then I realized for the first time that I could really like
Melbourne; that it had long, broad, spacious streets with clean,
fresh-looking office and department-store buildings, that even the
narrower side streets were clean and inviting, and that the street
cars were propelled by cables and not by trolley wires. So easy were
these cars and so low that no one ever waited for them to stop, but
hopped aboard anywhere along the street. Melbourne was to me a
perfect bath in cleanliness and orderliness,—just what a city ought
to be. Even in the very heart of the city the homes had a suburban
gentility about them, and there were no unnecessary noises, no
smoke, and no end of pretty girls. The people were a joy to look at.
Something of the tropical looseness in both dress and flesh, as
though their skins were always being fully ventilated, made them
attractive. The New Zealanders made me feel as though I were in a
bushel of apples; the Australians, carefully packed yellow plums. I
have never enjoyed just being on the street more than I did in
Melbourne.

A. A. White, Brisbane
AUSTRALIAN BLACKS IN THEIR NATIVE
ELEMENT

AN AUSTRALIAN BLACK IN MELBOURNE


Out of his element but happy none the
less

On Bourke Street, in the very midst of the pushing crowd, a soft-


voiced lad approached me for some information and strutted off, tall
in his self-confidence. Victorian belles, tall, graceful, russet-skinned,
plump but not flabby, moved with a fine air of self-reliance. On
closer acquaintance, I found that these girls were not silent and
opinionless as were most of the New Zealand girls. Whatever the
issue before the public, they had their defined opinions concerning
it, and they were not sneered at by the men. Then, too, there was a
companionship between the boys and girls, without reserve, that
was balm to my soul after the year in New Zealand.
Melbourne was the home of Madame Melba, and in consequence
the city is the most musical of any I lived in in the Antipodes. Even
the babies sing operatically on the streets, and the voices one hears
from open windows are not the head-voices of prayer-meetings, but
those of people who seem to know the value of the human larynx.
During the two weeks that I was in Melbourne, I was, whenever
I chose, a guest of the Master of the Mint, Mr. Bagg, who was the
uncle of a New Zealand girl of my acquaintance; lunched, dined and
afternoon tea-ed with his family whenever I felt like it; was rushed
to the theater to see an old pioneer play; and went to attend public
meetings at which the mayor and the prime minister spoke; visited
the beaches, and knew the joy of the most refreshing
companionship it was my good-fortune to meet with in all my
wanderings,—though there were others. And it was so with
whomever I met in Melbourne, from the clerk in the haberdashery,
who acquainted me with the jealousy that exists between Sydney
and Melbourne, to the woman in whose home I roomed on Fitzroy
Park, or the young couple with the toddling baby and the glorious
sheep-dog, who engaged me in conversation on the lawn near the
beach at St. Kilda.
And so I still see Melbourne in memory as a place I should enjoy
living in. I was often alone, but never lonely in it. And I see it from
its Botanic Gardens, with the broad Yarra Yarra River slowly cleaving
it in two, its soft, semi-tropical mists hanging over it, its temperate
climate, its cleanliness and its low, rolling hills where it hides its
suburbs.
I didn't go to see Adelaide, in South Australia, because I was
destined to live in Sydney, in New South Wales.

It is more than mere accident that Victoria has broader-gaged


railways than New South Wales, and that travelers from one state to
the other must get off at Albury and change, or between New South
Wales and Queensland to the north of it. It is not mere accident, I
am sure, for there is a like difference in the width of streets between
Melbourne and Sydney.
Sydney is hilly, exposed, bricky, and crowded, and though it is
the premier city of Australia, it grows without changing. There is a
conservatism about it which, in view of the activity of Australians, is
inexplicable. Sydney is almost an old city. Its streets wind as though
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like