Raspberry Pi Assembly Language Programming: ARM Processor Coding

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Gain all the skills required to dive into the fundamentals of the Raspberry Pi hardware architecture and how data is stored in the Pi’s memory. This book provides you with working starting points for your own projects while you develop a working knowledge of Assembly language programming on the Raspberry Pi. You'll learn how to interface to the Pi’s hardware including accessing the GPIO ports. The book will cover the basics of code optimization as well as how to inter-operate with C and Python code, so you'll develop enough background to use the official ARM reference documentation for further projects. With Raspberry Pi Assembly Language Programming as your guide you'll study how to read and reverse engineer machine code and then then apply those new skills to study code examples and take control of your Pi’s hardware and software both. What You'll Learn • Program basic ARM 32-Bit Assembly Language • Interface with the various hardware devices on the Raspberry Pi • Comprehend code containing Assembly language • Use the official ARM reference documentation Who This Book Is For Coders who have already learned to program in a higher-level language like Python, Java, C#, or C and now wish to learn Assembly programming.

Author(s): Stephen Smith
Publisher: Apress
Year: 2019

Language: English
Commentary: Publisher's PDF
Pages: 374
City: New York, NY
Tags: Linux; Programming; Debugging; Python; Assembly Language; Raspberry Pi; C; Stacks; GPIO; LEDs; Code Optimization; ARM Architecture; GNU Make

Table of Contents......Page 5
About the Author......Page 14
About the Technical Reviewer......Page 15
Acknowledgments......Page 16
Introduction......Page 17
Chapter 1: Getting Started......Page 19
About the ARM Processor......Page 20
What You Will Learn......Page 21
Why Use Assembly......Page 22
Tools You Need......Page 25
Computers and Numbers......Page 26
ARM Assembly Instructions......Page 29
CPU Registers......Page 30
ARM Instruction Format......Page 31
Raspberry Pi Memory......Page 33
About the GCC Assembler......Page 34
Hello World......Page 35
Where to Start......Page 38
Assembly Instructions......Page 39
Calling Linux......Page 40
Reverse Engineering Our Program......Page 41
Summary......Page 44
About Two’s Complement......Page 45
About Gnome Programmer’s Calculator......Page 47
Big vs. Little-endian......Page 48
Pros of Little-endian......Page 50
About Carry Flag......Page 51
About the Barrel Shifter......Page 52
Rotate Right......Page 53
About MOVT......Page 54
The Dreaded Flexible Operand2......Page 55
Small Number and Rotation......Page 56
MVN......Page 58
MOV Examples......Page 59
ADD/ADC......Page 63
Add with Carry......Page 65
Summary......Page 69
GNU Make......Page 70
A Rule for Building .s files......Page 71
Defining Variables......Page 72
Preparing to Debug......Page 73
Beginning GDB......Page 75
Git......Page 80
Jenkins......Page 81
Summary......Page 82
Unconditional Branch......Page 83
About the CPSR......Page 84
Branch on Condition......Page 86
Loops......Page 87
FOR Loops......Page 88
While Loops......Page 89
If/Then/Else......Page 90
AND......Page 91
BIC......Page 92
Design Patterns......Page 93
Converting Integers to ASCII......Page 94
Storing a Register to Memory......Page 98
Performance of Branch Instructions......Page 99
More Comparison Instructions......Page 100
Summary......Page 101
Chapter 5: Thanks for the  Memories......Page 102
Defining Memory Contents......Page 103
PC Relative Addressing......Page 107
Loading from Memory......Page 110
Indexing Through Memory......Page 111
Write Back......Page 114
Converting to Uppercase......Page 115
Storing a Register......Page 122
Summary......Page 123
Chapter 6: Functions and the  Stack......Page 124
Stacks on Raspbian......Page 125
Branch with Link......Page 126
Nesting Function Calls......Page 127
Managing the Registers......Page 129
Summary of the Function Call Algorithm......Page 130
Uppercase Revisited......Page 131
Stack Frames......Page 136
Stack Frame Example......Page 138
One More Optimization......Page 139
Macros......Page 140
Macro Definition......Page 143
Why Macros?......Page 144
Summary......Page 145
So Many Services......Page 146
Calling Convention......Page 147
Structures......Page 148
Wrappers......Page 149
Converting a File to Uppercase......Page 150
Error Checking......Page 155
Looping......Page 157
Summary......Page 158
GPIO Overview......Page 159
In Linux, Everything Is a File......Page 160
Flashing LEDs......Page 162
Moving Closer to the Metal......Page 166
Virtual Memory......Page 167
In Devices, Everything Is Memory......Page 168
Registers in Bits......Page 169
GPIO Function Select Registers......Page 170
More Flashing LEDs......Page 172
Table Driven......Page 178
Setting Pin Direction......Page 179
Setting and Clearing Pins......Page 180
Summary......Page 181
Calling C Routines......Page 182
Printing Debug Information......Page 183
Calling Printf......Page 185
Adding with Carry Revisited......Page 186
Calling Assembly Routines from C......Page 188
Static Library......Page 191
Shared Library......Page 192
Embedding Assembly Code Inside C Code......Page 195
Calling Assembly from Python......Page 198
Summary......Page 200
Multiplication......Page 201
Examples......Page 203
Division......Page 206
Example......Page 207
Multiply and Accumulate......Page 209
Vectors and Matrices......Page 210
Accumulate Instructions......Page 211
Example 1......Page 213
Accessing Matrix Elements......Page 217
Example 2......Page 218
Summary......Page 222
Chapter 11: Floating-Point Operations......Page 223
Normalization and NaNs......Page 224
Rounding Errors......Page 225
FPU Registers......Page 226
Function Call Protocol......Page 228
Loading and Saving FPU Registers......Page 229
Basic Arithmetic......Page 230
Distance Between Points......Page 232
Floating-Point Conversions......Page 236
Floating-Point Comparison......Page 237
Example......Page 239
Summary......Page 243
Chapter 12: NEON Coprocessor......Page 245
The NEON Registers......Page 246
Stay in Your Lane......Page 248
Arithmetic Operations......Page 249
4D Vector Distance......Page 250
3x3 Matrix Multiplication......Page 255
Summary......Page 260
Chapter 13: Conditional Instructions and Optimizing Code......Page 261
Improved Pipeline......Page 262
Optimizing the Uppercase Routine......Page 263
Simplifying the Range Comparison......Page 264
Using a Conditional Instruction......Page 267
Restricting the Problem Domain......Page 268
Using Parallelism with SIMD......Page 271
Summary......Page 275
Raspbian and GCC......Page 276
Division Revisited......Page 278
Code Created by GCC......Page 282
Reverse Engineering and Ghidra......Page 286
Summary......Page 290
Chapter 15: Thumb Code......Page 291
16-Bit Instruction Format......Page 292
Calling Thumb Code......Page 293
IT Blocks......Page 295
Uppercase in Thumb-2......Page 296
Use the C Compiler......Page 303
Summary......Page 305
Ubuntu MATE......Page 306
About 64 Bits......Page 307
More and Bigger Registers......Page 308
SP and Zero Register......Page 309
Function Call Interface......Page 310
Push and Pop Are Gone......Page 311
Porting from 32 Bits to 64 Bits......Page 312
Porting Uppercase to 64 Bits......Page 313
Conditional Instructions......Page 317
Example with CSEL......Page 318
Registers......Page 320
Instructions......Page 321
Example Using NEON......Page 322
Summary......Page 324
Appendix A: The ARM Instruction Set......Page 326
Linux System Call Numbers......Page 335
Linux System Call Error Codes......Page 350
Integers......Page 355
Floating-Point......Page 356
64 Bits......Page 357
Appendix D: Assembler Directives......Page 358
Appendix E: ASCII Character Set......Page 360
References......Page 372
Index......Page 373