How is a JUMP and CALL instruction different? How does it relate to the higher level concepts such as a GOTO or a procedure call? (Am I correct in the comparison?)
This is what I think:
JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called.
On the other hand, a CALL or procedure/function call returns to the point from where it is called. Due to this difference in their nature, languages typically make use of a stack and a stack frame is pushed to "remember" the location to come back for each procedure called. This behaviour applies to recursive procedures too. In case of tail recursion, there is however no need to "push" a stack frame for each call.
Your answers and comments will be much appreciated.
You're mostly right, if you are talking about CALL/JMP in x86 assembly or something similar. The main difference is:
Usually, CALL is just a convenience function implemented using JMP. You could do something like
movl $afterJmp, -(%esp)
jmp location
afterJmp:
instead of a CALL.
You're exactly right about the difference between a jump and a call.
In the sample case of a single function with tail recursion, then the compiler may be able to reuse the existing stack frame. However, it can become more complicated with mutually recursive functions:
void ping() { printf("ping\n"); pong(); }
void pong() { printf("pong\n"); ping(); }
Consider the case where ping() and pong() are more complex functions that take different numbers of parameters. Mark Probst's paper talks about tail recursion implementation for GCC in great detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With