jal
Jump and link
Saves the return address in $ra and jumps to label, the usual way to call a function.
Used in
- jal, jr, and the course calling conventionMIPS assembly
- Floating point and Coprocessor 1MIPS assembly
- A subroutine with its arguments in registersMIPS assembly
- Stack arguments and a stack frameMIPS assembly
- Recursion: factorial and FibonacciMIPS assembly
- Print a number in any base without helpMIPS assembly
- Drawing shapes on the screenMIPS assembly
- A bouncing ballMIPS assembly
- Move a square with the keyboardMIPS assembly
- The snake gameMIPS assembly
Forms
jal
Operands
label- A named address in the program, such as the start of a loop or a variable in
.data.
The standard function-call instruction in MIPS. The called function returns with 'jr $ra'. Same address-range restriction as 'j'.
# jal calls a local routine and saves the return address in $ra. Inspect $t2: 1 after return.
jal routine
li $t2, 1
b done # Skip the routine after returning.
routine: li $t2, 2
jr $ra # Return to the instruction after the call.
done: