Difference between JUMP and CALL

user59634 picture user59634 · Feb 7, 2009 · Viewed 33.6k times · Source

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.

Answer

Anteru picture Anteru · Feb 7, 2009

You're mostly right, if you are talking about CALL/JMP in x86 assembly or something similar. The main difference is:

  • JMP performs a jump to a location, without doing anything else
  • CALL pushes the current instruction pointer on the stack (rather: one after the current instruction), and then JMPs to the location. With a RET you can get back to where you were.

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.