?
Solved

Difference between Jmp and Call?

Posted on 2006-11-12
5
Medium Priority
?
1,633 Views
Last Modified: 2012-08-14
P:=@Button2.OnClick;
 Asm
  Call P;
 End;

Works like a charm

 P:=@Button2.OnClick;
 Asm
 Jmp P;
 End;


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

0
Comment
Question by:tobjectpascal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 140 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.

Russell



0
 
LVL 4

Author Comment

by:tobjectpascal
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 ...
0
 
LVL 4

Author Comment

by:tobjectpascal
ID: 17928080
procedure TForm1.Button1Click(Sender: TObject);
Var
 P: pointer;
 P2: POinter;
begin
 P:=@Button2.OnClick;
 P2:=@Button1.OnClick;
 Asm
  Push P2;
  Jmp P;
 End;
end;


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

Author Comment

by:tobjectpascal
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 :)
0
 
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.

Russell
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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