Raspberry Pi Operating System Assembly Language is a fully revised and updated guide to learning to program ARM machine code on your Raspberry Pi. With nothing other than the Raspberry Pi Operating System installed on your Raspberry Pi, this book shows you how to access all the tools that you'll need to create your own machine code programs using assembly language. Ideal for the novice, this book starts from first principles and leads you comfortably on your way to become an accomplished programmer. Providing lucid descriptions, award winning author Bruce Smith keeps things simple and includes plenty of program examples you can try for yourself. Ideas and concepts are introduced in the order required so you should never be left wondering. This book is compatible with all Raspberry PI models including the RPi 4, 400 and 3. Just some of the many features include:•Practical approach with example programs•GCC assembler and linker•ARM registers and arrangements•Use of Operating System calls•Debugging with GDB•Using libc function calls•Programming the GPIO•Floating Point and Neon co-processors•Thumb Code•Full details at the author websiteExamples are provided that are written using the GCC Compiler running under the Raspberry Pi Operating System, and can be downloaded from the website at www.brucesmith.info .What reviewers have said about Bruce's books: "This book is an excellent introduction to coding in ARM assembler on the Raspberry Pi." "This is the first computer book I have read in bed for pleasure rather than to cure insomnia!" "Great introduction to ARM assembler."
Author(s): Bruce Smith
Edition: 4
Publisher: BSB
Year: 2021
Language: English
Pages: 328
Using this eBook
Acknowledgements
Dedication
About the Author
Table Of Contents
1. Introduction
Imagination Unlimited
Start Experimenting
GNU C Compiler
Learn by Example
What Will You Learn?
Fourth Edition and Compatibility
Raspberry Pi OS
What About 64-bit?
Keyboard Computing
The Significance of ARM
Raspberry Pi Through the Ages
Compute Modules
Notation in Use
Table Terminology
Centre for Computing History
Companion Website and Free Books
2. Starting Out
Numbers with Meaning
ARM Instructions
The Transformation Process
Why Machine Code?
Language Levels
Into Orbit
RISC and Instruction Sets
Assembler Structure
Error Of Your Ways
Cross Compilers
The Raspberry Pi ARM Chips(s)
3. First Time Out
The Command Line
Creating A Source File
Come to the Execution
Assembler Errors
The Components
Lack of _start
Linking Files
Tidying Up
A Comment on Comments
Geany Programmer’s Editor
4. Bits of a RISC Machine
Binary to Decimal
Binary to Hex
Hex to Decimal and Back
Binary Addition
Subtraction
Twos Complement Numbers
When Twos Don’t Add Up
Desktop Calculator
5. ARM Arrangements
Word Lengths
Byte and Word Accessed Memory
Registers
R15 - Program Counter
Current Program Status Register
Bits and Flags
Setting Flags
S Suffix
R14: The Link Register
R13: The Stack Pointer
6. Data Processing
Addition Instructions
Subtraction
Multiplication
Divide Arrives
Move Instructions
Compare Instructions
Ordering Numbers
7. ROS Ins and Outs
SWI and SVC Commands
Writing to the Screen
Reading from the Keyboard
eax and Others
8. Logical Operations
Logical AND
Logical OR
Logical EOR
Logical Instructions
ORR to Convert Character Case
Bit Clear with BIC
Flag Tests
System Call Registers
9. Conditional Execution
Single Flag Condition Codes
EQ: Equal
NE: Not Equal
VS: Overflow Set
VC: Overflow Clear
MI: Minus Set
PL: Plus Clear
CS: Carry Set (HS: Higher or Same)
CC: Carry Clear (LO: Lower)
AL: Always
NV: Never
Multiple Flag Condition Code
HI: Higher (Unsigned)
LS: Lower Than or Same (Unsigned)
GE: Greater or Equal (Signed)
LT: Less Than (Signed)
GT: Greater Than (Signed)
LE: Less Than or Equal To (Signed)
Mixing the S Suffix
10. Branch and Compare
Branch Instructions
The Link Register
Using Compare Instructions
Compare Forward Thinking
Branch Exchange
11. Shifts and Rotates
Logical Shifts
Logical Shift Right
Arithmetic Shift Right
Rotations
Extended Rotate
Uses of Shifts and Rotates
Immediate Constant Range
Top Move
12. Smarter Numbers
Long Multiplication
Long Accumulation
Division and Remainder
Smarter Multiplication
Much More Inside
13. Program Counter R15
Pipelining
Calculating Branches
14. Debugging with GDB
Frozen Cases
Assembling for GDB
The Disassembler
Breakpoints
Breakpoint Labels
Memory Dump
Shortcuts
GDB Make Options
15. Data Transfer
ADR Directive
Indirect Addressing
ADR and LDR
Pre-Indexed Addressing
Accessing Memory Bytes
Address Write Back
Post-Indexed Addressing
Byte Conditions
PC Relative Addressing
16. Block Transfer
Write Back
Block Copy Routine
17. Stacks
Push and Pull
Stack Growth
Stack Application
Framed Work
Frame Pointer
18. Directives and Macros
Data Storage Directives
Aligning Data
Macros
Including Macros
19. File Handling
File Permissions
20. Using libc
Using C Functions in Assembler
Source File Structure
Investigating the Executable
Number Input with Scanf
Getting This Information
21. Writing Functions
Function Standards
More Than Three
Preserving Links and Flags
Robust Print Routines
22. Disassembling C
GCC - The Swiss Army Knife
A Simple C Framework
Sourcing the Assembler
A printf Example
Frame Pointer Variables
Disassembling System Calls
23. GPIO Functions
Memory Mapping
The GPIO Controller
GPIO In and Outs
Building the Code
Other GPIO Functions
GPIO Pins Explained
24. Floating-Point
VFP Architecture
The Register File
Managing and Printing
Assembling and Debugging VFP with GDB
Load, Store and Move
Precision Conversion
Vector Arithmetic
25. VFP Control Register
Conditional Execution
Scalar and Vector Operations
Which Type of Operator?
Len and Stride
26. Neon
Neon Assembler
Neon Instructions and Data Types
Addressing Modes
VLD and VST in their Stride
Load of Others
Neon Intrinsic
Neon Arrays
Order Correctly
Matrix Math
Multi Matrix
Macro Matrix Example
27. Thumb Code
Differences
Assembling Thumb
Accessing High Registers
Stack Operators
Single and Multi-Register
Functions in Thumb
ARMv7 Thumb Instructions
28. Unified Language
Thumb Changes
New A32 Instructions
Compare by Zero
Assembling UAL
29. Exception Handing
Modes of Operation
Vectors
Register Arrangements
Exception Handling
MRS and MSR
Interrupts When?
Your Interrupt Decisions
Returning from Interrupts
Writing Interrupt Routines
30. System on a Chip
The ARM Chip & Instruction Sets
Co-processors
Pipeline
Memory & Caches
The GPU
ARMv8 Overview
Raspberry Pi OS 64-Bit
In Summary
Archimedes Principle
A. ASCII Character Set
B. ARM Instruction Set
Load/Store Suffixes
Compare and Test Instructions
Branch Instructions
Arithmetic Instructions
Logical Instructions
Data Movement Instructions
C. RPi OS Syscalls