What is the purpose of the jr $ra instruction in MIPS?
The MIPS instruction
jr (jump register) is an unconditional jump where the target address is taken directly from a specified register. When a function (or subroutine) is called using the
jal (jump and link) instruction, the CPU automatically saves the address of the instruction after the jal call into the $ra (return address) register.The primary purpose of
jr $ra is to allow the function to return to the exact point in the calling code where it left off, ensuring the program's flow continues correctly after the function completes its task.