Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pseudoinstructions

Pseudoinstructions are assembler syntax, not additional ISA operations. Some are fixed aliases for one real instruction. Others are assembler macros whose length depends on the operands, target architecture, position-independent-code setting, relocations, or linker relaxation.

In the tables below, one instruction describes the canonical expansion before optional compressed-instruction selection or linker relaxation. Temporary means a register in addition to the pseudo’s explicit result or source registers.

Register and arithmetic conveniences

PseudoCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
mv rd, rsaddi rd, rs, 0yesnono
nopaddi x0, x0, 0yesnono
not rd, rsxori rd, rs, -1yesnono
neg rd, rssub rd, x0, rsyesnono
negw rd, rs (RV64)subw rd, x0, rsyesnono
sext.w rd, rs (RV64)addiw rd, rs, 0yesnono
li rd, immoperand-dependent constant constructionnot alwaysoperand and XLEN; no symbol relocationno

Comparisons that write 0 or 1

PseudoCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
seqz rd, rssltiu rd, rs, 1yesnono
snez rd, rssltu rd, x0, rsyesnono
sltz rd, rsslt rd, rs, x0yesnono
sgtz rd, rsslt rd, x0, rsyesnono

These names make the intended relation to zero explicit. For two arbitrary registers, use slt or sltu and swap operands or invert the Boolean when the opposite relation is needed.

Branch conveniences

PseudoCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
beqz rs, labelbeq rs, x0, labelyesno 1no
bnez rs, labelbne rs, x0, labelyesno 1no
bltz rs, labelblt rs, x0, labelyesno 1no
bgez rs, labelbge rs, x0, labelyesno 1no
bgtz rs, labelblt x0, rs, labelyesno 1no
blez rs, labelbge x0, rs, labelyesno 1no
bgt rs, rt, labelblt rt, rs, labelyesno 1no
ble rs, rt, labelbge rt, rs, labelyesno 1no
bgtu rs, rt, labelbltu rt, rs, labelyesno 1no
bleu rs, rt, labelbgeu rt, rs, labelyesno 1no

The reversed forms work by swapping the two source operands; they do not need a separate comparison instruction.

Calls, jumps, and returns

PseudoCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
j labeljal x0, labelyesrelocation resolves targetno
jr rsjalr x0, 0(rs)yesnono
retjalr x0, 0(ra)yesnono
call symbolauipc ra, ...; jalr ra, ...not alwaysyes; linker may relax itno extra register
tail symbolauipc t1, ...; jalr x0, ...not alwaysyes; linker may relax ityes, t1 (x6)

call rd, symbol is also accepted by GNU-compatible assemblers when a link register other than ra is intentional. A plain call symbol uses ra.

CSR conveniences

These require the Zicsr extension. Each is one instruction, has no symbol relocation or code-model choice, and uses no temporary register.

PseudoCanonical expansionEffect
csrr rd, csrcsrrs rd, csr, x0read CSR without changing it
csrw csr, rscsrrw x0, csr, rswrite CSR; discard old value
csrs csr, rscsrrs x0, csr, rsset selected bits
csrc csr, rscsrrc x0, csr, rsclear selected bits
csrwi csr, uimm5csrrwi x0, csr, uimm5write a 5-bit immediate
csrsi csr, uimm5csrrsi x0, csr, uimm5set bits from an immediate
csrci csr, uimm5csrrci x0, csr, uimm5clear bits from an immediate

See CSR access for the side-effect rules that distinguish csrrw from csrrs/csrrc when a source or destination is x0.

Addresses and symbols

PseudoCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
lla rd, symbolPC-relative auipc + addinorelocations; PIC setting does not change itno extra register
lga rd, symbolGOT-relative auipc + lw/ldnorelocations, ABI, and XLENno extra register
la rd, symbollla in non-PIC code; lga in PIC codenoyes; .option pic selects the formno extra register

Here the destination register doubles as the working address register, so it is modified by the first instruction but no additional temporary is consumed.

Symbol loads and stores

GNU-compatible assemblers accept address-forming macros that combine a symbol reference with a load or store. They are convenient, but they are not ordinary base load/store syntax and are not guaranteed by every assembler.

Assembler formCanonical expansionOne instruction?Relocation or code-model dependent?Temporary?
lb/lbu/lh/lhu/lw/lwu/ld rd, symbolauipc rd, %pcrel_hi(symbol); matching load into rdnoPC-relative relocations; width/XLEN constraintsno extra register
sb/sh/sw/sd rs, symbol, tmpauipc tmp, %pcrel_hi(symbol); matching store via tmpnoPC-relative relocations; width/XLEN constraintsyes, explicit tmp
flw/fld fd, symbol, tmpauipc tmp, %pcrel_hi(symbol); FP load via tmpnoPC-relative relocations and enabled FP extensionyes, explicit tmp
fsw/fsd fs, symbol, tmpauipc tmp, %pcrel_hi(symbol); FP store via tmpnoPC-relative relocations and enabled FP extensionyes, explicit tmp

The second instruction carries the matching %pcrel_lo relocation. Integer loads can reuse rd for address construction because the load overwrites it. Stores and floating-point loads cannot, so their syntax names a temporary integer register. These forms address the symbol directly; use la/lga plus an explicit load when GOT-based interposition semantics must be clear.

Inspect the emitted code

Canonical expansions explain the meaning, not necessarily the final bytes. The C extension can provide a compressed encoding for some aliases, and linker relaxation can shorten relocation-marked sequences. Use objdump -dr on object files to see relocations and on the linked executable to see the final code.


  1. The label is still resolved by an assembler or linker relocation. That changes the encoded displacement, not the canonical pseudoinstruction expansion. An out-of-range conditional branch generally requires the programmer or another tool to provide a longer sequence. ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10