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.
Japanese name: 疑似命令
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.
Japanese name: 疑似命令
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.
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.
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.
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.
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.
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.
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.
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.
No. nop is a pseudo-instruction encoded as addi x0, x0, 0, which changes nothing because writes to x0 are discarded.
Pseudo-instruction appears in 4 practice questions across 1 topic, including ISA & Assembly.
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.