jalr

RISC-V jalr Pseudo-Instruction Details

Assembler pseudo-instruction

Omitted-operand forms of JALR, commonly defaulting to ra as the link register and offset 0. It is used for indirect calls through a target address held in a register.

What You Write
jalr rs / jalr offset(rs) / jalr rd, rs
Typical Real Expansion
jalr ra, 0(rs) # or with offset: jalr ra, offset(rs) # or with explicit rd: jalr rd, 0(rs)

What This Pseudo Instruction Is Saving You From Writing

Function pointers, PLT stubs, and register-indirect calls often use rd=ra or imm=0; the pseudo forms make those common cases concise.

jalr primarily means "Indirect jump and link". It is assembler-level shorthand; when debugging, auditing, or reading machine code, reason from the real expansion and relocation semantics listed on this page.

Official Semantics Checklist

The official assembly manual treats jalr as an assembler-level pseudo-instruction or alias; hardware executes the expanded real instruction sequence.
The real semantics come from the ISA definitions of JALR and the other expanded instructions, not from a separate jalr hardware opcode.

Toolchain And Linker Boundaries

The shortened jalr forms fill omitted rd or offset defaults in the assembler; machine-code semantics still come from real JALR.
In indirect calls, PLT code, and function-pointer calls, the final target comes from the register value plus the 12-bit immediate, with JALR clearing target bit 0.

How To Read The Expansion

Step 1
jalr rs uses default link register ra, zero offset, and the target address in rs for an indirect call.
Step 2
jalr offset(rs) uses default link register ra and the given offset for an indirect call.
Step 3
jalr rd, rs uses explicit link register rd, zero offset, and the target address in rs for an indirect call.

What You May See In objdump / Disassembly

Disassembly may show either the pseudo-instruction or the expanded real instruction, depending on tool options and context.

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

Call through a function pointer
Jump to a code address held in a register while saving a return address
Read PLT, virtual-dispatch, or indirect-call sequences

Pitfalls / Common Confusions

JALR clears bit 0 of the target address; do not treat an odd address as the actual jump target
It overwrites the link register rd (ra by default); save the old return address if it must be preserved
The offset is a sign-extended 12-bit immediate, not an arbitrary register offset

FAQ

Is jalr a real RISC-V instruction?

jalr 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 jalr?

JALR clears bit 0 of the target address; do not treat an odd address as the actual jump target