jalr

Operands

$reg, $reg

Jump and link register : Saves the return address (PC + 4) in $t1, then jumps to the address in $t2. Allows calling a function whose address is only known at runtime (function pointer). Return with 'jr $t1'.

Variants

  • Jump and link register : Saves the return address (PC + 4) in $t1, then jumps to the address in $t2. Allows calling a function whose address is only known at runtime (function pointer). Return with 'jr $t1'. jalr $t1,$t2
  • Jump and link register : Saves the return address (PC + 4) in $ra, then jumps to the address in $t1. One-operand shorthand for 'jalr $ra,$t1'. Used to call a function via a pointer stored in a register. jalr $t1
# jalr calls a local routine and writes the return address to $ra. Inspect $t2: 1 after return.
la $t0, routine
jalr $t0
li $t2, 1
b done # Skip the routine after returning.
routine: li $t2, 2
jr $ra # Return to the instruction after the call.
done: