Question

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,

  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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top