RISC-V neg Pseudo-Instruction Details
Assembler pseudo-instructionNegate (two's complement) pseudo-instruction, expands to sub rd, x0, rs. Computes 0 - rs to obtain the arithmetic negation of rs. Common for sign flipping, absolute value pre-computation, and subtraction optimization.
What This Pseudo Instruction Is Saving You From Writing
More intuitive than sub rd, x0, rs for expressing negation. Compilers commonly use neg to implement the unary minus operator and optimize a - b into a + neg(b).
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 neg a real RISC-V instruction?
neg 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 neg?
Negating the minimum negative value overflows — e.g., on RV32, neg(0x80000000) = 0x80000000 (no trap, result equals itself)