Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Stephen Smith

Rating No ratings yet

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 covers 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 apply those new skills to study code examples and take control of your Pi’s hardware and software both. For this New Edition Since the original edition, the Raspberry Pi OS has moved to 64-bits. The operating system has been revamped along with several new versions of the Raspberry Pi hardware. The new edition is 64-bit, based on the latest Raspberry Pi OS and hardware, and incorporates reader feedback from the first edition. What You'll Learn Program basic ARM 64-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 Language programming.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Raspberry Pi Assembly Language Programming: ARM Processor Coding — Reading Guide ## 【One-Line Pitch】 A hands-on, project-driven introduction to ARM 64-bit Assembly Language on the Raspberry Pi, perfect for programmers who already know a high-level language like Python, C, or Java and want to understand what happens under the hood—from registers and memory to GPIO and code optimization. ## 【Book Arc】 - **Opening (~0%–9%)**: Sets up the 64-bit Raspberry Pi OS environment, introduces the ARM processor architecture, and explains how numbers, memory, and registers work—laying the foundation for everything that follows. - **Early (~9%–28%)**: Covers the core instruction set—MOV, ADD, SUB, shifts, and extension operators—with detailed walkthroughs of how the assembler translates high-level operations into actual ARM-64 machine code. - **Early (~28%–38%)**: Introduces GDB debugging, then moves into program flow control: loops, if/else constructs, condition codes, and bitwise logic, including practical patterns for implementing common high-level language constructs. - **Middle (~38%–47%)**: Explores memory operations in depth—loading/storing data, arrays, alignment, and the stack—then explains the ARM calling convention for functions, including register management and stack frames. - **Late (~47%–60%)**: Covers interfacing with the Raspberry Pi's hardware, particularly GPIO ports, and how to interoperate with C and Python code. - **Ending (~60%–100%)**: Delves into advanced topics: the NEON coprocessor for SIMD operations, code optimization techniques, and how to read and reverse-engineer existing machine code using tools like GCC, GDB, and Ghidra. ## 【Key Takeaways】 - **ARM-64 is a different beast from x86** (Early): The instruction set is regular and orthogonal—most instructions take the same operand forms—which makes it easier to learn than x86 once you grasp the patterns. This regularity pays off when you start reading ARM reference documentation. - **Registers are the star of the show** (Early): ARM-64 has 31 general-purpose registers (X0–X30) plus a dedicated stack pointer, and understanding how data moves between registers and memory is the core skill. The book emphasizes that most instructions execute in one clock cycle thanks to pipelining. - **Immediate operands have hidden complexity** (Early): The MOV instruction isn't as simple as it looks—the assembler converts it into ORR or MOVZ instructions depending on the value, and there are extension operators (uxtb, sxtw, etc.) for sign/zero-extending values. This matters when you're trying to understand disassembled code. - **The stack is your friend for function calls** (Middle): The ARM calling convention divides registers into caller-saved (X0–X18) and callee-saved (X19–X30) categories, and the book walks through exactly how to manage the stack pointer (SP) and link register (LR) when creating functions. - **Condition codes and branching are the heart of control flow** (Early): The book shows how to implement loops, if/else, and even SELECT/CASE constructs using CMP, SUBS, and conditional branches—patterns you'll reuse constantly in real assembly projects. - **Memory alignment matters on ARM** (Middle): The ARM processor often requires data to be aligned on word boundaries, and the book explains the .align directive and how to properly index into arrays with LDR/STR instructions. - **Optimization is about understanding trade-offs** (Late): The book covers practical techniques—avoiding branches, using conditional instructions, loop unrolling, keeping data small, and leveraging SIMD—while also warning about real-world issues like CPU overheating on the Pi. - **Reverse engineering is a learnable skill** (Late): By studying code generated by GCC and using tools like Ghidra, you can learn to read and understand machine code, which is invaluable for debugging and for taking control of the Pi's hardware. ## 【Reading Tips】 - **Skim the first chapter if you're comfortable with number systems**: The base-10 vs. base-2 explanation is thorough but basic; the real value starts with the instruction set walkthroughs in Chapter 2. - **Deep-read Chapters 2–4**: These cover the fundamental instructions (MOV, ADD, SUB, shifts) and control flow. Work through the exercises—especially the 128-bit addition/subtraction problems—because they force you to understand carry flags and register management. - **Use the accompanying code snippets**: The book references a codesnippets.s file for each chapter. Download these and step through them in GDB as you read—this is where the learning really sticks. - **Pay special attention to the register convention table in Chapter 6**: This is the single most important reference for writing functions that work correctly with the Linux ABI. Bookmark it. - **The optimization and reverse-engineering chapters (13–14) are skimmable on first read**: Come back to them when you have a specific performance problem or need to understand unfamiliar code—they're reference material more than sequential reading. ## 【Coverage Limits】 This guide covers the book's progression from fundamentals through advanced topics based on the available excerpts. The excerpts do not cover the full details of the GPIO interfacing chapters or the complete NEON coprocessor examples, though these are mentioned in the table of contents. ##
Excerpt 1
22 Summary...
View in text
Excerpt 2
ion process. Other instructions might stall, for instance, when waiting for memory to be loaded; again, the processor can perform other instructions that d...
View in text
Excerpt 3
normally from the command line. To list our program, type: list (or l). This lists ten lines. Type: l 61 ChapTer 3 ToolInG up Note The sd cards the raspber...
View in text
Excerpt 4
h the caller and callee are using the same set of general- purpose registers, a protocol or convention is needed to ensure that the working data of one doe...
View in text
Excerpt 5
or are generally programmable: • Pins 1 and 17: Provide +3.3V DC power. • Pins 2 and 4: Provide +5V DC power. © Stephen Smith 2025 157 S. Smith, Raspberry P...
View in text
Excerpt 6
8 X3 = -379198319187490559, 0xfabcd12345678901 MUL X4 = bottom 64 bits of X2*X3: X4 = 8455362044785495672, 0x75577afb36c28e78 SMULH...
View in text
Excerpt 7
Second matrix in column major order B: .short 9, 6, 3, 0 .short 8, 5, 2, 0 .short 7, 4, 1, 0 // Result matrix in column major order C: .fil...
View in text
Excerpt 8
ored value for LR located at memory address 0x7fffffffef70. The hacker’s strategy is to overwrite LR with an address, causing the program to do their biddi...
View in text
Tags
AI categories
Programming LanguageARM嵌入式
ISBN: 8868818744
Publisher: Apress
Publish Year: 2025
Language: English
Pages: 352
File Format: PDF
File Size: 9.6 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…