RISC-V Assembly Language Programming Unlock the Power of the RISC-V Instruction Set
Gain the skills required to dive into the fundamentals of the RISC-V instruction set architecture. This book explains the basics of code optimization, as well as how to interoperate with C and Python code, thus providing the starting points for your own projects as you develop a working knowledge of...
Otros Autores: | |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
Berkeley, CA :
Apress
2024.
|
Edición: | 1st ed. 2024. |
Colección: | Maker Innovations Series,
|
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009799142506719 |
Tabla de Contenidos:
- Intro
- Table of Contents
- About the Author
- About the Technical Reviewer
- Acknowledgments
- Introduction
- Chapter 1: Getting Started
- History and Evolution of the RISC-V CPU
- What You Will Learn
- Ten Reasons to Learn Assembly Language Programming
- Running Programs on RISC-V Systems
- Coding a Simple "Hello World" Program
- Hello World on the Starfive Visionfive 2
- Programming Hello World in the QEMU Emulator
- Install QEMU on Windows
- Install QEMU on Linux
- Compiling in Emulated Linux
- About Hello World on the ESP32-C3 Microcontroller
- Summary
- Exercises
- Chapter 2: Loading and Adding
- Computers and Numbers
- Negative Numbers
- About Two's Complement
- RISC-V Assembly Instructions
- CPU Registers
- RISC-V Instruction Format
- About the GCC Assembler
- Adding Registers
- 32-bits in a 64-bit World
- Moving Registers
- About Pseudoinstructions
- About Immediate Values
- Loading the Top
- Shifting the Bits
- Loading Larger Numbers into Registers
- More Shift Instructions
- About Subtraction
- Summary
- Exercises
- Chapter 3: Tooling Up
- GNU Make
- Rebuild a Project
- Rule for Building .S files
- Define Variables
- Build with CMake
- Debugging with GDB
- Preparation to Debug
- Setup for Linux
- Start GDB
- Set Up gdb for the ESP32-C3
- Debugging with GDB
- Summary
- Exercises
- Chapter 4: Controlling Program Flow
- Creating Unconditional Jumps
- Understanding Conditional Branches
- Using Branch Pseudoinstructions
- Constructing Loops
- Create FOR Loops
- Code While Loops
- Coding If/Then/Else
- Manipulating Logical Operators
- Using AND
- Using XOR
- Using OR
- Adopting 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.
- Using Comparison Instructions
- Summary
- Exercises
- Chapter 5: Thanks for the Memories
- Defining Memory Contents
- Aligning Data
- About Program Sections
- Big vs. Little Endian
- Pros of Little Endian
- About Memory Addresses
- Loading a Register with an Address
- PC Relative Addressing
- Loading Data from Memory
- Combining Loading Addresses and Memory
- Storing a Register
- Optimizing Through Relaxing
- Converting to Uppercase
- Summary
- Exercises
- Chapter 6: Functions and the Stack
- About Stacks
- Jump and Link
- Nesting Function Calls
- Function Parameters and Return Values
- Managing the Registers
- Summary of the Function Call Algorithm
- Uppercase Revisited
- Stack Frames
- Stack Frame Example
- Defining Symbols
- Macros
- Include Directive
- Macro Definition
- Labels
- Why Macros?
- Using Macros to Improve Code
- Summary
- Exercises
- Chapter 7: Linux Operating System Services
- So Many Services
- Calling Convention
- Finding Linux System Call Numbers
- Return Codes
- Structures
- About Wrappers
- Converting a File to Uppercase
- 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 Enable Registers
- GPIO Output Set Registers
- More Flashing LEDs
- GPIOTurnOn in Detail
- Root Access
- Summary
- Exercises
- Chapter 9: Interacting with C and Python
- Calling C Routines
- Printing Debug Information
- Preserving State
- Calling Printf
- Passing a String
- Register Masking Revisited
- Calling Assembly Routines from C
- Packaging the Code
- Static Library
- Shared Library
- Embedding Assembly Language Code inside C Code.
- Calling Assembly from Python
- Summary
- Exercises
- Chapter 10: Multiply and Divide
- Multiplication
- Examples
- Division
- Division by Zero and Overflow
- Example
- Example: Matrix Multiplication
- Vectors and Matrices
- Multiplying 3x3 Integer Matrices
- Accessing Matrix Elements
- Register Usage
- Summary
- Exercises
- Chapter 11: Floating-Point Operations
- About Floating Point Numbers
- About Normalization and NaNs
- Recognizing Rounding Errors
- Defining Floating Point Numbers
- About Floating Point Registers
- The Status and Control Register
- Defining the Function Call Protocol
- Loading and Saving FPU Registers
- Performing Basic Arithmetic
- Calculating Distance Between Points
- Performing Floating-Point Conversions
- Floating-Point Sign Injection
- Comparing Floating-Point Numbers
- Example
- Summary
- Exercises
- Chapter 12: Optimizing Code
- Optimizing the Uppercase Routine
- Simplifying the Range Comparison
- Restricting the Problem Domain
- Tips for Optimizing Code
- Avoiding Branch Instructions
- Moving Code Out of Loops
- Avoiding Expensive Instructions
- Use Macros
- Loop Unrolling
- Delay Preserving Registers in Functions
- Keeping Data Small
- Beware of Overheating
- Summary
- Exercises
- Chapter 13: Reading and Understanding Code
- Browsing Linux &
- GCC Code
- Comparing Strings
- About the Algorithm
- Macros and Kernel Options
- Code Created by GCC
- Reverse Engineering and Ghidra
- Summary
- Exercises
- Chapter 14: Hacking Code
- Buffer Overrun Hack
- Causes of Buffer Overrun
- Stealing Credit Card Numbers
- Stepping Through the Stack
- Mitigating Buffer Overrun Vulnerabilities
- Do Not Use strcpy
- PIE Is Good
- Poor Stack Canaries Are the First to Go
- Preventing Code Running on the Stack
- Tradeoffs of Buffer Overflow Mitigation Techniques
- Summary.
- Exercises
- Appendix A: The RISC-V Instruction Set
- RV32I Base Integer Instruction Set
- RV64I Base Integer Instruction Set-in Addition to RV32I
- RV32M Standard Extension
- RV64M Standard Extension-in Addition to RV32M
- RV32F Standard Extension
- RV64F Standard Extension-in Addition to RV32F
- RV32D Standard Extension
- RV64D Standard Extension-in Addition to RV32D
- Appendix B: Binary Formats
- Integers
- Floating Point
- Addresses
- Appendix C: Assembler Directives
- Appendix D: ASCII Character Set
- Appendix E: Answers to Exercises
- Chapter 2
- Chapter 3
- Chapter 5
- Chapter 6
- Chapter 8
- Chapter 10
- Chapter 12
- Index.