Programming with 64-Bit ARM Assembly Language : Single Board Computer Development for Raspberry Pi and Mobile Devices
معرفی کتاب «Programming with 64-Bit ARM Assembly Language : Single Board Computer Development for Raspberry Pi and Mobile Devices» نوشتهٔ John Watson Foster، Joan L. Slonczewski، John Wade Foster، Zarrintaj Aliabadi و Stephen Smith، منتشرشده توسط نشر Apress در سال 2020. این کتاب در 53 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است.
"Mastering ARM hardware architecture opens a world of programming for nearly all phones and tablets including the iPhone/iPad and most Android phones. Its also the heart of many single board computers like the Raspberry Pi. Gain the skills required to dive into the fundamentals of the ARM hardware architecture with this book and start your own projects while you develop a working knowledge of assembly language for the ARM 64-bit processor. You'll review assembly language programming for the ARM Processor in 64-bit mode and write programs for a number of single board computers, including the Nvidia Jetson Nano and the Raspberry Pi (running 64-bit Linux). The book also discusses how to target assembly language programs for Apple iPhones and iPads along with 64-Bit ARM based Android phones and tablets. It covers all the tools you require, the basics of the ARM hardware architecture, all the groups of ARM 64-Bit Assembly instructions, and how data is stored in the computers memory. In addition, interface apps to hardware such as the Raspberry Pis GPIO ports. The book covers code optimization, as well as how to inter-operate with C and Python code. With Programming with 64-Bit ARM Assembly Language as your guide youll study how to read, reverse engineer and hack machine code, then be able to apply these new skills to study code examples and take control of both your ARM devices hardware and software. You will: Make operating system calls from assembly language and include other software libraries in your projects Interface apps to hardware devices such as the Raspberry Pi GPIO ports Reverse engineer and hack code Use the official ARM reference documentation for your own projects"--Contracoberta Table of Contents 5 About the Author 16 About the Technical Reviewer 17 Acknowledgments 18 Introduction 19 Chapter 1: Getting Started 22 The Surprise Birth of the 64-Bit ARM 23 What You Will Learn 24 Why Use Assembly 24 Tools You Need 27 Raspberry Pi 4 or NVidia Jetson Nano 27 Text Editor 28 Specialty Programs 28 Computers and Numbers 29 ARM Assembly Instructions 32 CPU Registers 33 ARM Instruction Format 34 Computer Memory 37 About the GCC Assembler 38 Hello World 39 About Comments 41 Where to Start 42 Assembly Instructions 43 Data 43 Calling Linux 44 Reverse Engineering Our Program 45 Summary 47 Exercises 48 Chapter 2: Loading and Adding 49 Negative Numbers 49 About Two’s Complement 49 About Gnome Programmer’s Calculator 51 About One’s Complement 52 Big vs. Little Endian 53 About Bi-endian 54 Pros of Little Endian 54 Shifting and Rotating 55 About Carry Flag 56 About the Barrel Shifter 56 Basics of Shifting and Rotating 57 Logical Shift Left 58 Logical Shift Right 58 Arithmetic Shift Right 58 Rotate Right 58 Loading Registers 58 Instruction Aliases 59 MOV/MOVK/MOVN 60 About MOVK 61 Register to Register MOV 61 About Operand2 62 Register and Shift 62 Register and Extension 63 Small Number and Shift 64 MOVN 65 MOV Examples 66 ADD/ADC 70 Add with Carry 72 SUB/SBC 75 Summary 76 Exercises 76 Chapter 3: Tooling Up 78 GNU Make 78 Rebuilding a File 79 A Rule for Building .s Files 80 Defining Variables 80 GDB 81 Preparing to Debug 82 Beginning GDB 84 Cross-Compiling 89 Emulation 91 Android NDK 91 Apple XCode 96 Source Control and Build Servers 101 Git 101 Jenkins 102 Summary 103 Exercises 103 Chapter 4: Controlling Program Flow 105 Unconditional Branch 105 About Condition Flags 106 Branch on Condition 108 About the CMP Instruction 108 Loops 110 FOR Loops 110 While Loops 111 If/Then/Else 112 Logical Operators 113 AND 114 EOR 114 ORR 114 BIC 115 Design Patterns 115 Converting Integers to ASCII 116 Using Expressions in Immediate Constants 120 Storing a Register to Memory 121 Why Not Print in Decimal? 121 Performance of Branch Instructions 122 More Comparison Instructions 123 Summary 124 Exercises 124 Chapter 5: Thanks for the Memories 126 Defining Memory Contents 127 Aligning Data 131 Loading a Register with an Address 131 PC Relative Addressing 132 Loading Data from Memory 134 Indexing Through Memory 136 Write Back 139 Post-Indexed Addressing 140 Converting to Upper-Case 140 Storing a Register 148 Double Registers 148 Summary 149 Exercises 150 Chapter 6: Functions and the Stack 151 Stacks on Linux 152 Branch with Link 154 Nesting Function Calls 155 Function Parameters and Return Values 157 Managing the Registers 158 Summary of the Function Call Algorithm 159 Upper-Case Revisited 160 Stack Frames 164 Stack Frame Example 166 Defining Symbols 167 Macros 167 Include Directive 170 Macro Definition 171 Labels 171 Why Macros? 172 Macros to Improve Code 173 Summary 174 Exercises 174 Chapter 7: Linux Operating System Services 176 So Many Services 176 Calling Convention 177 Linux System Call Numbers 178 Return Codes 178 Structures 179 Wrappers 180 Converting a File to Upper-Case 181 Building .S Files 185 Opening a File 187 Error Checking 187 Looping 189 Summary 190 Exercises 191 Chapter 8: Programming GPIO Pins 192 GPIO Overview 192 In Linux, Everything Is a File 193 Flashing LEDs 194 Moving Closer to the Metal 200 Virtual Memory 200 In Devices, Everything Is Memory 201 Registers in Bits 203 GPIO Function Select Registers 204 GPIO Output Set and Clear Registers 205 More Flashing LEDs 206 Root Access 212 Table Driven 212 Setting Pin Direction 213 Setting and Clearing Pins 214 Summary 215 Exercises 216 Chapter 9: Interacting with C and Python 217 Calling C Routines 217 Printing Debug Information 218 Preserving State 221 Calling Printf 221 Passing a String 222 Adding with Carry Revisited 223 Calling Assembly Routines from C 225 Packaging Our Code 227 Static Library 228 Shared Library 229 Embedding Assembly Code Inside C Code 232 Calling Assembly from Python 235 Summary 237 Exercises 238 Chapter 10: Interfacing with Kotlin and Swift 239 About Kotlin, Swift, and Java 239 Creating an Android App 240 Create the Project 241 XML Screen Definition 244 Kotlin Main Program 247 The C++ Wrapper 249 Building the Project 250 Creating an iOS App 253 Create the Project 254 Adding Elements to the Main Storyboard 254 Adding Swift Code 255 Adding our Assembly Language Routine 258 Creating the Bridge 259 Building and Running the Project 260 Tips for Optimizing Apps 261 Summary 262 Exercises 262 Chapter 11: Multiply, Divide, and Accumulate 263 Multiplication 263 Examples 265 Division 269 Example 270 Multiply and Accumulate 272 Vectors and Matrices 272 Accumulate Instructions 274 Example 1 275 Accessing Matrix Elements 279 Multiply with Accumulate 280 Register Usage 280 Summary 280 Exercises 281 Chapter 12: Floating-Point Operations 282 About Floating-Point Numbers 282 About Normalization and NaNs 284 Recognizing Rounding Errors 284 Defining Floating-Point Numbers 285 About FPU Registers 286 Defining the Function Call Protocol 287 Loading and Saving FPU Registers 287 Performing Basic Arithmetic 289 Calculating Distance Between Points 290 Performing Floating-Point Conversions 294 Comparing Floating-Point Numbers 295 Example 296 Summary 301 Exercises 301 Chapter 13: Neon Coprocessor 303 About the NEON Registers 303 Stay in Your Lane 304 Performing Arithmetic Operations 306 Calculating 4D Vector Distance 307 Optimizing 3x3 Matrix Multiplication 312 Summary 317 Exercises 318 Chapter 14: Optimizing Code 319 Optimizing the Upper-Case Routine 319 Simplifying the Range Comparison 320 Using a Conditional Instruction 323 Example with CSEL 324 Restricting the Problem Domain 326 Using Parallelism with SIMD 329 Tips for Optimizing Code 333 Avoiding Branch Instructions 333 Avoiding Expensive Instructions 334 Don’t Be Afraid of Macros 335 Loop Unrolling 335 Keeping Data Small 335 Beware of Overheating 335 Summary 336 Exercises 336 Chapter 15: Reading and Understanding Code 338 Browsing Linux and GCC Code 339 Copying a Page of Memory 340 About the Algorithm 343 Macros and Kernel Options 345 Code Created by GCC 346 Using the CBNZ and CBZ Instructions 351 Reverse Engineering and Ghidra 351 Summary 356 Exercises 357 Chapter 16: Hacking Code 358 Buffer Overrun Hack 358 Causes of Buffer Overrun 358 Stealing Credit Card Numbers 359 Stepping Through the Stack 362 Mitigating Buffer Overrun Vulnerabilities 365 Don’t Use strcpy 366 PIE Is Good 368 Poor Stack Canaries Are the First to Go 369 Preventing Code Running on the Stack 373 Trade-offs of Buffer Overflow Mitigation Techniques 373 Summary 375 Exercises 376 Appendix A: The ARM Instruction Set 378 ARM 64-Bit Core Instructions 378 ARM 64-Bit NEON and FPU Instructions 397 Appendix B: Binary Formats 411 Integers 411 Floating Point 412 Addresses 413 Appendix C: Assembler Directives 414 Appendix D: ASCII Character Set 416 Answers to Exercises 428 Chapter 1 428 Chapter 2 428 Chapter 5 429 Chapter 6 429 Chapter 8 429 Chapter 14 430 Index 431 Mastering ARM hardware architecture opens a world of programming for nearly all phones and tablets including the iPhone/iPad and most Android phones. It's also the heart of many single board computers like the Raspberry Pi. Gain the skills required to dive into the fundamentals of the ARM hardware architecture with this book and start your own projects while you develop a working knowledge of assembly language for the ARM 64-bit processor. You'll review assembly language programming for the ARM Processor in 64-bit mode and write programs for a number of single board computers, including the Nvidia Jetson Nano and the Raspberry Pi (running 64-bit Linux). The book also discusses how to target assembly language programs for Apple iPhones and iPads along with 64-Bit ARM based Android phones and tablets. It covers all the tools you require, the basics of the ARM hardware architecture, all the groups of ARM 64-Bit Assembly instructions, and how data is stored in the computer's memory. In addition, interface apps to hardware such as the Raspberry Pi's GPIO ports. The book covers code optimization, as well as how to inter-operate with C and Python code. Readers will develop enough background to use the official ARM reference documentation for their own projects. With Programming with 64-Bit ARM Assembly Language as your guide you'll study how to read, reverse engineer and hack machine code, then be able to apply these new skills to study code examples and take control of both your ARM devices' hardware and software. What You'll Learn Make operating system calls from assembly language and include other software libraries in your projects Interface apps to hardware devices such as the Raspberry Pi GPIO ports Reverse engineer and hack code Use the official ARM reference documentation for your own projects Who This Book Is For Software developers who have already learned to program in a higher-level language like Python, Java, C#, or even C and now wish to learn Assembly programming.
دانلود کتاب Programming with 64-Bit ARM Assembly Language : Single Board Computer Development for Raspberry Pi and Mobile Devices