My Account Log in

1 option

RISC-V Assembly Language Programming : Unlock the Power of the RISC-V Instruction Set / by Stephen Smith.

O'Reilly Online Learning: Academic/Public Library Edition Available online

View online
Format:
Book
Author/Creator:
Smith, Stephen, 1623-1678, author.
Series:
Maker Innovations Series, 2948-2550
Language:
English
Subjects (All):
Makerspaces.
Maker.
Local Subjects:
Maker.
Physical Description:
1 online resource (369 pages)
Edition:
1st ed. 2024.
Place of Publication:
Berkeley, CA : Apress : Imprint: Apress, 2024.
Summary:
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 assembly language for various RISC-V processors. The RISC-V processor is the new open-source CPU that is quickly gaining popularity and this book serves as an introduction to assembly language programming for the processor in either 32- or 64-bit mode. You’ll see how to write assembly language programs for several single board computers, including the Starfive Visionfive 2 and the Espressif ESP32=C3 32-bit RISC-V microcontroller. The book also covers running RISC-V Linux with the QEMU emulator on and Intel/AMD based PC or laptop and all the tools required to do so. Moving on, you’ll examine the basics of the RISC-V hardware architecture, all the groups of RISC-V assembly language instructions and understand how data is stored in the computer’s memory. In addition, you’ll learn how to interface to hardware such as GPIO ports. With RISC-V Assembly Language Programming you’ll develop enough background to use the official RISC-V reference documentation for your own projects. What You'll Learn See how data is represented and stored in a RISC-V based computer Make operating system calls from assembly language and include other software libraries in projects Interface to various hardware devices Use the official RISC-V reference documentation.
Contents:
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
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
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
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
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
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
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
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
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
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
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
Chapter 13: Reading and Understanding Code
Browsing Linux &amp
GCC Code
Comparing Strings
About the Algorithm
Macros and Kernel Options
Code Created by GCC
Reverse Engineering and Ghidra
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.
Notes:
Includes index.
ISBN:
9798868801372
OCLC:
1420708108

The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.

Find

Home Release notes

My Account

Shelf Request an item Bookmarks Fines and fees Settings

Guides

Using the Find catalog Using Articles+ Using your account