Could someone provide an example of the usefulness of the jal instruction can how it can be used to return to the main body after completing a subroutine?
regards
Jump and Link instructions are similar to the jump instructions, except that they store the address of the next instruction (the one immediately after the jump) in the return address ($ra; $31) register. This allows a subroutine to return to the main body routine after completion.
The difference is that the target address for JR comes from a register specified in the instruction. The jump-and-link instruction ( JAL ) behaves like the simple jump instruction ( J ), but also stores a return address in register 31 ($ra).
JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called. On the other hand, a CALL or procedure/function call returns to the point from where it is called.
"jmp" is a "goto".
"jal" is a "gosub"
jal saves the return address in $ra, should you wish to return from whence you came ;)
http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With