Reputation: 939
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
Upvotes: 25
Views: 62615
Reputation: 239
Jump places a certain address in the program counter and continues execution from there, however, JAL(jump and link) does the same but it saves the return address in ra so that you can continue execution after your subroutine finishes ie:
int main() {
dosomething();
//code here
}
void dosomething() {
//.....code here
}
dosomething
would be a subroutine that returns to the main block and continues executing
Upvotes: 8
Reputation: 91
jump and link will do the jump to the routine and store the program counter into GPR r31, and when the routine finishes MIPS uses 'jr r31' to return from that routine.
Upvotes: 2
Reputation: 121849
"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
Upvotes: 25