Difference between Jmp and Call?

Posted on 2006-11-12
Last Modified: 2012-08-14
  Call P;

Works like a charm

 Jmp P;

What's the difference betwen Jmp and Call? Are they not the same thing?

Question by:tobjectpascal
  • 3
  • 2
LVL 26

Accepted Solution

Russell Libby earned 35 total points
ID: 17927966

Call expects a ret (return), to return to the calling location. Jmp is a like a "goto". If you jmp to code that performs a return, then an exception will be raised, as there won't be a call return on the stack.



Author Comment

ID: 17928045
So Call jumps to that segment of memory and starts executing the instructions/opcodes, it then hits the Ret and then it jumps back to the code that made the jmp execution?

Would that not mean Jmp requires a Ret; not Call? or could you not Push a Ret onto the Stack?

To me it makes more Sense if Jmp expected a Ret ...

Author Comment

ID: 17928080
procedure TForm1.Button1Click(Sender: TObject);
 P: pointer;
 P2: POinter;
  Push P2;
  Jmp P;

Interesting.... That actually brings it back to Button1.Click and then crashes lol

Author Comment

ID: 17928103
ok So any idea which Register contains the current code execution memory address? i Tried pushing EDI assuming that's where it's currently being exectued..

es:di right? do i need to push both? if you're not sure, that's ok I figured out from making the program crash that Pushing some address before jmping makes it return to that locaiton, just trying to work out how to make it get back again lol...

But thanks :)
LVL 26

Expert Comment

by:Russell Libby
ID: 17930005

> Would that not mean Jmp requires a Ret; not Call? or could you not Push a Ret onto the Stack?
> To me it makes more Sense if Jmp expected a Ret

In a word: NO.

The CALL saves procedure linking information on the stack and branches to the procedure specified with the destination (target) operand. The target operand specifies the address of the first instruction in the called procedure. This operand can be an immediate value, a general-purpose register, or a memory location. And when performing a near call, the processor pushes the value of the EIP register (which contains the offset of the instruction following the CALL instruction) onto the stack for use later as a return-instruction pointer.

The JMP is most commonly seen in two situations.

1. Branching logic within the same block of procedure code.
2. Hooking code that has been injected, where the calling code has already performed a CALL, and the hook code JMP's back to the original source.

JMP can be used in place of a call, but would require handling of the stack frame before making the JMP. Not usually a recommended idea.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSON on ISAPI REST Server using Delphi 2 229
Delphi Dbf export problem to a Visual Foxpro application 6 161
FMX StringGrid1->Canvas->FillRect Problem 3 127
Working with hours 3 46
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now