# `jalr`

[MIPS Documentation](https://asm-editor.specy.app/documentation/mips.md) › [Instructions](https://asm-editor.specy.app/documentation/mips/instruction.md)

Web page: https://asm-editor.specy.app/documentation/mips/instruction/jalr

**Jump and link register**

Category: Control flow

Saves the return address in the first register and jumps to the address in the second; with one register, the return address goes to $ra.

## Forms

- `jalr $t1, $t2`

- `jalr $t1` · 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.

## Operands

- `$t1`: Any general-purpose register, `$0` to `$31`, using its numeric or named spelling, such as `$8` or `$t0` (`$zero` is `$0`; `$ra` is `$31`).
- `$t2`: A general-purpose register. It may be the same register as `$t1`.

## Description

Allows calling a function whose address is only known at runtime (function pointer). Return with 'jr $t1'.

## Example

```mips
# 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:
```
