What is Pseudo-instruction?

Something written like an instruction in assembly that the assembler replaces with one or more real instructions, such as RISC-V nop, mv, li, j and ret.

Field: ISA & Assembly

Japanese name: 疑似命令

How the assembler expands them

A pseudo-instruction is assembly syntax with no encoding of its own; the assembler replaces it with one or more real instructions. In RISC-V, nop becomes addi x0, x0, 0, mv rd, rs becomes addi rd, rs, 0, j label becomes jal x0, label, ret becomes jalr x0, 0(ra), and bnez rs, label becomes bne rs, x0, label. Many rely on register x0, which always reads as zero and discards writes. Disassemblers usually print the pseudo form back, which makes listings easier to read.

One line, several instructions

Some pseudo-instructions expand to a variable number of real instructions. li (load immediate) becomes a single addi when the constant fits in a 12-bit signed immediate but lui followed by addi for a larger 32-bit value, and longer sequences for 64-bit constants. la (load address) and call for a distant function use auipc plus a second instruction to form a PC-relative address. Hand-computed code sizes and offsets must account for this.

Why ISAs rely on them

Defining nop, mv or a plain jump as separate hardware instructions would add opcodes and decoder logic without adding capability, since existing instructions with x0 already do the job. Pseudo-instructions keep the hardware instruction set small, a core RISC-V design goal, while giving programmers readable names for common idioms such as returning from a function or comparing against zero.

Pseudo-instructions vs. directives and macros

Assembler directives such as .text, .globl or .word are instructions to the assembler itself: they choose sections, export symbols or emit data, and do not correspond to machine instructions. A pseudo-instruction always turns into real instructions with a fixed meaning defined by the toolchain. Macros are similar expansions but defined by the programmer. Toolchains may also shorten some expansions later, for example turning an auipc-plus-jalr call into a single jal at link time when the target is close enough.

Try it: questions about Pseudo-instruction

Which real instruction does the assembler use for the RISC-V pseudo-instruction "nop" (do nothing)?

  1. Aaddi x0, x0, 0
  2. Bjal ra, 0
  3. Clw x0, 0(sp)
Show answer and explanation

Answer: A. addi x0, x0, 0

RISC-V has no dedicated do-nothing instruction; nop is encoded as "addi x0, x0, 0". The write to x0 is discarded, so no register or memory changes. Likewise "mv rd, rs" is "addi rd, rs, 0", "j label" is "jal x0, label" and "ret" is "jalr x0, 0(ra)". Using x0 to keep the number of instruction kinds small is part of the RISC-V design philosophy.

Which real instruction executes the RISC-V pseudo-instruction "ret"?

  1. Ajal ra, 0
  2. Bjalr x0, 0(ra)
  3. Clw ra, 0(sp)
Show answer and explanation

Answer: B. jalr x0, 0(ra)

jalr (jump and link register) jumps to a register value plus an offset and writes the next instruction's address into the destination. ret is "jalr x0, 0(ra)": it jumps to the address in ra and discards the link in x0. jalr is also used for jumps whose target is decided at run time, such as calls through function pointers or virtual functions. Restoring ra with "lw ra, ..." is preparation done before ret.

FAQ

What is the difference between a pseudo-instruction and a real instruction?

A real instruction has its own machine encoding that the CPU executes. A pseudo-instruction is only assembler syntax that is translated into one or more real instructions before execution.

What does li expand to in RISC-V?

For a small constant that fits in 12 signed bits, a single addi from x0; for larger 32-bit values, lui followed by addi, and longer sequences for 64-bit constants.

Is nop a real instruction in RISC-V?

No. nop is a pseudo-instruction encoded as addi x0, x0, 0, which changes nothing because writes to x0 are discarded.

Questions that mention Pseudo-instruction (2)

Pseudo-instruction appears in 4 practice questions across 1 topic, including ISA & Assembly.

  1. When the RISC-V code above finishes, what is the value in t0?
  2. What does the RISC-V instruction "jal ra, func" do?

Books on ISA & Assembly Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary