Programming with 64-Bit ARM Assembly Language
✍ Scribed by Stephen Smith
- Publisher
- Apress
- Year
- 2020
- Tongue
- English
- Leaves
- 436
- Edition
- 1
- Category
- Library
No coin nor oath required. For personal study only.
✦ Table of Contents
Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Getting Started
The Surprise Birth of the 64-Bit ARM
What You Will Learn
Why Use Assembly
Tools You Need
Raspberry Pi 4 or NVidia Jetson Nano
Text Editor
Specialty Programs
Computers and Numbers
ARM Assembly Instructions
CPU Registers
ARM Instruction Format
Computer Memory
About the GCC Assembler
Hello World
About Comments
Where to Start
Assembly Instructions
Data
Calling Linux
Reverse Engineering Our Program
Summary
Exercises
Chapter 2: Loading and Adding
Negative Numbers
About Two’s Complement
About Gnome Programmer’s Calculator
About One’s Complement
Big vs. Little Endian
About Bi-endian
Pros of Little Endian
Shifting and Rotating
About Carry Flag
About the Barrel Shifter
Basics of Shifting and Rotating
Logical Shift Left
Logical Shift Right
Arithmetic Shift Right
Rotate Right
Loading Registers
Instruction Aliases
MOV/MOVK/MOVN
About MOVK
Register to Register MOV
About Operand2
Register and Shift
Register and Extension
Small Number and Shift
MOVN
MOV Examples
ADD/ADC
Add with Carry
SUB/SBC
Summary
Exercises
Chapter 3: Tooling Up
GNU Make
Rebuilding a File
A Rule for Building .s Files
Defining Variables
GDB
Preparing to Debug
Beginning GDB
Cross-Compiling
Emulation
Android NDK
Apple XCode
Source Control and Build Servers
Git
Jenkins
Summary
Exercises
Chapter 4: Controlling Program Flow
Unconditional Branch
About Condition Flags
Branch on Condition
About the CMP Instruction
Loops
FOR Loops
While Loops
If/Then/Else
Logical Operators
AND
EOR
ORR
BIC
Design Patterns
Converting Integers to ASCII
Using Expressions in Immediate Constants
Storing a Register to Memory
Why Not Print in Decimal?
Performance of Branch Instructions
More Comparison Instructions
Summary
Exercises
Chapter 5: Thanks for the Memories
Defining Memory Contents
Aligning Data
Loading a Register with an Address
PC Relative Addressing
Loading Data from Memory
Indexing Through Memory
Write Back
Post-Indexed Addressing
Converting to Upper-Case
Storing a Register
Double Registers
Summary
Exercises
Chapter 6: Functions and the Stack
Stacks on Linux
Branch with Link
Nesting Function Calls
Function Parameters and Return Values
Managing the Registers
Summary of the Function Call Algorithm
Upper-Case Revisited
Stack Frames
Stack Frame Example
Defining Symbols
Macros
Include Directive
Macro Definition
Labels
Why Macros?
Macros to Improve Code
Summary
Exercises
Chapter 7: Linux Operating System Services
So Many Services
Calling Convention
Linux System Call Numbers
Return Codes
Structures
Wrappers
Converting a File to Upper-Case
Building .S Files
Opening a File
Error Checking
Looping
Summary
Exercises
Chapter 8: Programming GPIO Pins
GPIO Overview
In Linux, Everything Is a File
Flashing LEDs
Moving Closer to the Metal
Virtual Memory
In Devices, Everything Is Memory
Registers in Bits
GPIO Function Select Registers
GPIO Output Set and Clear Registers
More Flashing LEDs
Root Access
Table Driven
Setting Pin Direction
Setting and Clearing Pins
Summary
Exercises
Chapter 9: Interacting with C and Python
Calling C Routines
Printing Debug Information
Preserving State
Calling Printf
Passing a String
Adding with Carry Revisited
Calling Assembly Routines from C
Packaging Our Code
Static Library
Shared Library
Embedding Assembly Code Inside C Code
Calling Assembly from Python
Summary
Exercises
Chapter 10: Interfacing with Kotlin and Swift
About Kotlin, Swift, and Java
Creating an Android App
Create the Project
XML Screen Definition
Kotlin Main Program
The C++ Wrapper
Building the Project
Creating an iOS App
Create the Project
Adding Elements to the Main Storyboard
Adding Swift Code
Adding our Assembly Language Routine
Creating the Bridge
Building and Running the Project
Tips for Optimizing Apps
Summary
Exercises
Chapter 11: Multiply, Divide, and Accumulate
Multiplication
Examples
Division
Example
Multiply and Accumulate
Vectors and Matrices
Accumulate Instructions
Example 1
Accessing Matrix Elements
Multiply with Accumulate
Register Usage
Summary
Exercises
Chapter 12: Floating-Point Operations
About Floating-Point Numbers
About Normalization and NaNs
Recognizing Rounding Errors
Defining Floating-Point Numbers
About FPU Registers
Defining the Function Call Protocol
Loading and Saving FPU Registers
Performing Basic Arithmetic
Calculating Distance Between Points
Performing Floating-Point Conversions
Comparing Floating-Point Numbers
Example
Summary
Exercises
Chapter 13: Neon Coprocessor
About the NEON Registers
Stay in Your Lane
Performing Arithmetic Operations
Calculating 4D Vector Distance
Optimizing 3x3 Matrix Multiplication
Summary
Exercises
Chapter 14: Optimizing Code
Optimizing the Upper-Case Routine
Simplifying the Range Comparison
Using a Conditional Instruction
Example with CSEL
Restricting the Problem Domain
Using Parallelism with SIMD
Tips for Optimizing Code
Avoiding Branch Instructions
Avoiding Expensive Instructions
Don’t Be Afraid of Macros
Loop Unrolling
Keeping Data Small
Beware of Overheating
Summary
Exercises
Chapter 15: Reading and Understanding Code
Browsing Linux and GCC Code
Copying a Page of Memory
About the Algorithm
Macros and Kernel Options
Code Created by GCC
Using the CBNZ and CBZ Instructions
Reverse Engineering and Ghidra
Summary
Exercises
Chapter 16: Hacking Code
Buffer Overrun Hack
Causes of Buffer Overrun
Stealing Credit Card Numbers
Stepping Through the Stack
Mitigating Buffer Overrun Vulnerabilities
Don’t Use strcpy
PIE Is Good
Poor Stack Canaries Are the First to Go
Preventing Code Running on the Stack
Trade-offs of Buffer Overflow Mitigation Techniques
Summary
Exercises
Appendix A:
The ARM Instruction Set
ARM 64-Bit Core Instructions
ARM 64-Bit NEON and FPU Instructions
Appendix B:
Binary Formats
Integers
Floating Point
Addresses
Appendix C:
Assembler Directives
Appendix D:
ASCII Character Set
Answers to Exercises
Chapter 1
Chapter 2
Chapter 5
Chapter 6
Chapter 8
Chapter 14
Index
📜 SIMILAR VOLUMES
ARM 64-Bit Assembly Language carefully explains the concepts of assembly language programming, slowly building from simple examples towards complex programming on bare-metal embedded systems. Considerable emphasis is put on showing how to develop good, structured assembly code. More advanced topics
<p><i>ARM 64-Bit Assembly Language</i> carefully explains the concepts of assembly language programming, slowly building from simple examples towards complex programming on bare-metal embedded systems. Considerable emphasis is put on showing how to develop good, structured assembly code. More advanc
ARM 64-Bit Assembly Languagecarefully explains the concepts of assembly language programming, slowly building from simple examples towards complex programming on bare-metal embedded systems. Considerable emphasis is put on showing how to develop good, structured assembly code. More advanced topics s
<p><p>Gain the fundamentals of Armv8-A 32-bit and 64-bit assembly language programming. This book emphasizes Armv8-A assembly language topics that are relevant to modern software development. It is designed to help you quickly understand Armv8-A assembly language programming and the computational re