Does $ra returns the address of current instruction or the next instruction?
I am very confused in the concept of returning address by $ra. Does it return the address of the current instruction being executed or the instruction to be executed next? For explanation please use the following code,
开发者_JAVA百科
- Consider a code fragment that calls three functions func_A, func_B, and func_C. The Instruction 1 is located at address 1996. What would be loaded in register $ra when each of the three functions is called?
Instruction 1
Instruction 2
jal func_A
Instruction 3
jal func_B
Instruction 4
jal func_C
Instruction 5
Thanks in advance.
The next instruction is stored in $ra
So, when calling func_A, $ra = 2008; when calling func_B, $ra = 2016; when calling func_C, $ra = 2024.
This is logical, because you return from a subroutine by jr $ra
, thus jumping to the instruction after the subroutine call.
精彩评论