RISC-V ret Pseudo-Instruction Details
Assembler pseudo-instructionReturn from subroutine pseudo-instruction, expands to jalr x0, 0(ra). Jumps back to the caller indirectly via the ra register. The standard return mechanism in RISC-V function epilogues.
What This Pseudo Instruction Is Saving You From Writing
The most common function-return JALR pattern (rd=x0, rs1=ra) is explicit with ret. Recognizing ret in disassembly aids control-flow understanding.
Official Semantics Checklist
How To Read The Expansion
What You May See In objdump / Disassembly
Official References And Reading Order
This page treats pseudo-instructions as assembler-level aliases or macros: first read what real instructions they expand to, then use the official ISA manual for the behavior of those real instructions. ABI, relocation, and linker-relaxation details follow the psABI document.
When To Think Of It First
Pitfalls / Common Confusions
FAQ
Is ret a real RISC-V instruction?
ret is an assembler pseudo-instruction or alias, not a separate hardware opcode. The “Typical Real Expansion” section lists the official expansion, and behavior is defined by the expanded ISA instructions.
What is the main trap when using ret?
ret depends on ra holding the correct return address — if the function overwrites ra, it must save/restore it on the stack first