I´ve learned that both jal
and jalr
can be used for calling functions while on the contrary only jal
can be used for returning from functions like this:
sum3:
add a0, a0, a1
add a0, a0, a2
jalr x0, 0(ra)
However, this code uses jal
instead of jalr
for returning from a function and it works well:
call sum3
ret_sum3:
# following instructions
# ...
sum3:
add a0, a0, a1
add a0, a0, a2
jal x0, ret_sum3
In view of this, why it is said that jalr
is the instruction for returning from a function? I can use jal
for that too.