negpseudo
neg
rd, rspseudo
rd = -rs

neg flips the sign of a number: it turns 5 into -5 and -5 into 5. The name is short for negate, and the form neg rd, rs puts the negation of source register rs into destination register rd.

This is your first pseudo-instruction, and the idea is worth meeting properly. A pseudo-instruction is not a real machine operation; it is a convenient name that the assembler quietly rewrites into one or more genuine instructions before the processor ever sees it. neg is shorthand for sub rd, zero, rs — subtracting your number from zero (the special register that always holds 0). Since 0 minus x is -x, that one subtraction does the job. RISC-V leans on this trick constantly: rather than add a dedicated negate instruction, it reuses subtraction and the always-zero register, keeping the real instruction set small.

There is one genuine oddity. Because the range of negative numbers reaches one step further than the positives (down to about -2.1 billion but only up to about +2.1 billion), the single most-negative number has no positive twin. Negating it wraps around and gives back the same number — the one value where neg appears to do nothing. Code that computes absolute values has to account for it.

The example negates 5 into -5. Paired with a branch that skips the neg when the number is already positive, this becomes the standard two-instruction way to take an absolute value.

Expands to
sub rd, zero, rs

A pseudo-instruction: the assembler turns it into the real instruction(s) above.

li t0, 5
neg t1, t0       # t1 = -5