Webcentive RISC-V Reference

c.jalr

Jump and Link Register

Extension
C
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
c.jalr xs1
Length
16-bit (compressed)

Encoding

1513121176210
1001rs1≠00000010

Match 0x9002, mask 0xf07f. Source: c.jalr c_rs1_n0 1..0=2 15..13=4 12=1 6..2=0 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
rs1≠011:7c_rs1_n0

Description

C.JALR (jump and link register) performs the same operation as C.JR, but additionally writes the address of the instruction following the jump (pc+2) to the link register, x1. C.JALR expands to jalr x1, 0(xs1).

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}
XReg addr = X[xs1];
XReg returnaddr;
returnaddr = $pc + 2;

X[1] = returnaddr;
jump(addr);

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages