SimplifyC++ Article
RISC-V Assembly Development on Native RISC-V Linux Devices: Tools and Workflow
RISC-V Assembly Development on Native RISC-V Linux Devices: Tools and Workflow
As RISC-V rapidly grows in popularity across the open-source and embedded hardware communities, many developers are beginning to work directly on real RISC-V Linux hardware. Whether you are using boards like the VisionFive 2, HiFive Unmatched, MangoPi MQ-Pro or Banana Pi BPI-F3 having the right toolset is essential to develop and run low-level assembly code effectively.
This article offers a comprehensive overview of the RISC-V assembly tools available when working natively on a RISC-V CPU running Linux.
Why Native RISC-V Development?
Working directly on a RISC-V board (instead of cross-compiling from x86) enables:
Immediate testing and debugging on the target platform
Full access to Linux system calls in a RISC-V context
A more accurate view of performance and behavior
Greater learning opportunities for developers exploring new architecture
Essential Tools for RISC-V Assembly Programming on Linux
Here’s a list of the essential tools you’ll need on a native RISC-V Linux system:
1. GCC for RISC-V (gcc)
Installed by default on most RISC-V Linux distros like Debian RISC-V or Fedora RISC-V. It supports both C and assembly development.
sudo apt updatesudo apt install gcc2. GNU Assembler (as)
Assembles .s or .S files into object files.
as -o program.o program.s3. GNU Linker (ld)
Links object files into executable binaries. While ld can be used directly, using gcc for linking is usually safer due to automatic inclusion of system libraries.
gcc -o program program.s4. Objdump
Used for disassembling binaries or ELF files.
objdump -d program5. Readelf
Inspects ELF file structure, headers, and sections.
readelf -a program6. GDB
A powerful debugger available on most Linux distributions.
sudo apt install gdbgdb ./program7. Make and CMake
For automating builds. These tools are especially helpful for multi-file assembly projects.
sudo apt install make cmakeExample: Hello World in RISC-V Assembly
Here is a basic program that writes "Hello RISC-V!" using Linux system calls:
hello.s:
.section .datamsg: .asciz "Hello RISC-V!\n"
.section .text.globl _start_start: li a7, 64 # syscall write li a0, 1 # stdout la a1, msg # pointer to message li a2, 14 # length ecall
li a7, 93 # syscall exit li a0, 0 ecallBuild and Run:
as -o hello.o hello.sld -o hello hello.o./helloOptional But Useful Tools
| Tool | Use Case |
|---|---|
strace | Trace system calls during execution |
htop | Monitor runtime performance and CPU usage |
perf | Analyze performance events (if supported) |
Developing on x86 for RISC-V Boards (Cross Compilation)
While this article focuses on native development, if you're on an x86 host, you can cross-compile using:
sudo apt install gcc-riscv64-linux-gnuCompile and link:
riscv64-linux-gnu-gcc -o program program.sThen transfer the binary to your RISC-V board for testing.
Final Thoughts
RISC-V offers an open and extensible architecture that is transforming the embedded and systems programming landscape. By working directly on RISC-V Linux hardware with standard GNU tools, developers can learn, test, and deploy applications closer to the hardware layer with confidence.
As the ecosystem matures, mastering these native toolchains will become increasingly valuable for those working in firmware, IoT, operating systems, or bare-metal development.
If you're starting your RISC-V journey, there's no better way than to begin writing and executing your own assembly code—on the very architecture it was meant for.