RISC-V Assembly
Purpose
Guide agents through RISC-V assembly programming: RV32/RV64 instruction sets, register naming and calling conventions (psABI), ISA extension naming, inline assembly with GCC/Clang, compressed (RVC) instructions, and QEMU-based simulation with GDB remote debugging.
Triggers
- "How do I write RISC-V assembly?"
- "What are the RISC-V calling convention registers?"
- "How do I use inline asm for RISC-V in C?"
- "What do RISC-V extension letters mean (IMAFD)?"
- "How do I simulate RISC-V with QEMU?"
- "How do I debug RISC-V code with GDB?"
Workflow
1. Register file and calling convention
RISC-V has 32 integer registers (x0–x31) with ABI names:
Floating-point registers (F extension): f0–f31 (fa0–fa7 for arguments).
2. Basic instructions
3. Minimal function (psABI calling convention)
4. ISA extension naming
RISC-V extensions are combined as a string after the base ISA:
Common targets:
- Embedded:
rv32imac— no floating point, with atomics and compressed - Linux app:
rv64gc— full general + compressed - High performance:
rv64gcv— + vector
5. Inline assembly (GCC/Clang)
6. Compressed instructions (RVC)
RVC replaces common 32-bit instructions with 16-bit versions when:
- Register is in x8–x15 (for
c.versions) - Immediate fits in smaller field
- Specific instruction patterns match
7. QEMU simulation and GDB
For the RISC-V psABI calling convention details, see references/riscv-abi.md [blocked].
Related skills
- Use
skills/low-level-programming/assembly-armfor AArch64 comparison - Use
skills/low-level-programming/assembly-x86for x86-64 assembly - Use
skills/embedded/openocd-jtagfor real hardware RISC-V debugging - Use
skills/compilers/cross-gccfor RISC-V cross-compilation setup


