开发者

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百科
  1. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜